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