summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/fm/_Fmmodule.c
blob: e6497f2c5425af48e8170bf8c71bbd58e1920953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437

/* =========================== Module _Fm =========================== */

#include "Python.h"



#ifdef _WIN32
#include "pywintoolbox.h"
#else
#include "macglue.h"
#include "pymactoolbox.h"
#endif

/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
    	PyErr_SetString(PyExc_NotImplementedError, \
    	"Not available in this shared library/OS version"); \
    	return NULL; \
    }} while(0)


#ifdef WITHOUT_FRAMEWORKS
#include <Fonts.h>
#else
#include <Carbon/Carbon.h>
#endif


/*
** Parse/generate ComponentDescriptor records
*/
static PyObject *
FMRec_New(FMetricRec *itself)
{

	return Py_BuildValue("O&O&O&O&O&", 
		PyMac_BuildFixed, itself->ascent,
		PyMac_BuildFixed, itself->descent,
		PyMac_BuildFixed, itself->leading,
		PyMac_BuildFixed, itself->widMax,
		ResObj_New, itself->wTabHandle);
}

#if 0
/* Not needed... */
static int
FMRec_Convert(PyObject *v, FMetricRec *p_itself)
{
	return PyArg_ParseTuple(v, "O&O&O&O&O&",
		PyMac_GetFixed, &itself->ascent,
		PyMac_GetFixed, &itself->descent,
		PyMac_GetFixed, &itself->leading,
		PyMac_GetFixed, &itself->widMax,
		ResObj_Convert, &itself->wTabHandle);
}
#endif


static PyObject *Fm_Error;

#if !TARGET_API_MAC_CARBON

static PyObject *Fm_InitFonts(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
#ifndef InitFonts
	PyMac_PRECHECK(InitFonts);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	InitFonts();
	Py_INCREF(Py_None);
	_res = Py_None;
	return _res;
}
#endif

static PyObject *Fm_GetFontName(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	short familyID;
	Str255 name;
#ifndef GetFontName
	PyMac_PRECHECK(GetFontName);
#endif
	if (!PyArg_ParseTuple(_args, "h",
	                      &familyID))
		return NULL;
	GetFontName(familyID,
	            name);
	_res = Py_BuildValue("O&",
	                     PyMac_BuildStr255, name);
	return _res;
}

static PyObject *Fm_GetFNum(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Str255 name;
	short familyID;
#ifndef GetFNum
	PyMac_PRECHECK(GetFNum);
#endif
	if (!PyArg_ParseTuple(_args, "O&",
	                      PyMac_GetStr255, name))
		return NULL;
	GetFNum(name,
	        &familyID);
	_res = Py_BuildValue("h",
	                     familyID);
	return _res;
}

static PyObject *Fm_RealFont(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Boolean _rv;
	short fontNum;
	short size;
#ifndef RealFont
	PyMac_PRECHECK(RealFont);
#endif
	if (!PyArg_ParseTuple(_args, "hh",
	                      &fontNum,
	                      &size))
		return NULL;
	_rv = RealFont(fontNum,
	               size);
	_res = Py_BuildValue("b",
	                     _rv);
	return _res;
}

#if !TARGET_API_MAC_CARBON

static PyObject *Fm_SetFontLock(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Boolean lockFlag;
#ifndef SetFontLock
	PyMac_PRECHECK(SetFontLock);
#endif
	if (!PyArg_ParseTuple(_args, "b",
	                      &lockFlag))
		return NULL;
	SetFontLock(lockFlag);
	Py_INCREF(Py_None);
	_res = Py_None;
	return _res;
}
#endif

static PyObject *Fm_SetFScaleDisable(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Boolean fscaleDisable;
#ifndef SetFScaleDisable
	PyMac_PRECHECK(SetFScaleDisable);
#endif
	if (!PyArg_ParseTuple(_args, "b",
	                      &fscaleDisable))
		return NULL;
	SetFScaleDisable(fscaleDisable);
	Py_INCREF(Py_None);
	_res = Py_None;
	return _res;
}

static PyObject *Fm_FontMetrics(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	FMetricRec theMetrics;
#ifndef FontMetrics
	PyMac_PRECHECK(FontMetrics);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	FontMetrics(&theMetrics);
	_res = Py_BuildValue("O&",
	                     FMRec_New, &theMetrics);
	return _res;
}

static PyObject *Fm_SetFractEnable(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Boolean fractEnable;
#ifndef SetFractEnable
	PyMac_PRECHECK(SetFractEnable);
#endif
	if (!PyArg_ParseTuple(_args, "b",
	                      &fractEnable))
		return NULL;
	SetFractEnable(fractEnable);
	Py_INCREF(Py_None);
	_res = Py_None;
	return _res;
}

static PyObject *Fm_GetDefFontSize(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	short _rv;
#ifndef GetDefFontSize
	PyMac_PRECHECK(GetDefFontSize);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_rv = GetDefFontSize();
	_res = Py_BuildValue("h",
	                     _rv);
	return _res;
}

static PyObject *Fm_IsOutline(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Boolean _rv;
	Point numer;
	Point denom;
#ifndef IsOutline
	PyMac_PRECHECK(IsOutline);
#endif
	if (!PyArg_ParseTuple(_args, "O&O&",
	                      PyMac_GetPoint, &numer,
	                      PyMac_GetPoint, &denom))
		return NULL;
	_rv = IsOutline(numer,
	                denom);
	_res = Py_BuildValue("b",
	                     _rv);
	return _res;
}

