blob: 1d84a31d52f8c75a06b3a5e14d782279ab21a095 [file] [log] [blame]
Jack Jansen6259af91996-01-09 17:15:16 +00001
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
16extern PyObject *ResObj_New(Handle);
17extern int ResObj_Convert(PyObject *, Handle *);
18extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
20
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
23extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
25
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
37extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
Jack Jansen6259af91996-01-09 17:15:16 +000043extern PyObject *WinObj_WhichWindow(WindowPtr);
44
45#include <Fonts.h>
46
47/*
48** Parse/generate ComponentDescriptor records
49*/
50PyObject *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... */
64FMRec_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
78static PyObject *Fm_Error;
79
80static 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
93static 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
110static 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
127static 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
146static 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
161static 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
176static 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
190static 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
205static 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
219static 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
238static 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
253static 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
267static 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
282static 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
296static 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
311static 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
325static 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
Jack Jansena05ac601999-12-12 21:41:51 +0000339static PyObject *Fm_SetAntiAliasedTextEnabled(_self, _args)
340 PyObject *_self;
341 PyObject *_args;
342{
343 PyObject *_res = NULL;
344 OSStatus _err;
345 Boolean inEnable;
346 SInt16 inMinFontSize;
347 if (!PyArg_ParseTuple(_args, "bh",
348 &inEnable,
349 &inMinFontSize))
350 return NULL;
351 _err = SetAntiAliasedTextEnabled(inEnable,
352 inMinFontSize);
353 if (_err != noErr) return PyMac_Error(_err);
354 Py_INCREF(Py_None);
355 _res = Py_None;
356 return _res;
357}
358
359static PyObject *Fm_IsAntiAliasedTextEnabled(_self, _args)
360 PyObject *_self;
361 PyObject *_args;
362{
363 PyObject *_res = NULL;
364 Boolean _rv;
365 SInt16 outMinFontSize;
366 if (!PyArg_ParseTuple(_args, ""))
367 return NULL;
368 _rv = IsAntiAliasedTextEnabled(&outMinFontSize);
369 _res = Py_BuildValue("bh",
370 _rv,
371 outMinFontSize);
372 return _res;
373}
374
Jack Jansen6259af91996-01-09 17:15:16 +0000375static PyMethodDef Fm_methods[] = {
376 {"InitFonts", (PyCFunction)Fm_InitFonts, 1,
377 "() -> None"},
378 {"GetFontName", (PyCFunction)Fm_GetFontName, 1,
379 "(short familyID) -> (Str255 name)"},
380 {"GetFNum", (PyCFunction)Fm_GetFNum, 1,
381 "(Str255 name) -> (short familyID)"},
382 {"RealFont", (PyCFunction)Fm_RealFont, 1,
383 "(short fontNum, short size) -> (Boolean _rv)"},
384 {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1,
385 "(Boolean lockFlag) -> None"},
386 {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1,
387 "(Boolean fscaleDisable) -> None"},
388 {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1,
389 "() -> (FMetricRec theMetrics)"},
390 {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1,
391 "(Boolean fractEnable) -> None"},
392 {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1,
393 "() -> (short _rv)"},
394 {"IsOutline", (PyCFunction)Fm_IsOutline, 1,
395 "(Point numer, Point denom) -> (Boolean _rv)"},
396 {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1,
397 "(Boolean outlinePreferred) -> None"},
398 {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1,
399 "() -> (Boolean _rv)"},
400 {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1,
401 "(Boolean preserveGlyph) -> None"},
402 {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1,
403 "() -> (Boolean _rv)"},
404 {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1,
405 "() -> None"},
406 {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
407 "() -> (short _rv)"},
408 {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
409 "() -> (short _rv)"},
Jack Jansena05ac601999-12-12 21:41:51 +0000410 {"SetAntiAliasedTextEnabled", (PyCFunction)Fm_SetAntiAliasedTextEnabled, 1,
411 "(Boolean inEnable, SInt16 inMinFontSize) -> None"},
412 {"IsAntiAliasedTextEnabled", (PyCFunction)Fm_IsAntiAliasedTextEnabled, 1,
413 "() -> (Boolean _rv, SInt16 outMinFontSize)"},
Jack Jansen6259af91996-01-09 17:15:16 +0000414 {NULL, NULL, 0}
415};
416
417
418
419
420void initFm()
421{
422 PyObject *m;
423 PyObject *d;
424
425
426
427
428 m = Py_InitModule("Fm", Fm_methods);
429 d = PyModule_GetDict(m);
430 Fm_Error = PyMac_GetOSErrException();
431 if (Fm_Error == NULL ||
432 PyDict_SetItemString(d, "Error", Fm_Error) != 0)
433 Py_FatalError("can't initialize Fm.Error");
434}
435
436/* ========================= End module Fm ========================== */
437