Added ref to Misc/NEWS file; added hint to run regen script on Linux.
[python/dscho.git] / Mac / Modules / fm / Fmmodule.c
blobef264bca11d4652e691a59df8593f2232909eb71
2 /* =========================== Module Fm ============================ */
4 #include "Python.h"
8 #define SystemSevenOrLater 1
10 #include "macglue.h"
11 #include <Memory.h>
12 #include <Dialogs.h>
13 #include <Menus.h>
14 #include <Controls.h>
16 extern PyObject *ResObj_New(Handle);
17 extern int ResObj_Convert(PyObject *, Handle *);
18 extern PyObject *OptResObj_New(Handle);
19 extern int OptResObj_Convert(PyObject *, Handle *);
21 extern PyObject *WinObj_New(WindowPtr);
22 extern int WinObj_Convert(PyObject *, WindowPtr *);
23 extern PyTypeObject Window_Type;
24 #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
26 extern PyObject *DlgObj_New(DialogPtr);
27 extern int DlgObj_Convert(PyObject *, DialogPtr *);
28 extern PyTypeObject Dialog_Type;
29 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
31 extern PyObject *MenuObj_New(MenuHandle);
32 extern int MenuObj_Convert(PyObject *, MenuHandle *);
34 extern PyObject *CtlObj_New(ControlHandle);
35 extern int CtlObj_Convert(PyObject *, ControlHandle *);
37 extern PyObject *GrafObj_New(GrafPtr);
38 extern int GrafObj_Convert(PyObject *, GrafPtr *);
40 extern PyObject *BMObj_New(BitMapPtr);
41 extern int BMObj_Convert(PyObject *, BitMapPtr *);
43 extern PyObject *PMObj_New(PixMapHandle);
44 extern int PMObj_Convert(PyObject *, PixMapHandle *);
46 extern PyObject *WinObj_WhichWindow(WindowPtr);
48 #include <Fonts.h>
51 ** Parse/generate ComponentDescriptor records
53 PyObject *FMRec_New(itself)
54 FMetricRec *itself;
57 return Py_BuildValue("O&O&O&O&O&",
58 PyMac_BuildFixed, itself->ascent,
59 PyMac_BuildFixed, itself->descent,
60 PyMac_BuildFixed, itself->leading,
61 PyMac_BuildFixed, itself->widMax,
62 ResObj_New, itself->wTabHandle);
65 #if 0
66 /* Not needed... */
67 FMRec_Convert(v, p_itself)
68 PyObject *v;
69 FMetricRec *p_itself;
71 return PyArg_ParseTuple(v, "O&O&O&O&O&",
72 PyMac_GetFixed, &itself->ascent,
73 PyMac_GetFixed, &itself->descent,
74 PyMac_GetFixed, &itself->leading,
75 PyMac_GetFixed, &itself->widMax,
76 ResObj_Convert, &itself->wTabHandle);
78 #endif
81 static PyObject *Fm_Error;
83 static PyObject *Fm_InitFonts(_self, _args)
84 PyObject *_self;
85 PyObject *_args;
87 PyObject *_res = NULL;
88 if (!PyArg_ParseTuple(_args, ""))
89 return NULL;
90 InitFonts();
91 Py_INCREF(Py_None);
92 _res = Py_None;
93 return _res;
96 static PyObject *Fm_GetFontName(_self, _args)
97 PyObject *_self;
98 PyObject *_args;
100 PyObject *_res = NULL;
101 short familyID;
102 Str255 name;
103 if (!PyArg_ParseTuple(_args, "h",
104 &familyID))
105 return NULL;
106 GetFontName(familyID,
107 name);
108 _res = Py_BuildValue("O&",
109 PyMac_BuildStr255, name);
110 return _res;
113 static PyObject *Fm_GetFNum(_self, _args)
114 PyObject *_self;
115 PyObject *_args;
117 PyObject *_res = NULL;
118 Str255 name;
119 short familyID;
120 if (!PyArg_ParseTuple(_args, "O&",
121 PyMac_GetStr255, name))
122 return NULL;
123 GetFNum(name,
124 &familyID);
125 _res = Py_BuildValue("h",
126 familyID);
127 return _res;
130 static PyObject *Fm_RealFont(_self, _args)
131 PyObject *_self;
132 PyObject *_args;
134 PyObject *_res = NULL;
135 Boolean _rv;
136 short fontNum;
137 short size;
138 if (!PyArg_ParseTuple(_args, "hh",
139 &fontNum,
140 &size))
141 return NULL;
142 _rv = RealFont(fontNum,
143 size);
144 _res = Py_BuildValue("b",
145 _rv);
146 return _res;
149 static PyObject *Fm_SetFontLock(_self, _args)
150 PyObject *_self;
151 PyObject *_args;
153 PyObject *_res = NULL;
154 Boolean lockFlag;
155 if (!PyArg_ParseTuple(_args, "b",
156 &lockFlag))
157 return NULL;
158 SetFontLock(lockFlag);
159 Py_INCREF(Py_None);
160 _res = Py_None;
161 return _res;
164 static PyObject *Fm_SetFScaleDisable(_self, _args)
165 PyObject *_self;
166 PyObject *_args;
168 PyObject *_res = NULL;
169 Boolean fscaleDisable;
170 if (!PyArg_ParseTuple(_args, "b",
171 &fscaleDisable))
172 return NULL;
173 SetFScaleDisable(fscaleDisable);
174 Py_INCREF(Py_None);
175 _res = Py_None;
176 return _res;
179 static PyObject *Fm_FontMetrics(_self, _args)
180 PyObject *_self;
181 PyObject *_args;
183 PyObject *_res = NULL;
184 FMetricRec theMetrics;
185 if (!PyArg_ParseTuple(_args, ""))
186 return NULL;
187 FontMetrics(&theMetrics);
188 _res = Py_BuildValue("O&",
189 FMRec_New, &theMetrics);
190 return _res;
193 static PyObject *Fm_SetFractEnable(_self, _args)
194 PyObject *_self;
195 PyObject *_args;
197 PyObject *_res = NULL;
198 Boolean fractEnable;
199 if (!PyArg_ParseTuple(_args, "b",
200 &fractEnable))
201 return NULL;
202 SetFractEnable(fractEnable);
203 Py_INCREF(Py_None);
204 _res = Py_None;
205 return _res;
208 static PyObject *Fm_GetDefFontSize(_self, _args)
209 PyObject *_self;
210 PyObject *_args;
212 PyObject *_res = NULL;
213 short _rv;
214 if (!PyArg_ParseTuple(_args, ""))
215 return NULL;
216 _rv = GetDefFontSize();
217 _res = Py_BuildValue("h",
218 _rv);
219 return _res;
222 static PyObject *Fm_IsOutline(_self, _args)
223 PyObject *_self;
224 PyObject *_args;
226 PyObject *_res = NULL;
227 Boolean _rv;
228 Point numer;
229 Point denom;
230 if (!PyArg_ParseTuple(_args, "O&O&",
231 PyMac_GetPoint, &numer,
232 PyMac_GetPoint, &denom))
233 return NULL;
234 _rv = IsOutline(numer,
235 denom);
236 _res = Py_BuildValue("b",
237 _rv);
238 return _res;
241 static PyObject *Fm_SetOutlinePreferred(_self, _args)
242 PyObject *_self;
243 PyObject *_args;
245 PyObject *_res = NULL;
246 Boolean outlinePreferred;
247 if (!PyArg_ParseTuple(_args, "b",
248 &outlinePreferred))
249 return NULL;
250 SetOutlinePreferred(outlinePreferred);
251 Py_INCREF(Py_None);
252 _res = Py_None;
253 return _res;
256 static PyObject *Fm_GetOutlinePreferred(_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 = GetOutlinePreferred();
265 _res = Py_BuildValue("b",
266 _rv);
267 return _res;
270 static PyObject *Fm_SetPreserveGlyph(_self, _args)
271 PyObject *_self;
272 PyObject *_args;
274 PyObject *_res = NULL;
275 Boolean preserveGlyph;
276 if (!PyArg_ParseTuple(_args, "b",
277 &preserveGlyph))
278 return NULL;
279 SetPreserveGlyph(preserveGlyph);
280 Py_INCREF(Py_None);
281 _res = Py_None;
282 return _res;
285 static PyObject *Fm_GetPreserveGlyph(_self, _args)
286 PyObject *_self;
287 PyObject *_args;
289 PyObject *_res = NULL;
290 Boolean _rv;
291 if (!PyArg_ParseTuple(_args, ""))
292 return NULL;
293 _rv = GetPreserveGlyph();
294 _res = Py_BuildValue("b",
295 _rv);
296 return _res;
299 static PyObject *Fm_FlushFonts(_self, _args)
300 PyObject *_self;
301 PyObject *_args;
303 PyObject *_res = NULL;
304 OSErr _err;
305 if (!PyArg_ParseTuple(_args, ""))
306 return NULL;
307 _err = FlushFonts();
308 if (_err != noErr) return PyMac_Error(_err);
309 Py_INCREF(Py_None);
310 _res = Py_None;
311 return _res;
314 static PyObject *Fm_GetSysFont(_self, _args)
315 PyObject *_self;
316 PyObject *_args;
318 PyObject *_res = NULL;
319 short _rv;
320 if (!PyArg_ParseTuple(_args, ""))
321 return NULL;
322 _rv = GetSysFont();
323 _res = Py_BuildValue("h",
324 _rv);
325 return _res;
328 static PyObject *Fm_GetAppFont(_self, _args)
329 PyObject *_self;
330 PyObject *_args;
332 PyObject *_res = NULL;
333 short _rv;
334 if (!PyArg_ParseTuple(_args, ""))
335 return NULL;
336 _rv = GetAppFont();
337 _res = Py_BuildValue("h",
338 _rv);
339 return _res;
342 static PyMethodDef Fm_methods[] = {
343 {"InitFonts", (PyCFunction)Fm_InitFonts, 1,
344 "() -> None"},
345 {"GetFontName", (PyCFunction)Fm_GetFontName, 1,
346 "(short familyID) -> (Str255 name)"},
347 {"GetFNum", (PyCFunction)Fm_GetFNum, 1,
348 "(Str255 name) -> (short familyID)"},
349 {"RealFont", (PyCFunction)Fm_RealFont, 1,
350 "(short fontNum, short size) -> (Boolean _rv)"},
351 {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1,
352 "(Boolean lockFlag) -> None"},
353 {"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1,
354 "(Boolean fscaleDisable) -> None"},
355 {"FontMetrics", (PyCFunction)Fm_FontMetrics, 1,
356 "() -> (FMetricRec theMetrics)"},
357 {"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1,
358 "(Boolean fractEnable) -> None"},
359 {"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1,
360 "() -> (short _rv)"},
361 {"IsOutline", (PyCFunction)Fm_IsOutline, 1,
362 "(Point numer, Point denom) -> (Boolean _rv)"},
363 {"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1,
364 "(Boolean outlinePreferred) -> None"},
365 {"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1,
366 "() -> (Boolean _rv)"},
367 {"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1,
368 "(Boolean preserveGlyph) -> None"},
369 {"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1,
370 "() -> (Boolean _rv)"},
371 {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1,
372 "() -> None"},
373 {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
374 "() -> (short _rv)"},
375 {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
376 "() -> (short _rv)"},
377 {NULL, NULL, 0}
383 void initFm()
385 PyObject *m;
386 PyObject *d;
391 m = Py_InitModule("Fm", Fm_methods);
392 d = PyModule_GetDict(m);
393 Fm_Error = PyMac_GetOSErrException();
394 if (Fm_Error == NULL ||
395 PyDict_SetItemString(d, "Error", Fm_Error) != 0)
396 Py_FatalError("can't initialize Fm.Error");
399 /* ========================= End module Fm ========================== */