static PyObject *Fm_SetOutlinePreferred(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Boolean outlinePreferred;
#ifndef SetOutlinePreferred
	PyMac_PRECHECK(SetOutlinePreferred);
#endif
	if (!PyArg_ParseTuple(_args, "b",
	                      &outlinePreferred))
		return NULL;
	SetOutlinePreferred(outlinePreferred);
	Py_INCREF(Py_None);
	_res = Py_None;
	return _res;
}

static PyObject *Fm_GetOutlinePreferred(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Boolean _rv;
#ifndef GetOutlinePreferred
	PyMac_PRECHECK(GetOutlinePreferred);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_rv = GetOutlinePreferred();
	_res = Py_BuildValue("b",
	                     _rv);
	return _res;
}

static PyObject *Fm_SetPreserveGlyph(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Boolean preserveGlyph;
#ifndef SetPreserveGlyph
	PyMac_PRECHECK(SetPreserveGlyph);
#endif
	if (!PyArg_ParseTuple(_args, "b",
	                      &preserveGlyph))
		return NULL;
	SetPreserveGlyph(preserveGlyph);
	Py_INCREF(Py_None);
	_res = Py_None;
	return _res;
}

static PyObject *Fm_GetPreserveGlyph(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	Boolean _rv;
#ifndef GetPreserveGlyph
	PyMac_PRECHECK(GetPreserveGlyph);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_rv = GetPreserveGlyph();
	_res = Py_BuildValue("b",
	                     _rv);
	return _res;
}

#if !TARGET_API_MAC_CARBON

static PyObject *Fm_FlushFonts(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
#ifndef FlushFonts
	PyMac_PRECHECK(FlushFonts);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_err = FlushFonts();
	if (_err != noErr) return PyMac_Error(_err);
	Py_INCREF(Py_None);
	_res = Py_None;
	return _res;
}
#endif

static PyObject *Fm_GetSysFont(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	short _rv;
#ifndef GetSysFont
	PyMac_PRECHECK(GetSysFont);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_rv = GetSysFont();
	_res = Py_BuildValue("h",
	                     _rv);
	return _res;
}

static PyObject *Fm_GetAppFont(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	short _rv;
#ifndef GetAppFont
	PyMac_PRECHECK(GetAppFont);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_rv = GetAppFont();
	_res = Py_BuildValue("h",
	                     _rv);
	return _res;
}

static PyObject *Fm_QDTextBounds(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	char *inText__in__;
	int inText__len__;
	int inText__in_len__;
	Rect bounds;
#ifndef QDTextBounds
	PyMac_PRECHECK(QDTextBounds);
#endif
	if (!PyArg_ParseTuple(_args, "s#",
	                      &inText__in__, &inText__in_len__))
		return NULL;
	inText__len__ = inText__in_len__;
	QDTextBounds(inText__len__, inText__in__,
	             &bounds);
	_res = Py_BuildValue("O&",
	                     PyMac_BuildRect, &bounds);
	return _res;
}

static PyMethodDef Fm_methods[] = {

#if !TARGET_API_MAC_CARBON
	{"InitFonts", (PyCFunction)Fm_InitFonts, 1,
	 "() -> None"},
#endif
	{"GetFontName", (PyCFunction)Fm_GetFontName, 1,
	 "(short familyID) -> (Str255 name)"},
	{"GetFNum", (PyCFunction)Fm_GetFNum, 1,
	 "(Str255 name) -> (short familyID)"},
	{"RealFont", (PyCFunction)Fm_RealFont, 1,
	 "(short fontNum, short size) -> (Boolean _rv)"},

#if !TARGET_API_MAC_CARBON
	{"SetFontLock", (PyCFunction)Fm_SetFontLock, 1,
	 "(Boolean lockFlag) -> None"},
#endif
	{"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1,
	 "(Boolean fscaleDisable) -> None"},
	{"FontMetrics", (PyCFunction)Fm_FontMetrics, 1,
	 "() -> (FMetricRec theMetrics)"},
	{"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1,
	 "(Boolean fractEnable) -> None"},
	{"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1,
	 "() -> (short _rv)"},
	{"IsOutline", (PyCFunction)Fm_IsOutline, 1,
	 "(Point numer, Point denom) -> (Boolean _rv)"},
	{"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1,
	 "(Boolean outlinePreferred) -> None"},
	{"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1,
	 "() -> (Boolean _rv)"},
	{"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1,
	 "(Boolean preserveGlyph) -> None"},
	{"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1,
	 "() -> (Boolean _rv)"},

#if !TARGET_API_MAC_CARBON
	{"FlushFonts", (PyCFunction)Fm_FlushFonts, 1,
	 "() -> None"},
#endif
	{"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
	 "() -> (short _rv)"},
	{"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
	 "() -> (short _rv)"},
	{"QDTextBounds", (PyCFunction)Fm_QDTextBounds, 1,
	 "(Buffer inText) -> (Rect bounds)"},
	{NULL, NULL, 0}
};




void init_Fm(void)
{
	PyObject *m;
	PyObject *d;




	m = Py_InitModule("_Fm", Fm_methods);
	d = PyModule_GetDict(m);
	Fm_Error = PyMac_GetOSErrException();
	if (Fm_Error == NULL ||
	    PyDict_SetItemString(d, "Error", Fm_Error) != 0)
		return;
}

/* ========================= End module _Fm ========================= */