typo: use one instead instead of two
[python.git] / Mac / Modules / fm / _Fmmodule.c
blobb982cc31aaf528a30168c7330e2e839826dcbf89
2 /* =========================== Module _Fm =========================== */
4 #include "Python.h"
6 #ifndef __LP64__
9 #include "pymactoolbox.h"
11 /* Macro to test whether a weak-loaded CFM function exists */
12 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
13 PyErr_SetString(PyExc_NotImplementedError, \
14 "Not available in this shared library/OS version"); \
15 return NULL; \
16 }} while(0)
19 #include <Carbon/Carbon.h>
23 ** Parse/generate ComponentDescriptor records
25 static PyObject *
26 FMRec_New(FMetricRec *itself)
29 return Py_BuildValue("O&O&O&O&O&",
30 PyMac_BuildFixed, itself->ascent,
31 PyMac_BuildFixed, itself->descent,
32 PyMac_BuildFixed, itself->leading,
33 PyMac_BuildFixed, itself->widMax,
34 ResObj_New, itself->wTabHandle);
37 #if 0
38 /* Not needed... */
39 static int
40 FMRec_Convert(PyObject *v, FMetricRec *p_itself)
42 return PyArg_ParseTuple(v, "O&O&O&O&O&",
43 PyMac_GetFixed, &itself->ascent,
44 PyMac_GetFixed, &itself->descent,
45 PyMac_GetFixed, &itself->leading,
46 PyMac_GetFixed, &itself->widMax,
47 ResObj_Convert, &itself->wTabHandle);
49 #endif
52 static PyObject *Fm_Error;
54 static PyObject *Fm_GetFontName(PyObject *_self, PyObject *_args)
56 PyObject *_res = NULL;
57 short familyID;
58 Str255 name;
59 #ifndef GetFontName
60 PyMac_PRECHECK(GetFontName);
61 #endif
62 if (!PyArg_ParseTuple(_args, "h",
63 &familyID))
64 return NULL;
65 GetFontName(familyID,
66 name);
67 _res = Py_BuildValue("O&",
68 PyMac_BuildStr255, name);
69 return _res;
72 static PyObject *Fm_GetFNum(PyObject *_self, PyObject *_args)
74 PyObject *_res = NULL;
75 Str255 name;
76 short familyID;
77 #ifndef GetFNum
78 PyMac_PRECHECK(GetFNum);
79 #endif
80 if (!PyArg_ParseTuple(_args, "O&",
81 PyMac_GetStr255, name))
82 return NULL;
83 GetFNum(name,
84 &familyID);
85 _res = Py_BuildValue("h",
86 familyID);
87 return _res;
90 static PyObject *Fm_RealFont(PyObject *_self, PyObject *_args)
92 PyObject *_res = NULL;
93 Boolean _rv;
94 short fontNum;
95 short size;
96 #ifndef RealFont
97 PyMac_PRECHECK(RealFont);
98 #endif
99 if (!PyArg_ParseTuple(_args, "hh",
100 &fontNum,
101 &size))
102 return NULL;
103 _rv = RealFont(fontNum,
104 size);
105 _res = Py_BuildValue("b",
106 _rv);
107 return _res;
110 static PyObject *Fm_SetFScaleDisable(PyObject *_self, PyObject *_args)
112 PyObject *_res = NULL;
113 Boolean fscaleDisable;
114 #ifndef SetFScaleDisable
115 PyMac_PRECHECK(SetFScaleDisable);
116 #endif
117 if (!PyArg_ParseTuple(_args, "b",
118 &fscaleDisable))
119 return NULL;
120 SetFScaleDisable(fscaleDisable);
121 Py_INCREF(Py_None);
122 _res = Py_None;
123 return _res;
126 static PyObject *Fm_FontMetrics(PyObject *_self, PyObject *_args)
128 PyObject *_res = NULL;
129 FMetricRec theMetrics;
130 #ifndef FontMetrics
131 PyMac_PRECHECK(FontMetrics);
132 #endif
133 if (!PyArg_ParseTuple(_args, ""))
134 return NULL;
135 FontMetrics(&theMetrics);
136 _res = Py_BuildValue("O&",
137 FMRec_New, &theMetrics);
138 return _res;
141 static PyObject *Fm_SetFractEnable(PyObject *_self, PyObject *_args)
143 PyObject *_res = NULL;
144 Boolean fractEnable;
145 #ifndef SetFractEnable
146 PyMac_PRECHECK(SetFractEnable);
147 #endif
148 if (!PyArg_ParseTuple(_args, "b",
149 &fractEnable))
150 return NULL;
151 SetFractEnable(fractEnable);
152 Py_INCREF(Py_None);
153 _res = Py_None;
154 return _res;
157 static PyObject *Fm_GetDefFontSize(PyObject *_self, PyObject *_args)
159 PyObject *_res = NULL;
160 short _rv;
161 #ifndef GetDefFontSize
162 PyMac_PRECHECK(GetDefFontSize);
163 #endif
164 if (!PyArg_ParseTuple(_args, ""))
165 return NULL;
166 _rv = GetDefFontSize();
167 _res = Py_BuildValue("h",
168 _rv);
169 return _res;
172 static PyObject *Fm_IsOutline(PyObject *_self, PyObject *_args)
174 PyObject *_res = NULL;
175 Boolean _rv;
176 Point numer;
177 Point denom;
178 #ifndef IsOutline
179 PyMac_PRECHECK(IsOutline);
180 #endif
181 if (!PyArg_ParseTuple(_args, "O&O&",
182 PyMac_GetPoint, &numer,
183 PyMac_GetPoint, &denom))
184 return NULL;
185 _rv = IsOutline(numer,
186 denom);
187 _res = Py_BuildValue("b",
188 _rv);
189 return _res;
192 static PyObject *Fm_SetOutlinePreferred(PyObject *_self, PyObject *_args)
194 PyObject *_res = NULL;
195 Boolean outlinePreferred;
196 #ifndef SetOutlinePreferred
197 PyMac_PRECHECK(SetOutlinePreferred);
198 #endif
199 if (!PyArg_ParseTuple(_args, "b",
200 &outlinePreferred))
201 return NULL;
202 SetOutlinePreferred(outlinePreferred);
203 Py_INCREF(Py_None);
204 _res = Py_None;
205 return _res;
208 static PyObject *Fm_GetOutlinePreferred(PyObject *_self, PyObject *_args)
210 PyObject *_res = NULL;
211 Boolean _rv;
212 #ifndef GetOutlinePreferred
213 PyMac_PRECHECK(GetOutlinePreferred);
214 #endif
215 if (!PyArg_ParseTuple(_args, ""))
216 return NULL;
217 _rv = GetOutlinePreferred();
218 _res = Py_BuildValue("b",
219 _rv);
220 return _res;
223 static PyObject *Fm_SetPreserveGlyph(PyObject *_self, PyObject *_args)
225 PyObject *_res = NULL;
226 Boolean preserveGlyph;
227 #ifndef SetPreserveGlyph
228 PyMac_PRECHECK(SetPreserveGlyph);
229 #endif
230 if (!PyArg_ParseTuple(_args, "b",
231 &preserveGlyph))
232 return NULL;
233 SetPreserveGlyph(preserveGlyph);
234 Py_INCREF(Py_None);
235 _res = Py_None;
236 return _res;
239 static PyObject *Fm_GetPreserveGlyph(PyObject *_self, PyObject *_args)
241 PyObject *_res = NULL;
242 Boolean _rv;
243 #ifndef GetPreserveGlyph
244 PyMac_PRECHECK(GetPreserveGlyph);
245 #endif
246 if (!PyArg_ParseTuple(_args, ""))
247 return NULL;
248 _rv = GetPreserveGlyph();
249 _res = Py_BuildValue("b",
250 _rv);
251 return _res;
254 static PyObject *Fm_GetSysFont(PyObject *_self, PyObject *_args)
256 PyObject *_res = NULL;
257 short _rv;
258 #ifndef GetSysFont
259 PyMac_PRECHECK(GetSysFont);
260 #endif
261 if (!PyArg_ParseTuple(_args, ""))
262 return NULL;
263 _rv = GetSysFont();
264 _res = Py_BuildValue("h",
265 _rv);
266 return _res;
269 static PyObject *Fm_GetAppFont(PyObject *_self, PyObject *_args)
271 PyObject *_res = NULL;
272 short _rv;
273 #ifndef GetAppFont
274 PyMac_PRECHECK(GetAppFont);
275 #endif
276 if (!PyArg_ParseTuple(_args, ""))
277 return NULL;
278 _rv = GetAppFont();
279 _res = Py_BuildValue("h",
280 _rv);
281 return _res;
284 static PyObject *Fm_QDTextBounds(PyObject *_self, PyObject *_args)
286 PyObject *_res = NULL;
287 char *inText__in__;
288 int inText__len__;
289 int inText__in_len__;
290 Rect bounds;
291 #ifndef QDTextBounds
292 PyMac_PRECHECK(QDTextBounds);
293 #endif
294 if (!PyArg_ParseTuple(_args, "s#",
295 &inText__in__, &inText__in_len__))
296 return NULL;
297 inText__len__ = inText__in_len__;
298 QDTextBounds(inText__len__, inText__in__,
299 &bounds);
300 _res = Py_BuildValue("O&",
301 PyMac_BuildRect, &bounds);
302 return _res;
305 static PyMethodDef Fm_methods[] = {
306 {"GetFontName", (PyCFunction)Fm_GetFontName, 1,
307 PyDoc_STR("(short familyID) -> (Str255 name)")},
308 {"GetFNum", (PyCFunction)Fm_GetFNum, 1,
309 PyDoc_STR("(Str255 name) -> (short familyID)")},
310 {"RealFont", (PyCFunction)Fm_RealFont, 1,
311 PyDoc_STR("(short fontNum, short size) -> (Boolean _rv)")},
312 {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1,
313 PyDoc_STR("(Boolean fscaleDisable) -> None")},
314 {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1,
315 PyDoc_STR("() -> (FMetricRec theMetrics)")},
316 {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1,
317 PyDoc_STR("(Boolean fractEnable) -> None")},
318 {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1,
319 PyDoc_STR("() -> (short _rv)")},
320 {"IsOutline", (PyCFunction)Fm_IsOutline, 1,
321 PyDoc_STR("(Point numer, Point denom) -> (Boolean _rv)")},
322 {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1,
323 PyDoc_STR("(Boolean outlinePreferred) -> None")},
324 {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1,
325 PyDoc_STR("() -> (Boolean _rv)")},
326 {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1,
327 PyDoc_STR("(Boolean preserveGlyph) -> None")},
328 {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1,
329 PyDoc_STR("() -> (Boolean _rv)")},
330 {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
331 PyDoc_STR("() -> (short _rv)")},
332 {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
333 PyDoc_STR("() -> (short _rv)")},
334 {"QDTextBounds", (PyCFunction)Fm_QDTextBounds, 1,
335 PyDoc_STR("(Buffer inText) -> (Rect bounds)")},
336 {NULL, NULL, 0}
339 #else /* __LP64__ */
341 static PyMethodDef Fm_methods[] = {
342 {NULL, NULL, 0}
345 #endif /* __LP64__ */
347 void init_Fm(void)
349 PyObject *m;
350 #ifndef __LP64__
351 PyObject *d;
352 #endif /* __LP64__ */
357 m = Py_InitModule("_Fm", Fm_methods);
358 #ifndef __LP64__
359 d = PyModule_GetDict(m);
360 Fm_Error = PyMac_GetOSErrException();
361 if (Fm_Error == NULL ||
362 PyDict_SetItemString(d, "Error", Fm_Error) != 0)
363 return;
364 #endif /* __LP64__ */
367 /* ========================= End module _Fm ========================= */