blob: 0d66d16912c3d39b30f6904f7eb707336582efb4 [file] [log] [blame]
Jack Jansen6259af91996-01-09 17:15:16 +00001
2/* =========================== Module Fm ============================ */
3
4#include "Python.h"
5
6
7
Jack Jansen6259af91996-01-09 17:15:16 +00008#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Jack Jansen6259af91996-01-09 17:15:16 +000010
11#include <Fonts.h>
12
13/*
14** Parse/generate ComponentDescriptor records
15*/
Jack Jansen9d8b96c2000-07-14 22:16:45 +000016static PyObject *
17FMRec_New(itself)
Jack Jansen6259af91996-01-09 17:15:16 +000018 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 Jansen9d8b96c2000-07-14 22:16:45 +000031static int
Jack Jansen6259af91996-01-09 17:15:16 +000032FMRec_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
46static PyObject *Fm_Error;
47
Jack Jansen74a1e632000-07-14 22:37:27 +000048#if !TARGET_API_MAC_CARBON
Jack Jansen8d929ae2000-06-21 22:07:06 +000049
Jack Jansen6259af91996-01-09 17:15:16 +000050static 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 Jansen8d929ae2000-06-21 22:07:06 +000062#endif
Jack Jansen6259af91996-01-09 17:15:16 +000063
64static 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
81static 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
98static 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 Jansen74a1e632000-07-14 22:37:27 +0000117#if !TARGET_API_MAC_CARBON
Jack Jansen8d929ae2000-06-21 22:07:06 +0000118
Jack Jansen6259af91996-01-09 17:15:16 +0000119static 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 Jansen8d929ae2000-06-21 22:07:06 +0000133#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000134
135static 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
150static 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
164static 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
179static 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
193static 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
212static 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
227static 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
241static 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
256static 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 Jansen74a1e632000-07-14 22:37:27 +0000270#if !TARGET_API_MAC_CARBON
Jack Jansen8d929ae2000-06-21 22:07:06 +0000271
Jack Jansen6259af91996-01-09 17:15:16 +0000272static 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 Jansen8d929ae2000-06-21 22:07:06 +0000286#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000287
288static 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
302static 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 Jansena05ac601999-12-12 21:41:51 +0000316static PyObject *Fm_SetAntiAliasedTextEnabled(_self, _args)
317 PyObject *_self;
318 PyObject *_args;
319{
320 PyObject *_res = NULL;
321 OSStatus _err;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000322 Boolean iEnable;
323 SInt16 iMinFontSize;
Jack Jansena05ac601999-12-12 21:41:51 +0000324 if (!PyArg_ParseTuple(_args, "bh",
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000325 &iEnable,
326 &iMinFontSize))
Jack Jansena05ac601999-12-12 21:41:51 +0000327 return NULL;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000328 _err = SetAntiAliasedTextEnabled(iEnable,
329 iMinFontSize);
Jack Jansena05ac601999-12-12 21:41:51 +0000330 if (_err != noErr) return PyMac_Error(_err);
331 Py_INCREF(Py_None);
332 _res = Py_None;
333 return _res;
334}
335
336static PyObject *Fm_IsAntiAliasedTextEnabled(_self, _args)
337 PyObject *_self;
338 PyObject *_args;
339{
340 PyObject *_res = NULL;
341 Boolean _rv;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000342 SInt16 oMinFontSize;
Jack Jansena05ac601999-12-12 21:41:51 +0000343 if (!PyArg_ParseTuple(_args, ""))
344 return NULL;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000345 _rv = IsAntiAliasedTextEnabled(&oMinFontSize);
Jack Jansena05ac601999-12-12 21:41:51 +0000346 _res = Py_BuildValue("bh",
347 _rv,
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000348 oMinFontSize);
Jack Jansena05ac601999-12-12 21:41:51 +0000349 return _res;
350}
351
Jack Jansen6259af91996-01-09 17:15:16 +0000352static PyMethodDef Fm_methods[] = {
Jack Jansen8d929ae2000-06-21 22:07:06 +0000353
Jack Jansen74a1e632000-07-14 22:37:27 +0000354#if !TARGET_API_MAC_CARBON
Jack Jansen6259af91996-01-09 17:15:16 +0000355 {"InitFonts", (PyCFunction)Fm_InitFonts, 1,
356 "() -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000357#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000358 {"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 Jansen8d929ae2000-06-21 22:07:06 +0000364
Jack Jansen74a1e632000-07-14 22:37:27 +0000365#if !TARGET_API_MAC_CARBON
Jack Jansen6259af91996-01-09 17:15:16 +0000366 {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1,
367 "(Boolean lockFlag) -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000368#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000369 {"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 Jansen8d929ae2000-06-21 22:07:06 +0000387
Jack Jansen74a1e632000-07-14 22:37:27 +0000388#if !TARGET_API_MAC_CARBON
Jack Jansen6259af91996-01-09 17:15:16 +0000389 {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1,
390 "() -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000391#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000392 {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
393 "() -> (short _rv)"},
394 {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
395 "() -> (short _rv)"},
Jack Jansena05ac601999-12-12 21:41:51 +0000396 {"SetAntiAliasedTextEnabled", (PyCFunction)Fm_SetAntiAliasedTextEnabled, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000397 "(Boolean iEnable, SInt16 iMinFontSize) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000398 {"IsAntiAliasedTextEnabled", (PyCFunction)Fm_IsAntiAliasedTextEnabled, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000399 "() -> (Boolean _rv, SInt16 oMinFontSize)"},
Jack Jansen6259af91996-01-09 17:15:16 +0000400 {NULL, NULL, 0}
401};
402
403
404
405
406void 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 Jansenf7d5aa62000-12-10 23:43:49 +0000419 return;
Jack Jansen6259af91996-01-09 17:15:16 +0000420}
421
422/* ========================= End module Fm ========================== */
423