Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 524b588 | 1995-01-04 19:10:35 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 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 |
| 15 | permission. |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 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. |
| 20 | |
| 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. |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
| 32 | /* Font Manager module */ |
| 33 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 34 | #include "Python.h" |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 35 | |
| 36 | #include <gl.h> |
| 37 | #include <device.h> |
| 38 | #include <fmclient.h> |
| 39 | |
| 40 | |
| 41 | /* Font Handle object implementation */ |
| 42 | |
| 43 | typedef struct { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 44 | PyObject_HEAD |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 45 | fmfonthandle fh_fh; |
| 46 | } fhobject; |
| 47 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 48 | staticforward PyTypeObject Fhtype; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 49 | |
| 50 | #define is_fhobject(v) ((v)->ob_type == &Fhtype) |
| 51 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 52 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 53 | newfhobject(fh) |
| 54 | fmfonthandle fh; |
| 55 | { |
| 56 | fhobject *fhp; |
| 57 | if (fh == NULL) { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 58 | PyErr_SetString(PyExc_RuntimeError, |
| 59 | "error creating new font handle"); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 60 | return NULL; |
| 61 | } |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 62 | fhp = PyObject_New(fhobject, &Fhtype); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 63 | if (fhp == NULL) |
| 64 | return NULL; |
| 65 | fhp->fh_fh = fh; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 66 | return (PyObject *)fhp; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /* Font Handle methods */ |
| 70 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 71 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 72 | fh_scalefont(self, args) |
| 73 | fhobject *self; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 74 | PyObject *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 75 | { |
| 76 | double size; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 77 | if (!PyArg_Parse(args, "d", &size)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 78 | return NULL; |
| 79 | return newfhobject(fmscalefont(self->fh_fh, size)); |
| 80 | } |
| 81 | |
| 82 | /* XXX fmmakefont */ |
| 83 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 84 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 85 | fh_setfont(self, args) |
| 86 | fhobject *self; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 87 | PyObject *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 88 | { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 89 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 90 | return NULL; |
| 91 | fmsetfont(self->fh_fh); |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 92 | Py_INCREF(Py_None); |
| 93 | return Py_None; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 96 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 97 | fh_getfontname(self, args) |
| 98 | fhobject *self; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 99 | PyObject *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 100 | { |
| 101 | char fontname[256]; |
| 102 | int len; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 103 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 104 | return NULL; |
| 105 | len = fmgetfontname(self->fh_fh, sizeof fontname, fontname); |
| 106 | if (len < 0) { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 107 | PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontname"); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 108 | return NULL; |
| 109 | } |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 110 | return PyString_FromStringAndSize(fontname, len); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 113 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 114 | fh_getcomment(self, args) |
| 115 | fhobject *self; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 116 | PyObject *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 117 | { |
| 118 | char comment[256]; |
| 119 | int len; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 120 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 121 | return NULL; |
| 122 | len = fmgetcomment(self->fh_fh, sizeof comment, comment); |
| 123 | if (len < 0) { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 124 | PyErr_SetString(PyExc_RuntimeError, "error in fmgetcomment"); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 125 | return NULL; |
| 126 | } |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 127 | return PyString_FromStringAndSize(comment, len); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 130 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 131 | fh_getfontinfo(self, args) |
| 132 | fhobject *self; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 133 | PyObject *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 134 | { |
| 135 | fmfontinfo info; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 136 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 137 | return NULL; |
| 138 | if (fmgetfontinfo(self->fh_fh, &info) < 0) { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 139 | PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontinfo"); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 140 | return NULL; |
| 141 | } |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 142 | return Py_BuildValue("(llllllll)", |
| 143 | info.printermatched, |
| 144 | info.fixed_width, |
| 145 | info.xorig, |
| 146 | info.yorig, |
| 147 | info.xsize, |
| 148 | info.ysize, |
| 149 | info.height, |
| 150 | info.nglyphs); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | #if 0 |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 154 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 155 | fh_getwholemetrics(self, args) |
| 156 | fhobject *self; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 157 | PyObject *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 158 | { |
| 159 | } |
| 160 | #endif |
| 161 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 162 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 163 | fh_getstrwidth(self, args) |
| 164 | fhobject *self; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 165 | PyObject *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 166 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 167 | char *str; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 168 | if (!PyArg_Parse(args, "s", &str)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 169 | return NULL; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 170 | return PyInt_FromLong(fmgetstrwidth(self->fh_fh, str)); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 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}, |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 179 | #if 0 |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 180 | {"getwholemetrics", (PyCFunction)fh_getwholemetrics}, |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 181 | #endif |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 182 | {"getstrwidth", (PyCFunction)fh_getstrwidth}, |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 183 | {NULL, NULL} /* sentinel */ |
| 184 | }; |
| 185 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 186 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 187 | fh_getattr(fhp, name) |
| 188 | fhobject *fhp; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 189 | char *name; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 190 | { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 191 | return Py_FindMethod(fh_methods, (PyObject *)fhp, name); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static void |
| 195 | fh_dealloc(fhp) |
| 196 | fhobject *fhp; |
| 197 | { |
| 198 | fmfreefont(fhp->fh_fh); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 199 | PyObject_Del(fhp); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 202 | static PyTypeObject Fhtype = { |
| 203 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 204 | 0, /*ob_size*/ |
| 205 | "font handle", /*tp_name*/ |
| 206 | sizeof(fhobject), /*tp_size*/ |
| 207 | 0, /*tp_itemsize*/ |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 208 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 209 | (destructor)fh_dealloc, /*tp_dealloc*/ |
| 210 | 0, /*tp_print*/ |
| 211 | (getattrfunc)fh_getattr, /*tp_getattr*/ |
| 212 | 0, /*tp_setattr*/ |
| 213 | 0, /*tp_compare*/ |
| 214 | 0, /*tp_repr*/ |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | |
| 218 | /* Font Manager functions */ |
| 219 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 220 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 221 | fm_init(self, args) |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 222 | PyObject *self, *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 223 | { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 224 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 225 | return NULL; |
| 226 | fminit(); |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 227 | Py_INCREF(Py_None); |
| 228 | return Py_None; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 231 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 232 | fm_findfont(self, args) |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 233 | PyObject *self, *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 234 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 235 | char *str; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 236 | if (!PyArg_Parse(args, "s", &str)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 237 | return NULL; |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 238 | return newfhobject(fmfindfont(str)); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 241 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 242 | fm_prstr(self, args) |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 243 | PyObject *self, *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 244 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 245 | char *str; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 246 | if (!PyArg_Parse(args, "s", &str)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 247 | return NULL; |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 248 | fmprstr(str); |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 249 | Py_INCREF(Py_None); |
| 250 | return Py_None; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /* XXX This uses a global variable as temporary! Not re-entrant! */ |
| 254 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 255 | static PyObject *fontlist; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 256 | |
| 257 | static void |
| 258 | clientproc(fontname) |
| 259 | char *fontname; |
| 260 | { |
| 261 | int err; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 262 | PyObject *v; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 263 | if (fontlist == NULL) |
| 264 | return; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 265 | v = PyString_FromString(fontname); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 266 | if (v == NULL) |
| 267 | err = -1; |
| 268 | else { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 269 | err = PyList_Append(fontlist, v); |
| 270 | Py_DECREF(v); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 271 | } |
| 272 | if (err != 0) { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 273 | Py_DECREF(fontlist); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 274 | fontlist = NULL; |
| 275 | } |
| 276 | } |
| 277 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 278 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 279 | fm_enumerate(self, args) |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 280 | PyObject *self, *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 281 | { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 282 | PyObject *res; |
| 283 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 284 | return NULL; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 285 | fontlist = PyList_New(0); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 286 | if (fontlist == NULL) |
| 287 | return NULL; |
| 288 | fmenumerate(clientproc); |
| 289 | res = fontlist; |
| 290 | fontlist = NULL; |
| 291 | return res; |
| 292 | } |
| 293 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 294 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 295 | fm_setpath(self, args) |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 296 | PyObject *self, *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 297 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 298 | char *str; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 299 | if (!PyArg_Parse(args, "s", &str)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 300 | return NULL; |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 301 | fmsetpath(str); |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 302 | Py_INCREF(Py_None); |
| 303 | return Py_None; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 306 | static PyObject * |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 307 | fm_fontpath(self, args) |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 308 | PyObject *self, *args; |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 309 | { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 310 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 311 | return NULL; |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 312 | return PyString_FromString(fmfontpath()); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 315 | static PyMethodDef fm_methods[] = { |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 316 | {"init", fm_init}, |
| 317 | {"findfont", fm_findfont}, |
| 318 | {"enumerate", fm_enumerate}, |
| 319 | {"prstr", fm_prstr}, |
| 320 | {"setpath", fm_setpath}, |
| 321 | {"fontpath", fm_fontpath}, |
| 322 | {NULL, NULL} /* sentinel */ |
| 323 | }; |
| 324 | |
| 325 | |
| 326 | void |
| 327 | initfm() |
| 328 | { |
Roger E. Masse | ed648a2 | 1997-01-17 16:08:55 +0000 | [diff] [blame] | 329 | Py_InitModule("fm", fm_methods); |
Guido van Rossum | a0c191e | 1991-04-03 19:02:31 +0000 | [diff] [blame] | 330 | fminit(); |
| 331 | } |