|
| 1 | + |
| 2 | +/* =========================== Module _Fm =========================== */ |
| 3 | + |
| 4 | +#include "Python.h" |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +#include "macglue.h" |
| 9 | +#include "pymactoolbox.h" |
| 10 | + |
| 11 | +/* Macro to test whether a weak-loaded CFM function exists */ |
| 12 | +#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ |
| 13 | + PyErr_SetString(PyExc_NotImplementedError, \ |
| 14 | + "Not available in this shared library/OS version"); \ |
| 15 | + return NULL; \ |
| 16 | + }} while(0) |
| 17 | + |
| 18 | + |
| 19 | +#ifdef WITHOUT_FRAMEWORKS |
| 20 | +#include <Fonts.h> |
| 21 | +#else |
| 22 | +#include <Carbon/Carbon.h> |
| 23 | +#endif |
| 24 | + |
| 25 | + |
| 26 | +/* |
| 27 | +** Parse/generate ComponentDescriptor records |
| 28 | +*/ |
| 29 | +static PyObject * |
| 30 | +FMRec_New(FMetricRec *itself) |
| 31 | +{ |
| 32 | + |
| 33 | + return Py_BuildValue("O&O&O&O&O&", |
| 34 | + PyMac_BuildFixed, itself->ascent, |
| 35 | + PyMac_BuildFixed, itself->descent, |
| 36 | + PyMac_BuildFixed, itself->leading, |
| 37 | + PyMac_BuildFixed, itself->widMax, |
| 38 | + ResObj_New, itself->wTabHandle); |
| 39 | +} |
| 40 | + |
| 41 | +#if 0 |
| 42 | +/* Not needed... */ |
| 43 | +static int |
| 44 | +FMRec_Convert(PyObject *v, FMetricRec *p_itself) |
| 45 | +{ |
| 46 | + return PyArg_ParseTuple(v, "O&O&O&O&O&", |
| 47 | + PyMac_GetFixed, &itself->ascent, |
| 48 | + PyMac_GetFixed, &itself->descent, |
| 49 | + PyMac_GetFixed, &itself->leading, |
| 50 | + PyMac_GetFixed, &itself->widMax, |
| 51 | + ResObj_Convert, &itself->wTabHandle); |
| 52 | +} |
| 53 | +#endif |
| 54 | + |
| 55 | + |
| 56 | +static PyObject *Fm_Error; |
| 57 | + |
| 58 | +#if !TARGET_API_MAC_CARBON |
| 59 | + |
| 60 | +static PyObject *Fm_InitFonts(PyObject *_self, PyObject *_args) |
| 61 | +{ |
| 62 | + PyObject *_res = NULL; |
| 63 | + if (!PyArg_ParseTuple(_args, "")) |
| 64 | + return NULL; |
| 65 | + InitFonts(); |
| 66 | + Py_INCREF(Py_None); |
| 67 | + _res = Py_None; |
| 68 | + return _res; |
| 69 | +} |
| 70 | +#endif |
| 71 | + |
| 72 | +static PyObject *Fm_GetFontName(PyObject *_self, PyObject *_args) |
| 73 | +{ |
| 74 | + PyObject *_res = NULL; |
| 75 | + short familyID; |
| 76 | + Str255 name; |
| 77 | + if (!PyArg_ParseTuple(_args, "h", |
| 78 | + &familyID)) |
| 79 | + return NULL; |
| 80 | + GetFontName(familyID, |
| 81 | + name); |
| 82 | + _res = Py_BuildValue("O&", |
| 83 | + PyMac_BuildStr255, name); |
| 84 | + return _res; |
| 85 | +} |
| 86 | + |
| 87 | +static PyObject *Fm_GetFNum(PyObject *_self, PyObject *_args) |
| 88 | +{ |
| 89 | + PyObject *_res = NULL; |
| 90 | + Str255 name; |
| 91 | + short familyID; |
| 92 | + if (!PyArg_ParseTuple(_args, "O&", |
| 93 | + PyMac_GetStr255, name)) |
| 94 | + return NULL; |
| 95 | + GetFNum(name, |
| 96 | + &familyID); |
| 97 | + _res = Py_BuildValue("h", |
| 98 | + familyID); |
| 99 | + return _res; |
| 100 | +} |
| 101 | + |
| 102 | +static PyObject *Fm_RealFont(PyObject *_self, PyObject *_args) |
| 103 | +{ |
| 104 | + PyObject *_res = NULL; |
| 105 | + Boolean _rv; |
| 106 | + short fontNum; |
| 107 | + short size; |
| 108 | + if (!PyArg_ParseTuple(_args, "hh", |
| 109 | + &fontNum, |
| 110 | + &size)) |
| 111 | + return NULL; |
| 112 | + _rv = RealFont(fontNum, |
| 113 | + size); |
| 114 | + _res = Py_BuildValue("b", |
| 115 | + _rv); |
| 116 | + return _res; |
| 117 | +} |
| 118 | + |
| 119 | +#if !TARGET_API_MAC_CARBON |
| 120 | + |
| 121 | +static PyObject *Fm_SetFontLock(PyObject *_self, PyObject *_args) |
| 122 | +{ |
| 123 | + PyObject *_res = NULL; |
| 124 | + Boolean lockFlag; |
| 125 | + if (!PyArg_ParseTuple(_args, "b", |
| 126 | + &lockFlag)) |
| 127 | + return NULL; |
| 128 | + SetFontLock(lockFlag); |
| 129 | + Py_INCREF(Py_None); |
| 130 | + _res = Py_None; |
| 131 | + return _res; |
| 132 | +} |
| 133 | +#endif |
| 134 | + |
| 135 | +static PyObject *Fm_SetFScaleDisable(PyObject *_self, PyObject *_args) |
| 136 | +{ |
| 137 | + PyObject *_res = NULL; |
| 138 | + Boolean fscaleDisable; |
| 139 | + if (!PyArg_ParseTuple(_args, "b", |
| 140 | + &fscaleDisable)) |
| 141 | + return NULL; |
| 142 | + SetFScaleDisable(fscaleDisable); |
| 143 | + Py_INCREF(Py_None); |
| 144 | + _res = Py_None; |
| 145 | + return _res; |
| 146 | +} |
| 147 | + |
| 148 | +static PyObject *Fm_FontMetrics(PyObject *_self, PyObject *_args) |
| 149 | +{ |
| 150 | + PyObject *_res = NULL; |
| 151 | + FMetricRec theMetrics; |
| 152 | + if (!PyArg_ParseTuple(_args, "")) |
| 153 | + return NULL; |
| 154 | + FontMetrics(&theMetrics); |
| 155 | + _res = Py_BuildValue("O&", |
| 156 | + FMRec_New, &theMetrics); |
| 157 | + return _res; |
| 158 | +} |
| 159 | + |
| 160 | +static PyObject *Fm_SetFractEnable(PyObject *_self, PyObject *_args) |
| 161 | +{ |
| 162 | + PyObject *_res = NULL; |
| 163 | + Boolean fractEnable; |
| 164 | + if (!PyArg_ParseTuple(_args, "b", |
| 165 | + &fractEnable)) |
| 166 | + return NULL; |
| 167 | + SetFractEnable(fractEnable); |
| 168 | + Py_INCREF(Py_None); |
| 169 | + _res = Py_None; |
| 170 | + return _res; |
| 171 | +} |
| 172 | + |
| 173 | +static PyObject *Fm_GetDefFontSize(PyObject *_self, PyObject *_args) |
| 174 | +{ |
| 175 | + PyObject *_res = NULL; |
| 176 | + short _rv; |
| 177 | + if (!PyArg_ParseTuple(_args, "")) |
| 178 | + return NULL; |
| 179 | + _rv = GetDefFontSize(); |
| 180 | + _res = Py_BuildValue("h", |
| 181 | + _rv); |
| 182 | + return _res; |
| 183 | +} |
| 184 | + |
| 185 | +static PyObject *Fm_IsOutline(PyObject *_self, PyObject *_args) |
| 186 | +{ |
| 187 | + PyObject *_res = NULL; |
| 188 | + Boolean _rv; |
| 189 | + Point numer; |
| 190 | + Point denom; |
| 191 | + if (!PyArg_ParseTuple(_args, "O&O&", |
| 192 | + PyMac_GetPoint, &numer, |
| 193 | + PyMac_GetPoint, &denom)) |
| 194 | + return NULL; |
| 195 | + _rv = IsOutline(numer, |
| 196 | + denom); |
| 197 | + _res = Py_BuildValue("b", |
| 198 | + _rv); |
| 199 | + return _res; |
| 200 | +} |
| 201 | + |
| 202 | +static PyObject *Fm_SetOutlinePreferred(PyObject *_self, PyObject *_args) |
| 203 | +{ |
| 204 | + PyObject *_res = NULL; |
| 205 | + Boolean outlinePreferred; |
| 206 | + if (!PyArg_ParseTuple(_args, "b", |
| 207 | + &outlinePreferred)) |
| 208 | + return NULL; |
| 209 | + SetOutlinePreferred(outlinePreferred); |
| 210 | + Py_INCREF(Py_None); |
| 211 | + _res = Py_None; |
| 212 | + return _res; |
| 213 | +} |
| 214 | + |
| 215 | +static PyObject *Fm_GetOutlinePreferred(PyObject *_self, PyObject *_args) |
| 216 | +{ |
| 217 | + PyObject *_res = NULL; |
| 218 | + Boolean _rv; |
| 219 | + if (!PyArg_ParseTuple(_args, "")) |
| 220 | + return NULL; |
| 221 | + _rv = GetOutlinePreferred(); |
| 222 | + _res = Py_BuildValue("b", |
| 223 | + _rv); |
| 224 | + return _res; |
| 225 | +} |
| 226 | + |
| 227 | +static PyObject *Fm_SetPreserveGlyph(PyObject *_self, PyObject *_args) |
| 228 | +{ |
| 229 | + PyObject *_res = NULL; |
| 230 | + Boolean preserveGlyph; |
| 231 | + if (!PyArg_ParseTuple(_args, "b", |
| 232 | + &preserveGlyph)) |
| 233 | + return NULL; |
| 234 | + SetPreserveGlyph(preserveGlyph); |
| 235 | + Py_INCREF(Py_None); |
| 236 | + _res = Py_None; |
| 237 | + return _res; |
| 238 | +} |
| 239 | + |
| 240 | +static PyObject *Fm_GetPreserveGlyph(PyObject *_self, PyObject *_args) |
| 241 | +{ |
| 242 | + PyObject *_res = NULL; |
| 243 | + Boolean _rv; |
| 244 | + if (!PyArg_ParseTuple(_args, "")) |
| 245 | + return NULL; |
| 246 | + _rv = GetPreserveGlyph(); |
| 247 | + _res = Py_BuildValue("b", |
| 248 | + _rv); |
| 249 | + return _res; |
| 250 | +} |
| 251 | + |
| 252 | +#if !TARGET_API_MAC_CARBON |
| 253 | + |
| 254 | +static PyObject *Fm_FlushFonts(PyObject *_self, PyObject *_args) |
| 255 | +{ |
| 256 | + PyObject *_res = NULL; |
| 257 | + OSErr _err; |
| 258 | + if (!PyArg_ParseTuple(_args, "")) |
| 259 | + return NULL; |
| 260 | + _err = FlushFonts(); |
| 261 | + if (_err != noErr) return PyMac_Error(_err); |
| 262 | + Py_INCREF(Py_None); |
| 263 | + _res = Py_None; |
| 264 | + return _res; |
| 265 | +} |
| 266 | +#endif |
| 267 | + |
| 268 | +static PyObject *Fm_GetSysFont(PyObject *_self, PyObject *_args) |
| 269 | +{ |
| 270 | + PyObject *_res = NULL; |
| 271 | + short _rv; |
| 272 | + if (!PyArg_ParseTuple(_args, "")) |
| 273 | + return NULL; |
| 274 | + _rv = GetSysFont(); |
| 275 | + _res = Py_BuildValue("h", |
| 276 | + _rv); |
| 277 | + return _res; |
| 278 | +} |
| 279 | + |
| 280 | +static PyObject *Fm_GetAppFont(PyObject *_self, PyObject *_args) |
| 281 | +{ |
| 282 | + PyObject *_res = NULL; |
| 283 | + short _rv; |
| 284 | + if (!PyArg_ParseTuple(_args, "")) |
| 285 | + return NULL; |
| 286 | + _rv = GetAppFont(); |
| 287 | + _res = Py_BuildValue("h", |
| 288 | + _rv); |
| 289 | + return _res; |
| 290 | +} |
| 291 | + |
| 292 | +static PyMethodDef Fm_methods[] = { |
| 293 | + |
| 294 | +#if !TARGET_API_MAC_CARBON |
| 295 | + {"InitFonts", (PyCFunction)Fm_InitFonts, 1, |
| 296 | + "() -> None"}, |
| 297 | +#endif |
| 298 | + {"GetFontName", (PyCFunction)Fm_GetFontName, 1, |
| 299 | + "(short familyID) -> (Str255 name)"}, |
| 300 | + {"GetFNum", (PyCFunction)Fm_GetFNum, 1, |
| 301 | + "(Str255 name) -> (short familyID)"}, |
| 302 | + {"RealFont", (PyCFunction)Fm_RealFont, 1, |
| 303 | + "(short fontNum, short size) -> (Boolean _rv)"}, |
| 304 | + |
| 305 | +#if !TARGET_API_MAC_CARBON |
| 306 | + {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1, |
| 307 | + "(Boolean lockFlag) -> None"}, |
| 308 | +#endif |
| 309 | + {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1, |
| 310 | + "(Boolean fscaleDisable) -> None"}, |
| 311 | + {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1, |
| 312 | + "() -> (FMetricRec theMetrics)"}, |
| 313 | + {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1, |
| 314 | + "(Boolean fractEnable) -> None"}, |
| 315 | + {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1, |
| 316 | + "() -> (short _rv)"}, |
| 317 | + {"IsOutline", (PyCFunction)Fm_IsOutline, 1, |
| 318 | + "(Point numer, Point denom) -> (Boolean _rv)"}, |
| 319 | + {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1, |
| 320 | + "(Boolean outlinePreferred) -> None"}, |
| 321 | + {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1, |
| 322 | + "() -> (Boolean _rv)"}, |
| 323 | + {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1, |
| 324 | + "(Boolean preserveGlyph) -> None"}, |
| 325 | + {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1, |
| 326 | + "() -> (Boolean _rv)"}, |
| 327 | + |
| 328 | +#if !TARGET_API_MAC_CARBON |
| 329 | + {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1, |
| 330 | + "() -> None"}, |
| 331 | +#endif |
| 332 | + {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1, |
| 333 | + "() -> (short _rv)"}, |
| 334 | + {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1, |
| 335 | + "() -> (short _rv)"}, |
| 336 | + {NULL, NULL, 0} |
| 337 | +}; |
| 338 | + |
| 339 | + |
| 340 | + |
| 341 | + |
| 342 | +void init_Fm(void) |
| 343 | +{ |
| 344 | + PyObject *m; |
| 345 | + PyObject *d; |
| 346 | + |
| 347 | + |
| 348 | + |
| 349 | + |
| 350 | + m = Py_InitModule("_Fm", Fm_methods); |
| 351 | + d = PyModule_GetDict(m); |
| 352 | + Fm_Error = PyMac_GetOSErrException(); |
| 353 | + if (Fm_Error == NULL || |
| 354 | + PyDict_SetItemString(d, "Error", Fm_Error) != 0) |
| 355 | + return; |
| 356 | +} |
| 357 | + |
| 358 | +/* ========================= End module _Fm ========================= */ |
| 359 | + |
0 commit comments