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