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