Bump version to 0.9.1.
[python/dscho.git] / Mac / Modules / fm / Fmmodule.c
blob6d1c5070c793f5aafdea6f09a9c34301b25daef8
2 /* =========================== Module Fm ============================ */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #include <Fonts.h>
14 ** Parse/generate ComponentDescriptor records
16 static PyObject *
17 FMRec_New(itself)
18 FMetricRec *itself;
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);
29 #if 0
30 /* Not needed... */
31 static int
32 FMRec_Convert(v, p_itself)
33 PyObject *v;
34 FMetricRec *p_itself;
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);
43 #endif
46 static PyObject *Fm_Error;
48 #if !TARGET_API_MAC_CARBON
50 static PyObject *Fm_InitFonts(_self, _args)
51 PyObject *_self;
52 PyObject *_args;
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;
62 #endif
64 static PyObject *Fm_GetFontName(_self, _args)
65 PyObject *_self;
66 PyObject *_args;
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;
81 static PyObject *Fm_GetFNum(_self, _args)
82 PyObject *_self;
83 PyObject *_args;
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;
98 static PyObject *Fm_RealFont(_self, _args)
99 PyObject *_self;
100 PyObject *_args;
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;
117 #if !TARGET_API_MAC_CARBON
119 static PyObject *Fm_SetFontLock(_self, _args)
120 PyObject *_self;
121 PyObject *_args;
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;
133 #endif
135 static PyObject *Fm_SetFScaleDisable(_self, _args)
136 PyObject *_self;
137 PyObject *_args;
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;
150 static PyObject *Fm_FontMetrics(_self, _args)
151 PyObject *_self;
152 PyObject *_args;
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;
164 static PyObject *Fm_SetFractEnable(_self, _args)
165 PyObject *_self;
166 PyObject *_args;
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;
179 static PyObject *Fm_GetDefFontSize(_self, _args)
180 PyObject *_self;
181 PyObject *_args;
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;
193 static PyObject *Fm_IsOutline(_self, _args)
194 PyObject *_self;
195 PyObject *_args;
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;
212 static PyObject *Fm_SetOutlinePreferred(_self, _args)
213 PyObject *_self;
214 PyObject *_args;
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;
227 static PyObject *Fm_GetOutlinePreferred(_self, _args)
228 PyObject *_self;
229 PyObject *_args;
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;
241 static PyObject *Fm_SetPreserveGlyph(_self, _args)
242 PyObject *_self;
243 PyObject *_args;
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;
256 static PyObject *Fm_GetPreserveGlyph(_self, _args)
257 PyObject *_self;
258 PyObject *_args;
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;
270 #if !TARGET_API_MAC_CARBON
272 static PyObject *Fm_FlushFonts(_self, _args)
273 PyObject *_self;
274 PyObject *_args;
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;
286 #endif
288 static PyObject *Fm_GetSysFont(_self, _args)
289 PyObject *_self;
290 PyObject *_args;
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;
302 static PyObject *Fm_GetAppFont(_self, _args)
303 PyObject *_self;
304 PyObject *_args;
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;
316 static PyObject *Fm_SetAntiAliasedTextEnabled(_self, _args)
317 PyObject *_self;
318 PyObject *_args;
320 PyObject *_res = NULL;
321 OSStatus _err;
322 Boolean inEnable;
323 SInt16 inMinFontSize;
324 if (!PyArg_ParseTuple(_args, "bh",
325 &inEnable,
326 &inMinFontSize))
327 return NULL;
328 _err = SetAntiAliasedTextEnabled(inEnable,
329 inMinFontSize);
330 if (_err != noErr) return PyMac_Error(_err);
331 Py_INCREF(Py_None);
332 _res = Py_None;
333 return _res;
336 static PyObject *Fm_IsAntiAliasedTextEnabled(_self, _args)
337 PyObject *_self;
338 PyObject *_args;
340 PyObject *_res = NULL;
341 Boolean _rv;
342 SInt16 outMinFontSize;
343 if (!PyArg_ParseTuple(_args, ""))
344 return NULL;
345 _rv = IsAntiAliasedTextEnabled(&outMinFontSize);
346 _res = Py_BuildValue("bh",
347 _rv,
348 outMinFontSize);
349 return _res;
352 static PyMethodDef Fm_methods[] = {
354 #if !TARGET_API_MAC_CARBON
355 {"InitFonts", (PyCFunction)Fm_InitFonts, 1,
356 "() -> None"},
357 #endif
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)"},
365 #if !TARGET_API_MAC_CARBON
366 {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1,
367 "(Boolean lockFlag) -> None"},
368 #endif
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)"},
388 #if !TARGET_API_MAC_CARBON
389 {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1,
390 "() -> None"},
391 #endif
392 {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
393 "() -> (short _rv)"},
394 {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
395 "() -> (short _rv)"},
396 {"SetAntiAliasedTextEnabled", (PyCFunction)Fm_SetAntiAliasedTextEnabled, 1,
397 "(Boolean inEnable, SInt16 inMinFontSize) -> None"},
398 {"IsAntiAliasedTextEnabled", (PyCFunction)Fm_IsAntiAliasedTextEnabled, 1,
399 "() -> (Boolean _rv, SInt16 outMinFontSize)"},
400 {NULL, NULL, 0}
406 void initFm()
408 PyObject *m;
409 PyObject *d;
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)
419 Py_FatalError("can't initialize Fm.Error");
422 /* ========================= End module Fm ========================== */