blob: 0469b6cb12af03d8b36df22cc4ecfdf34824958e [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
284static PyMethodDef Fm_methods[] = {
Jack Jansen8d929ae2000-06-21 22:07:06 +0000285
Jack Jansen74a1e632000-07-14 22:37:27 +0000286#if !TARGET_API_MAC_CARBON
Jack Jansen6259af91996-01-09 17:15:16 +0000287 {"InitFonts", (PyCFunction)Fm_InitFonts, 1,
288 "() -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000289#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000290 {"GetFontName", (PyCFunction)Fm_GetFontName, 1,
291 "(short familyID) -> (Str255 name)"},
292 {"GetFNum", (PyCFunction)Fm_GetFNum, 1,
293 "(Str255 name) -> (short familyID)"},
294 {"RealFont", (PyCFunction)Fm_RealFont, 1,
295 "(short fontNum, short size) -> (Boolean _rv)"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000296
Jack Jansen74a1e632000-07-14 22:37:27 +0000297#if !TARGET_API_MAC_CARBON
Jack Jansen6259af91996-01-09 17:15:16 +0000298 {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1,
299 "(Boolean lockFlag) -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000300#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000301 {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1,
302 "(Boolean fscaleDisable) -> None"},
303 {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1,
304 "() -> (FMetricRec theMetrics)"},
305 {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1,
306 "(Boolean fractEnable) -> None"},
307 {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1,
308 "() -> (short _rv)"},
309 {"IsOutline", (PyCFunction)Fm_IsOutline, 1,
310 "(Point numer, Point denom) -> (Boolean _rv)"},
311 {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1,
312 "(Boolean outlinePreferred) -> None"},
313 {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1,
314 "() -> (Boolean _rv)"},
315 {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1,
316 "(Boolean preserveGlyph) -> None"},
317 {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1,
318 "() -> (Boolean _rv)"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000319
Jack Jansen74a1e632000-07-14 22:37:27 +0000320#if !TARGET_API_MAC_CARBON
Jack Jansen6259af91996-01-09 17:15:16 +0000321 {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1,
322 "() -> None"},
Jack Jansen8d929ae2000-06-21 22:07:06 +0000323#endif
Jack Jansen6259af91996-01-09 17:15:16 +0000324 {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
325 "() -> (short _rv)"},
326 {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
327 "() -> (short _rv)"},
Jack Jansen6259af91996-01-09 17:15:16 +0000328 {NULL, NULL, 0}
329};
330
331
332
333
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000334void initFm(void)
Jack Jansen6259af91996-01-09 17:15:16 +0000335{
336 PyObject *m;
337 PyObject *d;
338
339
340
341
342 m = Py_InitModule("Fm", Fm_methods);
343 d = PyModule_GetDict(m);
344 Fm_Error = PyMac_GetOSErrException();
345 if (Fm_Error == NULL ||
346 PyDict_SetItemString(d, "Error", Fm_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000347 return;
Jack Jansen6259af91996-01-09 17:15:16 +0000348}
349
350/* ========================= End module Fm ========================== */
351