1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Font Manager module */
27 #include "allobjects.h"
29 #include "modsupport.h"
36 /* Font Handle object implementation */
43 staticforward typeobject Fhtype
;
45 #define is_fhobject(v) ((v)->ob_type == &Fhtype)
53 err_setstr(RuntimeError
, "error creating new font handle");
56 fhp
= NEWOBJ(fhobject
, &Fhtype
);
63 /* Font Handle methods */
66 fh_scalefont(self
, args
)
71 if (!getargs(args
, "d", &size
))
73 return newfhobject(fmscalefont(self
->fh_fh
, size
));
79 fh_setfont(self
, args
)
85 fmsetfont(self
->fh_fh
);
91 fh_getfontname(self
, args
)
99 len
= fmgetfontname(self
->fh_fh
, sizeof fontname
, fontname
);
101 err_setstr(RuntimeError
, "error in fmgetfontname");
104 return newsizedstringobject(fontname
, len
);
108 fh_getcomment(self
, args
)
116 len
= fmgetcomment(self
->fh_fh
, sizeof comment
, comment
);
118 err_setstr(RuntimeError
, "error in fmgetcomment");
121 return newsizedstringobject(comment
, len
);
125 fh_getfontinfo(self
, args
)
133 if (fmgetfontinfo(self
->fh_fh
, &info
) < 0) {
134 err_setstr(RuntimeError
, "error in fmgetfontinfo");
137 return mkvalue("(llllllll)",
150 fh_getwholemetrics(self
, args
)
158 fh_getstrwidth(self
, args
)
163 if (!getstrarg(args
, &str
))
165 return newintobject(fmgetstrwidth(self
->fh_fh
, str
));
168 static struct methodlist fh_methods
[] = {
169 {"scalefont", (method
)fh_scalefont
},
170 {"setfont", (method
)fh_setfont
},
171 {"getfontname", (method
)fh_getfontname
},
172 {"getcomment", (method
)fh_getcomment
},
173 {"getfontinfo", (method
)fh_getfontinfo
},
175 {"getwholemetrics", (method
)fh_getwholemetrics
},
177 {"getstrwidth", (method
)fh_getstrwidth
},
178 {NULL
, NULL
} /* sentinel */
182 fh_getattr(fhp
, name
)
186 return findmethod(fh_methods
, (object
*)fhp
, name
);
193 fmfreefont(fhp
->fh_fh
);
197 static typeobject Fhtype
= {
198 OB_HEAD_INIT(&Typetype
)
200 "font handle", /*tp_name*/
201 sizeof(fhobject
), /*tp_size*/
204 (destructor
)fh_dealloc
, /*tp_dealloc*/
206 (getattrfunc
)fh_getattr
, /*tp_getattr*/
213 /* Font Manager functions */
227 fm_findfont(self
, args
)
231 if (!getstrarg(args
, &str
))
233 return newfhobject(fmfindfont(str
));
241 if (!getstrarg(args
, &str
))
248 /* XXX This uses a global variable as temporary! Not re-entrant! */
250 static object
*fontlist
;
258 if (fontlist
== NULL
)
260 v
= newstringobject(fontname
);
264 err
= addlistitem(fontlist
, v
);
274 fm_enumerate(self
, args
)
280 fontlist
= newlistobject(0);
281 if (fontlist
== NULL
)
283 fmenumerate(clientproc
);
290 fm_setpath(self
, args
)
294 if (!getstrarg(args
, &str
))
302 fm_fontpath(self
, args
)
307 return newstringobject(fmfontpath());
310 static struct methodlist fm_methods
[] = {
312 {"findfont", fm_findfont
},
313 {"enumerate", fm_enumerate
},
315 {"setpath", fm_setpath
},
316 {"fontpath", fm_fontpath
},
317 {NULL
, NULL
} /* sentinel */
324 initmodule("fm", fm_methods
);