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 or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
32 /* Font Manager module */
41 /* Font Handle object implementation */
48 staticforward PyTypeObject Fhtype
;
50 #define is_fhobject(v) ((v)->ob_type == &Fhtype)
58 PyErr_SetString(PyExc_RuntimeError
,
59 "error creating new font handle");
62 fhp
= PyObject_NEW(fhobject
, &Fhtype
);
66 return (PyObject
*)fhp
;
69 /* Font Handle methods */
72 fh_scalefont(self
, args
)
77 if (!PyArg_Parse(args
, "d", &size
))
79 return newfhobject(fmscalefont(self
->fh_fh
, size
));
85 fh_setfont(self
, args
)
89 if (!PyArg_NoArgs(args
))
91 fmsetfont(self
->fh_fh
);
97 fh_getfontname(self
, args
)
103 if (!PyArg_NoArgs(args
))
105 len
= fmgetfontname(self
->fh_fh
, sizeof fontname
, fontname
);
107 PyErr_SetString(PyExc_RuntimeError
, "error in fmgetfontname");
110 return PyString_FromStringAndSize(fontname
, len
);
114 fh_getcomment(self
, args
)
120 if (!PyArg_NoArgs(args
))
122 len
= fmgetcomment(self
->fh_fh
, sizeof comment
, comment
);
124 PyErr_SetString(PyExc_RuntimeError
, "error in fmgetcomment");
127 return PyString_FromStringAndSize(comment
, len
);
131 fh_getfontinfo(self
, args
)
136 if (!PyArg_NoArgs(args
))
138 if (fmgetfontinfo(self
->fh_fh
, &info
) < 0) {
139 PyErr_SetString(PyExc_RuntimeError
, "error in fmgetfontinfo");
142 return Py_BuildValue("(llllllll)",
155 fh_getwholemetrics(self
, args
)
163 fh_getstrwidth(self
, args
)
168 if (!PyArg_Parse(args
, "s", &str
))
170 return PyInt_FromLong(fmgetstrwidth(self
->fh_fh
, str
));
173 static PyMethodDef fh_methods
[] = {
174 {"scalefont", (PyCFunction
)fh_scalefont
},
175 {"setfont", (PyCFunction
)fh_setfont
},
176 {"getfontname", (PyCFunction
)fh_getfontname
},
177 {"getcomment", (PyCFunction
)fh_getcomment
},
178 {"getfontinfo", (PyCFunction
)fh_getfontinfo
},
180 {"getwholemetrics", (PyCFunction
)fh_getwholemetrics
},
182 {"getstrwidth", (PyCFunction
)fh_getstrwidth
},
183 {NULL
, NULL
} /* sentinel */
187 fh_getattr(fhp
, name
)
191 return Py_FindMethod(fh_methods
, (PyObject
*)fhp
, name
);
198 fmfreefont(fhp
->fh_fh
);
202 static PyTypeObject Fhtype
= {
203 PyObject_HEAD_INIT(&PyType_Type
)
205 "font handle", /*tp_name*/
206 sizeof(fhobject
), /*tp_size*/
209 (destructor
)fh_dealloc
, /*tp_dealloc*/
211 (getattrfunc
)fh_getattr
, /*tp_getattr*/
218 /* Font Manager functions */
222 PyObject
*self
, *args
;
224 if (!PyArg_NoArgs(args
))
232 fm_findfont(self
, args
)
233 PyObject
*self
, *args
;
236 if (!PyArg_Parse(args
, "s", &str
))
238 return newfhobject(fmfindfont(str
));
243 PyObject
*self
, *args
;
246 if (!PyArg_Parse(args
, "s", &str
))
253 /* XXX This uses a global variable as temporary! Not re-entrant! */
255 static PyObject
*fontlist
;
263 if (fontlist
== NULL
)
265 v
= PyString_FromString(fontname
);
269 err
= PyList_Append(fontlist
, v
);
279 fm_enumerate(self
, args
)
280 PyObject
*self
, *args
;
283 if (!PyArg_NoArgs(args
))
285 fontlist
= PyList_New(0);
286 if (fontlist
== NULL
)
288 fmenumerate(clientproc
);
295 fm_setpath(self
, args
)
296 PyObject
*self
, *args
;
299 if (!PyArg_Parse(args
, "s", &str
))
307 fm_fontpath(self
, args
)
308 PyObject
*self
, *args
;
310 if (!PyArg_NoArgs(args
))
312 return PyString_FromString(fmfontpath());
315 static PyMethodDef fm_methods
[] = {
317 {"findfont", fm_findfont
},
318 {"enumerate", fm_enumerate
},
320 {"setpath", fm_setpath
},
321 {"fontpath", fm_fontpath
},
322 {NULL
, NULL
} /* sentinel */
329 Py_InitModule("fm", fm_methods
);