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