blob: 0a072670fd056937cbf9083d50b2ac996ed12d52 [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
Jack Jansenfa77e1a2001-05-22 21:56:42 +000011#ifdef WITHOUT_FRAMEWORKS
Jack Jansen6259af91996-01-09 17:15:16 +000012#include <Fonts.h>
Jack Jansenfa77e1a2001-05-22 21:56:42 +000013#else
14#include <Carbon/Carbon.h>
15#endif
16
Jack Jansen6259af91996-01-09 17:15:16 +000017
18/*
19** Parse/generate ComponentDescriptor records
20*/
Jack Jansen9d8b96c2000-07-14 22:16:45 +000021static PyObject *
Jack Jansenfa77e1a2001-05-22 21:56:42 +000022FMRec_New(FMetricRec *itself)
Jack Jansen6259af91996-01-09 17:15:16 +000023{
24
25 return Py_BuildValue("O&O&O&O&O&",
26 PyMac_BuildFixed, itself->ascent,
27 PyMac_BuildFixed, itself->descent,
28 PyMac_BuildFixed, itself->leading,
29 PyMac_BuildFixed, itself->widMax,
30 ResObj_New, itself->wTabHandle);
31}
32
33#if 0
34/* Not needed... */
Jack Jansen9d8b96c2000-07-14 22:16:45 +000035static int
Jack Jansenfa77e1a2001-05-22 21:56:42 +000036FMRec_Convert(PyObject *v, FMetricRec *p_itself)
Jack Jansen6259af91996-01-09 17:15:16 +000037{
38 return PyArg_ParseTuple(v, "O&O&O&O&O&",
39 PyMac_GetFixed, &itself->ascent,
40 PyMac_GetFixed, &itself->descent,
41 PyMac_GetFixed, &itself->leading,
42 PyMac_GetFixed, &itself->widMax,
43 ResObj_Convert, &itself->wTabHandle);
44}
45#endif
46
47
48static PyObject *Fm_Error;
49
Jack Jansen74a1e632000-07-14 22:37:27 +000050#if !TARGET_API_MAC_CARBON
Jack Jansen8d929ae2000-06-21 22:07:06 +000051
Jack Jansenfa77e1a2001-05-22 21:56:42 +000052static PyObject *Fm_InitFonts(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +000053{
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
Jack Jansenfa77e1a2001-05-22 21:56:42 +000064static PyObject *Fm_GetFontName(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +000065{
66 PyObject *_res = NULL;
67 short familyID;
68 Str255 name;
69 if (!PyArg_ParseTuple(_args, "h",
70 &familyID))
71 return NULL;
72 GetFontName(familyID,
73 name);
74 _res = Py_BuildValue("O&",
75 PyMac_BuildStr255, name);
76 return _res;
77}
78
Jack Jansenfa77e1a2001-05-22 21:56:42 +000079static PyObject *Fm_GetFNum(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +000080{
81 PyObject *_res = NULL;
82 Str255 name;
83 short familyID;
84 if (!PyArg_ParseTuple(_args, "O&",
85 PyMac_GetStr255, name))
86 return NULL;
87 GetFNum(name,
88 &familyID);
89 _res = Py_BuildValue("h",
90 familyID);
91 return _res;
92}
93
Jack Jansenfa77e1a2001-05-22 21:56:42 +000094static PyObject *Fm_RealFont(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +000095{
96 PyObject *_res = NULL;
97 Boolean _rv;
98 short fontNum;
99 short size;
100 if (!PyArg_ParseTuple(_args, "hh",
101 &fontNum,
102 &size))
103 return NULL;
104 _rv = RealFont(fontNum,
105 size);
106 _res = Py_BuildValue("b",
107 _rv);
108 return _res;
109}
110
Jack Jansen74a1e632000-07-14 22:37:27 +0000111#if !TARGET_API_MAC_CARBON
Jack Jansen8d929ae2000-06-21 22:07:06 +0000112
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000113static PyObject *Fm_SetFontLock(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000114{
115 PyObject *_res = NULL;
116 Boolean lockFlag;
117 if (!PyArg_ParseTuple(_args, "b",
118 &lockFlag))
119 return NULL;
120 SetFontLock(lockFlag);
121 Py_INCREF(Py_None);
122 _res = Py_None;
123 return _res;
124}
Jack Jansen8d929ae2000-06-21 22:07:06 +0000125#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000126
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000127static PyObject *Fm_SetFScaleDisable(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000128{
129 PyObject *_res = NULL;
130 Boolean fscaleDisable;
131 if (!PyArg_ParseTuple(_args, "b",
132 &fscaleDisable))
133 return NULL;
134 SetFScaleDisable(fscaleDisable);
135 Py_INCREF(Py_None);
136 _res = Py_None;
137 return _res;
138}
139
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000140static PyObject *Fm_FontMetrics(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000141{
142 PyObject *_res = NULL;
143 FMetricRec theMetrics;
144 if (!PyArg_ParseTuple(_args, ""))
145 return NULL;
146 FontMetrics(&theMetrics);
147 _res = Py_BuildValue("O&",
148 FMRec_New, &theMetrics);
149 return _res;
150}
151
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000152static PyObject *Fm_SetFractEnable(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000153{
154 PyObject *_res = NULL;
155 Boolean fractEnable;
156 if (!PyArg_ParseTuple(_args, "b",
157 &fractEnable))
158 return NULL;
159 SetFractEnable(fractEnable);
160 Py_INCREF(Py_None);
161 _res = Py_None;
162 return _res;
163}
164
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000165static PyObject *Fm_GetDefFontSize(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000166{
167 PyObject *_res = NULL;
168 short _rv;
169 if (!PyArg_ParseTuple(_args, ""))
170 return NULL;
171 _rv = GetDefFontSize();
172 _res = Py_BuildValue("h",
173 _rv);
174 return _res;
175}
176
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000177static PyObject *Fm_IsOutline(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000178{
179 PyObject *_res = NULL;
180 Boolean _rv;
181 Point numer;
182 Point denom;
183 if (!PyArg_ParseTuple(_args, "O&O&",
184 PyMac_GetPoint, &numer,
185 PyMac_GetPoint, &denom))
186 return NULL;
187 _rv = IsOutline(numer,
188 denom);
189 _res = Py_BuildValue("b",
190 _rv);
191 return _res;
192}
193
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000194static PyObject *Fm_SetOutlinePreferred(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000195{
196 PyObject *_res = NULL;
197 Boolean outlinePreferred;
198 if (!PyArg_ParseTuple(_args, "b",
199 &outlinePreferred))
200 return NULL;
201 SetOutlinePreferred(outlinePreferred);
202 Py_INCREF(Py_None);
203 _res = Py_None;
204 return _res;
205}
206
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000207static PyObject *Fm_GetOutlinePreferred(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000208{
209 PyObject *_res = NULL;
210 Boolean _rv;
211 if (!PyArg_ParseTuple(_args, ""))
212 return NULL;
213 _rv = GetOutlinePreferred();
214 _res = Py_BuildValue("b",
215 _rv);
216 return _res;
217}
218
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000219static PyObject *Fm_SetPreserveGlyph(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000220{
221 PyObject *_res = NULL;
222 Boolean preserveGlyph;
223 if (!PyArg_ParseTuple(_args, "b",
224 &preserveGlyph))
225 return NULL;
226 SetPreserveGlyph(preserveGlyph);
227 Py_INCREF(Py_None);
228 _res = Py_None;
229 return _res;
230}
231
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000232static PyObject *Fm_GetPreserveGlyph(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000233{
234 PyObject *_res = NULL;
235 Boolean _rv;
236 if (!PyArg_ParseTuple(_args, ""))
237 return NULL;
238 _rv = GetPreserveGlyph();
239 _res = Py_BuildValue("b",
240 _rv);
241 return _res;
242}
243
Jack Jansen74a1e632000-07-14 22:37:27 +0000244#if !TARGET_API_MAC_CARBON
Jack Jansen8d929ae2000-06-21 22:07:06 +0000245
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000246static PyObject *Fm_FlushFonts(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000247{
248 PyObject *_res = NULL;
249 OSErr _err;
250 if (!PyArg_ParseTuple(_args, ""))
251 return NULL;
252 _err = FlushFonts();
253 if (_err != noErr) return PyMac_Error(_err);
254 Py_INCREF(Py_None);
255 _res = Py_None;
256 return _res;
257}
Jack Jansen8d929ae2000-06-21 22:07:06 +0000258#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000259
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000260static PyObject *Fm_GetSysFont(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000261{
262 PyObject *_res = NULL;
263 short _rv;
264 if (!PyArg_ParseTuple(_args, ""))
265 return NULL;
266 _rv = GetSysFont();
267 _res = Py_BuildValue("h",
268 _rv);
269 return _res;
270}
271
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000272static PyObject *Fm_GetAppFont(PyObject *_self, PyObject *_args)
Jack Jansen6259af91996-01-09 17:15:16 +0000273{
274 PyObject *_res = NULL;
275 short _rv;
276 if (!PyArg_ParseTuple(_args, ""))
277 return NULL;
278 _rv = GetAppFont();
279 _res = Py_BuildValue("h",
280 _rv);
281 return _res;
282}
283
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000284static PyObject *Fm_SetAntiAliasedTextEnabled(PyObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000285{
286 PyObject *_res = NULL;
287 OSStatus _err;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000288 Boolean iEnable;
289 SInt16 iMinFontSize;
Jack Jansena05ac601999-12-12 21:41:51 +0000290 if (!PyArg_ParseTuple(_args, "bh",
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000291 &iEnable,
292 &iMinFontSize))
Jack Jansena05ac601999-12-12 21:41:51 +0000293 return NULL;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000294 _err = SetAntiAliasedTextEnabled(iEnable,
295 iMinFontSize);
Jack Jansena05ac601999-12-12 21:41:51 +0000296 if (_err != noErr) return PyMac_Error(_err);
297 Py_INCREF(Py_None);
298 _res = Py_None;
299 return _res;
300}
301
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000302static PyObject *Fm_IsAntiAliasedTextEnabled(PyObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000303{
304 PyObject *_res = NULL;
305 Boolean _rv;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000306 SInt16 oMinFontSize;
Jack Jansena05ac601999-12-12 21:41:51 +0000307 if (!PyArg_ParseTuple(_args, ""))
308 return NULL;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000309 _rv = IsAntiAliasedTextEnabled(&oMinFontSize);
Jack Jansena05ac601999-12-12 21:41:51 +0000310 _res = Py_BuildValue("bh",
311 _rv,
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000312 oMinFontSize);
Jack Jansena05ac601999-12-12 21:41:51 +0000313 return _res;
314}
315
Jack Jansen6259af91996-01-09 17:15:16 +0000316static PyMethodDef Fm_methods[] = {
Jack Jansen8d929ae2000-06-21 22:07:06 +0000317
Jack Jansen74a1e632000-07-14 22:37:27 +0000318#if !TARGET_API_MAC_CARBON
Jack Jansen6259af91996-01-09 17:15:16 +0000319 {"InitFonts", (PyCFunction)Fm_InitFonts, 1,
320 "() -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000321#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000322 {"GetFontName", (PyCFunction)Fm_GetFontName, 1,
323 "(short familyID) -> (Str255 name)"},
324 {"GetFNum", (PyCFunction)Fm_GetFNum, 1,
325 "(Str255 name) -> (short familyID)"},
326 {"RealFont", (PyCFunction)Fm_RealFont, 1,
327 "(short fontNum, short size) -> (Boolean _rv)"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000328
Jack Jansen74a1e632000-07-14 22:37:27 +0000329#if !TARGET_API_MAC_CARBON
Jack Jansen6259af91996-01-09 17:15:16 +0000330 {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1,
331 "(Boolean lockFlag) -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000332#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000333 {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1,
334 "(Boolean fscaleDisable) -> None"},
335 {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1,
336 "() -> (FMetricRec theMetrics)"},
337 {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1,
338 "(Boolean fractEnable) -> None"},
339 {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1,
340 "() -> (short _rv)"},
341 {"IsOutline", (PyCFunction)Fm_IsOutline, 1,
342 "(Point numer, Point denom) -> (Boolean _rv)"},
343 {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1,
344 "(Boolean outlinePreferred) -> None"},
345 {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1,
346 "() -> (Boolean _rv)"},
347 {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1,
348 "(Boolean preserveGlyph) -> None"},
349 {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1,
350 "() -> (Boolean _rv)"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000351
Jack Jansen74a1e632000-07-14 22:37:27 +0000352#if !TARGET_API_MAC_CARBON
Jack Jansen6259af91996-01-09 17:15:16 +0000353 {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1,
354 "() -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000355#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000356 {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
357 "() -> (short _rv)"},
358 {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
359 "() -> (short _rv)"},
Jack Jansena05ac601999-12-12 21:41:51 +0000360 {"SetAntiAliasedTextEnabled", (PyCFunction)Fm_SetAntiAliasedTextEnabled, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000361 "(Boolean iEnable, SInt16 iMinFontSize) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000362 {"IsAntiAliasedTextEnabled", (PyCFunction)Fm_IsAntiAliasedTextEnabled, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000363 "() -> (Boolean _rv, SInt16 oMinFontSize)"},
Jack Jansen6259af91996-01-09 17:15:16 +0000364 {NULL, NULL, 0}
365};
366
367
368
369
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000370void initFm(void)
Jack Jansen6259af91996-01-09 17:15:16 +0000371{
372 PyObject *m;
373 PyObject *d;
374
375
376
377
378 m = Py_InitModule("Fm", Fm_methods);
379 d = PyModule_GetDict(m);
380 Fm_Error = PyMac_GetOSErrException();
381 if (Fm_Error == NULL ||
382 PyDict_SetItemString(d, "Error", Fm_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000383 return;
Jack Jansen6259af91996-01-09 17:15:16 +0000384}
385
386/* ========================= End module Fm ========================== */
387