Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module Fm ============================ */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 8 | #include "macglue.h" |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 9 | #include "pymactoolbox.h" |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 10 | |
| 11 | #include <Fonts.h> |
| 12 | |
| 13 | /* |
| 14 | ** Parse/generate ComponentDescriptor records |
| 15 | */ |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 16 | static PyObject * |
| 17 | FMRec_New(itself) |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 18 | FMetricRec *itself; |
| 19 | { |
| 20 | |
| 21 | return Py_BuildValue("O&O&O&O&O&", |
| 22 | PyMac_BuildFixed, itself->ascent, |
| 23 | PyMac_BuildFixed, itself->descent, |
| 24 | PyMac_BuildFixed, itself->leading, |
| 25 | PyMac_BuildFixed, itself->widMax, |
| 26 | ResObj_New, itself->wTabHandle); |
| 27 | } |
| 28 | |
| 29 | #if 0 |
| 30 | /* Not needed... */ |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 31 | static int |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 32 | FMRec_Convert(v, p_itself) |
| 33 | PyObject *v; |
| 34 | FMetricRec *p_itself; |
| 35 | { |
| 36 | return PyArg_ParseTuple(v, "O&O&O&O&O&", |
| 37 | PyMac_GetFixed, &itself->ascent, |
| 38 | PyMac_GetFixed, &itself->descent, |
| 39 | PyMac_GetFixed, &itself->leading, |
| 40 | PyMac_GetFixed, &itself->widMax, |
| 41 | ResObj_Convert, &itself->wTabHandle); |
| 42 | } |
| 43 | #endif |
| 44 | |
| 45 | |
| 46 | static PyObject *Fm_Error; |
| 47 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 48 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 49 | |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 50 | static PyObject *Fm_InitFonts(_self, _args) |
| 51 | PyObject *_self; |
| 52 | PyObject *_args; |
| 53 | { |
| 54 | PyObject *_res = NULL; |
| 55 | if (!PyArg_ParseTuple(_args, "")) |
| 56 | return NULL; |
| 57 | InitFonts(); |
| 58 | Py_INCREF(Py_None); |
| 59 | _res = Py_None; |
| 60 | return _res; |
| 61 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 62 | #endif |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 63 | |
| 64 | static PyObject *Fm_GetFontName(_self, _args) |
| 65 | PyObject *_self; |
| 66 | PyObject *_args; |
| 67 | { |
| 68 | PyObject *_res = NULL; |
| 69 | short familyID; |
| 70 | Str255 name; |
| 71 | if (!PyArg_ParseTuple(_args, "h", |
| 72 | &familyID)) |
| 73 | return NULL; |
| 74 | GetFontName(familyID, |
| 75 | name); |
| 76 | _res = Py_BuildValue("O&", |
| 77 | PyMac_BuildStr255, name); |
| 78 | return _res; |
| 79 | } |
| 80 | |
| 81 | static PyObject *Fm_GetFNum(_self, _args) |
| 82 | PyObject *_self; |
| 83 | PyObject *_args; |
| 84 | { |
| 85 | PyObject *_res = NULL; |
| 86 | Str255 name; |
| 87 | short familyID; |
| 88 | if (!PyArg_ParseTuple(_args, "O&", |
| 89 | PyMac_GetStr255, name)) |
| 90 | return NULL; |
| 91 | GetFNum(name, |
| 92 | &familyID); |
| 93 | _res = Py_BuildValue("h", |
| 94 | familyID); |
| 95 | return _res; |
| 96 | } |
| 97 | |
| 98 | static PyObject *Fm_RealFont(_self, _args) |
| 99 | PyObject *_self; |
| 100 | PyObject *_args; |
| 101 | { |
| 102 | PyObject *_res = NULL; |
| 103 | Boolean _rv; |
| 104 | short fontNum; |
| 105 | short size; |
| 106 | if (!PyArg_ParseTuple(_args, "hh", |
| 107 | &fontNum, |
| 108 | &size)) |
| 109 | return NULL; |
| 110 | _rv = RealFont(fontNum, |
| 111 | size); |
| 112 | _res = Py_BuildValue("b", |
| 113 | _rv); |
| 114 | return _res; |
| 115 | } |
| 116 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 117 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 118 | |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 119 | static PyObject *Fm_SetFontLock(_self, _args) |
| 120 | PyObject *_self; |
| 121 | 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 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 133 | #endif |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 134 | |
| 135 | static PyObject *Fm_SetFScaleDisable(_self, _args) |
| 136 | PyObject *_self; |
| 137 | PyObject *_args; |
| 138 | { |
| 139 | PyObject *_res = NULL; |
| 140 | Boolean fscaleDisable; |
| 141 | if (!PyArg_ParseTuple(_args, "b", |
| 142 | &fscaleDisable)) |
| 143 | return NULL; |
| 144 | SetFScaleDisable(fscaleDisable); |
| 145 | Py_INCREF(Py_None); |
| 146 | _res = Py_None; |
| 147 | return _res; |
| 148 | } |
| 149 | |
| 150 | static PyObject *Fm_FontMetrics(_self, _args) |
| 151 | PyObject *_self; |
| 152 | PyObject *_args; |
| 153 | { |
| 154 | PyObject *_res = NULL; |
| 155 | FMetricRec theMetrics; |
| 156 | if (!PyArg_ParseTuple(_args, "")) |
| 157 | return NULL; |
| 158 | FontMetrics(&theMetrics); |
| 159 | _res = Py_BuildValue("O&", |
| 160 | FMRec_New, &theMetrics); |
| 161 | return _res; |
| 162 | } |
| 163 | |
| 164 | static PyObject *Fm_SetFractEnable(_self, _args) |
| 165 | PyObject *_self; |
| 166 | PyObject *_args; |
| 167 | { |
| 168 | PyObject *_res = NULL; |
| 169 | Boolean fractEnable; |
| 170 | if (!PyArg_ParseTuple(_args, "b", |
| 171 | &fractEnable)) |
| 172 | return NULL; |
| 173 | SetFractEnable(fractEnable); |
| 174 | Py_INCREF(Py_None); |
| 175 | _res = Py_None; |
| 176 | return _res; |
| 177 | } |
| 178 | |
| 179 | static PyObject *Fm_GetDefFontSize(_self, _args) |
| 180 | PyObject *_self; |
| 181 | PyObject *_args; |
| 182 | { |
| 183 | PyObject *_res = NULL; |
| 184 | short _rv; |
| 185 | if (!PyArg_ParseTuple(_args, "")) |
| 186 | return NULL; |
| 187 | _rv = GetDefFontSize(); |
| 188 | _res = Py_BuildValue("h", |
| 189 | _rv); |
| 190 | return _res; |
| 191 | } |
| 192 | |
| 193 | static PyObject *Fm_IsOutline(_self, _args) |
| 194 | PyObject *_self; |
| 195 | PyObject *_args; |
| 196 | { |
| 197 | PyObject *_res = NULL; |
| 198 | Boolean _rv; |
| 199 | Point numer; |
| 200 | Point denom; |
| 201 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 202 | PyMac_GetPoint, &numer, |
| 203 | PyMac_GetPoint, &denom)) |
| 204 | return NULL; |
| 205 | _rv = IsOutline(numer, |
| 206 | denom); |
| 207 | _res = Py_BuildValue("b", |
| 208 | _rv); |
| 209 | return _res; |
| 210 | } |
| 211 | |
| 212 | static PyObject *Fm_SetOutlinePreferred(_self, _args) |
| 213 | PyObject *_self; |
| 214 | PyObject *_args; |
| 215 | { |
| 216 | PyObject *_res = NULL; |
| 217 | Boolean outlinePreferred; |
| 218 | if (!PyArg_ParseTuple(_args, "b", |
| 219 | &outlinePreferred)) |
| 220 | return NULL; |
| 221 | SetOutlinePreferred(outlinePreferred); |
| 222 | Py_INCREF(Py_None); |
| 223 | _res = Py_None; |
| 224 | return _res; |
| 225 | } |
| 226 | |
| 227 | static PyObject *Fm_GetOutlinePreferred(_self, _args) |
| 228 | PyObject *_self; |
| 229 | PyObject *_args; |
| 230 | { |
| 231 | PyObject *_res = NULL; |
| 232 | Boolean _rv; |
| 233 | if (!PyArg_ParseTuple(_args, "")) |
| 234 | return NULL; |
| 235 | _rv = GetOutlinePreferred(); |
| 236 | _res = Py_BuildValue("b", |
| 237 | _rv); |
| 238 | return _res; |
| 239 | } |
| 240 | |
| 241 | static PyObject *Fm_SetPreserveGlyph(_self, _args) |
| 242 | PyObject *_self; |
| 243 | PyObject *_args; |
| 244 | { |
| 245 | PyObject *_res = NULL; |
| 246 | Boolean preserveGlyph; |
| 247 | if (!PyArg_ParseTuple(_args, "b", |
| 248 | &preserveGlyph)) |
| 249 | return NULL; |
| 250 | SetPreserveGlyph(preserveGlyph); |
| 251 | Py_INCREF(Py_None); |
| 252 | _res = Py_None; |
| 253 | return _res; |
| 254 | } |
| 255 | |
| 256 | static PyObject *Fm_GetPreserveGlyph(_self, _args) |
| 257 | PyObject *_self; |
| 258 | PyObject *_args; |
| 259 | { |
| 260 | PyObject *_res = NULL; |
| 261 | Boolean _rv; |
| 262 | if (!PyArg_ParseTuple(_args, "")) |
| 263 | return NULL; |
| 264 | _rv = GetPreserveGlyph(); |
| 265 | _res = Py_BuildValue("b", |
| 266 | _rv); |
| 267 | return _res; |
| 268 | } |
| 269 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 270 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 271 | |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 272 | static PyObject *Fm_FlushFonts(_self, _args) |
| 273 | PyObject *_self; |
| 274 | PyObject *_args; |
| 275 | { |
| 276 | PyObject *_res = NULL; |
| 277 | OSErr _err; |
| 278 | if (!PyArg_ParseTuple(_args, "")) |
| 279 | return NULL; |
| 280 | _err = FlushFonts(); |
| 281 | if (_err != noErr) return PyMac_Error(_err); |
| 282 | Py_INCREF(Py_None); |
| 283 | _res = Py_None; |
| 284 | return _res; |
| 285 | } |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 286 | #endif |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 287 | |
| 288 | static PyObject *Fm_GetSysFont(_self, _args) |
| 289 | PyObject *_self; |
| 290 | PyObject *_args; |
| 291 | { |
| 292 | PyObject *_res = NULL; |
| 293 | short _rv; |
| 294 | if (!PyArg_ParseTuple(_args, "")) |
| 295 | return NULL; |
| 296 | _rv = GetSysFont(); |
| 297 | _res = Py_BuildValue("h", |
| 298 | _rv); |
| 299 | return _res; |
| 300 | } |
| 301 | |
| 302 | static PyObject *Fm_GetAppFont(_self, _args) |
| 303 | PyObject *_self; |
| 304 | PyObject *_args; |
| 305 | { |
| 306 | PyObject *_res = NULL; |
| 307 | short _rv; |
| 308 | if (!PyArg_ParseTuple(_args, "")) |
| 309 | return NULL; |
| 310 | _rv = GetAppFont(); |
| 311 | _res = Py_BuildValue("h", |
| 312 | _rv); |
| 313 | return _res; |
| 314 | } |
| 315 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 316 | static PyObject *Fm_SetAntiAliasedTextEnabled(_self, _args) |
| 317 | PyObject *_self; |
| 318 | PyObject *_args; |
| 319 | { |
| 320 | PyObject *_res = NULL; |
| 321 | OSStatus _err; |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 322 | Boolean iEnable; |
| 323 | SInt16 iMinFontSize; |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 324 | if (!PyArg_ParseTuple(_args, "bh", |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 325 | &iEnable, |
| 326 | &iMinFontSize)) |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 327 | return NULL; |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 328 | _err = SetAntiAliasedTextEnabled(iEnable, |
| 329 | iMinFontSize); |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 330 | if (_err != noErr) return PyMac_Error(_err); |
| 331 | Py_INCREF(Py_None); |
| 332 | _res = Py_None; |
| 333 | return _res; |
| 334 | } |
| 335 | |
| 336 | static PyObject *Fm_IsAntiAliasedTextEnabled(_self, _args) |
| 337 | PyObject *_self; |
| 338 | PyObject *_args; |
| 339 | { |
| 340 | PyObject *_res = NULL; |
| 341 | Boolean _rv; |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 342 | SInt16 oMinFontSize; |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 343 | if (!PyArg_ParseTuple(_args, "")) |
| 344 | return NULL; |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 345 | _rv = IsAntiAliasedTextEnabled(&oMinFontSize); |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 346 | _res = Py_BuildValue("bh", |
| 347 | _rv, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 348 | oMinFontSize); |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 349 | return _res; |
| 350 | } |
| 351 | |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 352 | static PyMethodDef Fm_methods[] = { |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 353 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 354 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 355 | {"InitFonts", (PyCFunction)Fm_InitFonts, 1, |
| 356 | "() -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 357 | #endif |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 358 | {"GetFontName", (PyCFunction)Fm_GetFontName, 1, |
| 359 | "(short familyID) -> (Str255 name)"}, |
| 360 | {"GetFNum", (PyCFunction)Fm_GetFNum, 1, |
| 361 | "(Str255 name) -> (short familyID)"}, |
| 362 | {"RealFont", (PyCFunction)Fm_RealFont, 1, |
| 363 | "(short fontNum, short size) -> (Boolean _rv)"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 364 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 365 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 366 | {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1, |
| 367 | "(Boolean lockFlag) -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 368 | #endif |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 369 | {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1, |
| 370 | "(Boolean fscaleDisable) -> None"}, |
| 371 | {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1, |
| 372 | "() -> (FMetricRec theMetrics)"}, |
| 373 | {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1, |
| 374 | "(Boolean fractEnable) -> None"}, |
| 375 | {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1, |
| 376 | "() -> (short _rv)"}, |
| 377 | {"IsOutline", (PyCFunction)Fm_IsOutline, 1, |
| 378 | "(Point numer, Point denom) -> (Boolean _rv)"}, |
| 379 | {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1, |
| 380 | "(Boolean outlinePreferred) -> None"}, |
| 381 | {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1, |
| 382 | "() -> (Boolean _rv)"}, |
| 383 | {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1, |
| 384 | "(Boolean preserveGlyph) -> None"}, |
| 385 | {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1, |
| 386 | "() -> (Boolean _rv)"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 387 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 388 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 389 | {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1, |
| 390 | "() -> None"}, |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 391 | #endif |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 392 | {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1, |
| 393 | "() -> (short _rv)"}, |
| 394 | {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1, |
| 395 | "() -> (short _rv)"}, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 396 | {"SetAntiAliasedTextEnabled", (PyCFunction)Fm_SetAntiAliasedTextEnabled, 1, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 397 | "(Boolean iEnable, SInt16 iMinFontSize) -> None"}, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 398 | {"IsAntiAliasedTextEnabled", (PyCFunction)Fm_IsAntiAliasedTextEnabled, 1, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 399 | "() -> (Boolean _rv, SInt16 oMinFontSize)"}, |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 400 | {NULL, NULL, 0} |
| 401 | }; |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | void initFm() |
| 407 | { |
| 408 | PyObject *m; |
| 409 | PyObject *d; |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | m = Py_InitModule("Fm", Fm_methods); |
| 415 | d = PyModule_GetDict(m); |
| 416 | Fm_Error = PyMac_GetOSErrException(); |
| 417 | if (Fm_Error == NULL || |
| 418 | PyDict_SetItemString(d, "Error", Fm_Error) != 0) |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 419 | return; |
Jack Jansen | 6259af9 | 1996-01-09 17:15:16 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* ========================= End module Fm ========================== */ |
| 423 | |