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 | |
| 80 | static PyObject *Fm_InitFonts(_self, _args) |
| 81 | PyObject *_self; |
| 82 | PyObject *_args; |
| 83 | { |
| 84 | PyObject *_res = NULL; |
| 85 | if (!PyArg_ParseTuple(_args, "")) |
| 86 | return NULL; |
| 87 | InitFonts(); |
| 88 | Py_INCREF(Py_None); |
| 89 | _res = Py_None; |
| 90 | return _res; |
| 91 | } |
| 92 | |
| 93 | static PyObject *Fm_GetFontName(_self, _args) |
| 94 | PyObject *_self; |
| 95 | PyObject *_args; |
| 96 | { |
| 97 | PyObject *_res = NULL; |
| 98 | short familyID; |
| 99 | Str255 name; |
| 100 | if (!PyArg_ParseTuple(_args, "h", |
| 101 | &familyID)) |
| 102 | return NULL; |
| 103 | GetFontName(familyID, |
| 104 | name); |
| 105 | _res = Py_BuildValue("O&", |
| 106 | PyMac_BuildStr255, name); |
| 107 | return _res; |
| 108 | } |
| 109 | |
| 110 | static PyObject *Fm_GetFNum(_self, _args) |
| 111 | PyObject *_self; |
| 112 | PyObject *_args; |
| 113 | { |
| 114 | PyObject *_res = NULL; |
| 115 | Str255 name; |
| 116 | short familyID; |
| 117 | if (!PyArg_ParseTuple(_args, "O&", |
| 118 | PyMac_GetStr255, name)) |
| 119 | return NULL; |
| 120 | GetFNum(name, |
| 121 | &familyID); |
| 122 | _res = Py_BuildValue("h", |
| 123 | familyID); |
| 124 | return _res; |
| 125 | } |
| 126 | |
| 127 | static PyObject *Fm_RealFont(_self, _args) |
| 128 | PyObject *_self; |
| 129 | PyObject *_args; |
| 130 | { |
| 131 | PyObject *_res = NULL; |
| 132 | Boolean _rv; |
| 133 | short fontNum; |
| 134 | short size; |
| 135 | if (!PyArg_ParseTuple(_args, "hh", |
| 136 | &fontNum, |
| 137 | &size)) |
| 138 | return NULL; |
| 139 | _rv = RealFont(fontNum, |
| 140 | size); |
| 141 | _res = Py_BuildValue("b", |
| 142 | _rv); |
| 143 | return _res; |
| 144 | } |
| 145 | |
| 146 | static PyObject *Fm_SetFontLock(_self, _args) |
| 147 | PyObject *_self; |
| 148 | PyObject *_args; |
| 149 | { |
| 150 | PyObject *_res = NULL; |
| 151 | Boolean lockFlag; |
| 152 | if (!PyArg_ParseTuple(_args, "b", |
| 153 | &lockFlag)) |
| 154 | return NULL; |
| 155 | SetFontLock(lockFlag); |
| 156 | Py_INCREF(Py_None); |
| 157 | _res = Py_None; |
| 158 | return _res; |
| 159 | } |
| 160 | |
| 161 | static PyObject *Fm_SetFScaleDisable(_self, _args) |
| 162 | PyObject *_self; |
| 163 | PyObject *_args; |
| 164 | { |
| 165 | PyObject *_res = NULL; |
| 166 | Boolean fscaleDisable; |
| 167 | if (!PyArg_ParseTuple(_args, "b", |
| 168 | &fscaleDisable)) |
| 169 | return NULL; |
| 170 | SetFScaleDisable(fscaleDisable); |
| 171 | Py_INCREF(Py_None); |
| 172 | _res = Py_None; |
| 173 | return _res; |
| 174 | } |
| 175 | |
| 176 | static PyObject *Fm_FontMetrics(_self, _args) |
| 177 | PyObject *_self; |
| 178 | PyObject *_args; |
| 179 | { |
| 180 | PyObject *_res = NULL; |
| 181 | FMetricRec theMetrics; |
| 182 | if (!PyArg_ParseTuple(_args, "")) |
| 183 | return NULL; |
| 184 | FontMetrics(&theMetrics); |
| 185 | _res = Py_BuildValue("O&", |
| 186 | FMRec_New, &theMetrics); |
| 187 | return _res; |
| 188 | } |
| 189 | |
| 190 | static PyObject *Fm_SetFractEnable(_self, _args) |
| 191 | PyObject *_self; |
| 192 | PyObject *_args; |
| 193 | { |
| 194 | PyObject *_res = NULL; |
| 195 | Boolean fractEnable; |
| 196 | if (!PyArg_ParseTuple(_args, "b", |
| 197 | &fractEnable)) |
| 198 | return NULL; |
| 199 | SetFractEnable(fractEnable); |
| 200 | Py_INCREF(Py_None); |
| 201 | _res = Py_None; |
| 202 | return _res; |
| 203 | } |
| 204 | |
| 205 | static PyObject *Fm_GetDefFontSize(_self, _args) |
| 206 | PyObject *_self; |
| 207 | PyObject *_args; |
| 208 | { |
| 209 | PyObject *_res = NULL; |
| 210 | short _rv; |
| 211 | if (!PyArg_ParseTuple(_args, "")) |
| 212 | return NULL; |
| 213 | _rv = GetDefFontSize(); |
| 214 | _res = Py_BuildValue("h", |
| 215 | _rv); |
| 216 | return _res; |
| 217 | } |
| 218 | |
| 219 | static PyObject *Fm_IsOutline(_self, _args) |
| 220 | PyObject *_self; |
| 221 | PyObject *_args; |
| 222 | { |
| 223 | PyObject *_res = NULL; |
| 224 | Boolean _rv; |
| 225 | Point numer; |
| 226 | Point denom; |
| 227 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 228 | PyMac_GetPoint, &numer, |
| 229 | PyMac_GetPoint, &denom)) |
| 230 | return NULL; |
| 231 | _rv = IsOutline(numer, |
| 232 | denom); |
| 233 | _res = Py_BuildValue("b", |
| 234 | _rv); |
| 235 | return _res; |
| 236 | } |
| 237 | |
| 238 | static PyObject *Fm_SetOutlinePreferred(_self, _args) |
| 239 | PyObject *_self; |
| 240 | PyObject *_args; |
| 241 | { |
| 242 | PyObject *_res = NULL; |
| 243 | Boolean outlinePreferred; |
| 244 | if (!PyArg_ParseTuple(_args, "b", |
| 245 | &outlinePreferred)) |
| 246 | return NULL; |
| 247 | SetOutlinePreferred(outlinePreferred); |
| 248 | Py_INCREF(Py_None); |
| 249 | _res = Py_None; |
| 250 | return _res; |
| 251 | } |
| 252 | |
| 253 | static PyObject *Fm_GetOutlinePreferred(_self, _args) |
| 254 | PyObject *_self; |
| 255 | PyObject *_args; |
| 256 | { |
| 257 | PyObject *_res = NULL; |
| 258 | Boolean _rv; |
| 259 | if (!PyArg_ParseTuple(_args, "")) |
| 260 | return NULL; |
| 261 | _rv = GetOutlinePreferred(); |
| 262 | _res = Py_BuildValue("b", |
| 263 | _rv); |
| 264 | return _res; |
| 265 | } |
| 266 | |
| 267 | static PyObject *Fm_SetPreserveGlyph(_self, _args) |
| 268 | PyObject *_self; |
| 269 | PyObject *_args; |
| 270 | { |
| 271 | PyObject *_res = NULL; |
| 272 | Boolean preserveGlyph; |
| 273 | if (!PyArg_ParseTuple(_args, "b", |
| 274 | &preserveGlyph)) |
| 275 | return NULL; |
| 276 | SetPreserveGlyph(preserveGlyph); |
| 277 | Py_INCREF(Py_None); |
| 278 | _res = Py_None; |
| 279 | return _res; |
| 280 | } |
| 281 | |
| 282 | static PyObject *Fm_GetPreserveGlyph(_self, _args) |
| 283 | PyObject *_self; |
| 284 | PyObject *_args; |
| 285 | { |
| 286 | PyObject *_res = NULL; |
| 287 | Boolean _rv; |
| 288 | if (!PyArg_ParseTuple(_args, "")) |
| 289 | return NULL; |
| 290 | _rv = GetPreserveGlyph(); |
| 291 | _res = Py_BuildValue("b", |
| 292 | _rv); |
| 293 | return _res; |
| 294 | } |
| 295 | |
| 296 | static PyObject *Fm_FlushFonts(_self, _args) |
| 297 | PyObject *_self; |
| 298 | PyObject *_args; |
| 299 | { |
| 300 | PyObject *_res = NULL; |
| 301 | OSErr _err; |
| 302 | if (!PyArg_ParseTuple(_args, "")) |
| 303 | return NULL; |
| 304 | _err = FlushFonts(); |
| 305 | if (_err != noErr) return PyMac_Error(_err); |
| 306 | Py_INCREF(Py_None); |
| 307 | _res = Py_None; |
| 308 | return _res; |
| 309 | } |
| 310 | |
| 311 | static PyObject *Fm_GetSysFont(_self, _args) |
| 312 | PyObject *_self; |
| 313 | PyObject *_args; |
| 314 | { |
| 315 | PyObject *_res = NULL; |
| 316 | short _rv; |
| 317 | if (!PyArg_ParseTuple(_args, "")) |
| 318 | return NULL; |
| 319 | _rv = GetSysFont(); |
| 320 | _res = Py_BuildValue("h", |
| 321 | _rv); |
| 322 | return _res; |
| 323 | } |
| 324 | |
| 325 | static PyObject *Fm_GetAppFont(_self, _args) |
| 326 | PyObject *_self; |
| 327 | PyObject *_args; |
| 328 | { |
| 329 | PyObject *_res = NULL; |
| 330 | short _rv; |
| 331 | if (!PyArg_ParseTuple(_args, "")) |
| 332 | return NULL; |
| 333 | _rv = GetAppFont(); |
| 334 | _res = Py_BuildValue("h", |
| 335 | _rv); |
| 336 | return _res; |
| 337 | } |
| 338 | |
| 339 | static PyMethodDef Fm_methods[] = { |
| 340 | {"InitFonts", (PyCFunction)Fm_InitFonts, 1, |
| 341 | "() -> None"}, |
| 342 | {"GetFontName", (PyCFunction)Fm_GetFontName, 1, |
| 343 | "(short familyID) -> (Str255 name)"}, |
| 344 | {"GetFNum", (PyCFunction)Fm_GetFNum, 1, |
| 345 | "(Str255 name) -> (short familyID)"}, |
| 346 | {"RealFont", (PyCFunction)Fm_RealFont, 1, |
| 347 | "(short fontNum, short size) -> (Boolean _rv)"}, |
| 348 | {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1, |
| 349 | "(Boolean lockFlag) -> None"}, |
| 350 | {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1, |
| 351 | "(Boolean fscaleDisable) -> None"}, |
| 352 | {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1, |
| 353 | "() -> (FMetricRec theMetrics)"}, |
| 354 | {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1, |
| 355 | "(Boolean fractEnable) -> None"}, |
| 356 | {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1, |
| 357 | "() -> (short _rv)"}, |
| 358 | {"IsOutline", (PyCFunction)Fm_IsOutline, 1, |
| 359 | "(Point numer, Point denom) -> (Boolean _rv)"}, |
| 360 | {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1, |
| 361 | "(Boolean outlinePreferred) -> None"}, |
| 362 | {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1, |
| 363 | "() -> (Boolean _rv)"}, |
| 364 | {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1, |
| 365 | "(Boolean preserveGlyph) -> None"}, |
| 366 | {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1, |
| 367 | "() -> (Boolean _rv)"}, |
| 368 | {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1, |
| 369 | "() -> None"}, |
| 370 | {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1, |
| 371 | "() -> (short _rv)"}, |
| 372 | {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1, |
| 373 | "() -> (short _rv)"}, |
| 374 | {NULL, NULL, 0} |
| 375 | }; |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | void initFm() |
| 381 | { |
| 382 | PyObject *m; |
| 383 | PyObject *d; |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | m = Py_InitModule("Fm", Fm_methods); |
| 389 | d = PyModule_GetDict(m); |
| 390 | Fm_Error = PyMac_GetOSErrException(); |
| 391 | if (Fm_Error == NULL || |
| 392 | PyDict_SetItemString(d, "Error", Fm_Error) != 0) |
| 393 | Py_FatalError("can't initialize Fm.Error"); |
| 394 | } |
| 395 | |
| 396 | /* ========================= End module Fm ========================== */ |
| 397 | |