2001-08-23 11:02:09 -03:00
|
|
|
|
|
|
|
/* =========================== Module _Fm =========================== */
|
|
|
|
|
|
|
|
#include "Python.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "pymactoolbox.h"
|
|
|
|
|
|
|
|
/* Macro to test whether a weak-loaded CFM function exists */
|
|
|
|
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
|
2003-11-19 12:13:35 -04:00
|
|
|
PyErr_SetString(PyExc_NotImplementedError, \
|
|
|
|
"Not available in this shared library/OS version"); \
|
|
|
|
return NULL; \
|
2001-08-23 11:02:09 -03:00
|
|
|
}} while(0)
|
|
|
|
|
|
|
|
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Parse/generate ComponentDescriptor records
|
|
|
|
*/
|
|
|
|
static PyObject *
|
|
|
|
FMRec_New(FMetricRec *itself)
|
|
|
|
{
|
|
|
|
|
2005-07-03 17:59:44 -03:00
|
|
|
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);
|
2001-08-23 11:02:09 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Not needed... */
|
|
|
|
static int
|
|
|
|
FMRec_Convert(PyObject *v, FMetricRec *p_itself)
|
|
|
|
{
|
2005-07-03 17:59:44 -03:00
|
|
|
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);
|
2001-08-23 11:02:09 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static PyObject *Fm_Error;
|
|
|
|
|
|
|
|
static PyObject *Fm_GetFontName(PyObject *_self, PyObject *_args)
|
|
|
|
{
|
|
|
|
PyObject *_res = NULL;
|
|
|
|
short familyID;
|
|
|
|
Str255 name;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef GetFontName
|
|
|
|
PyMac_PRECHECK(GetFontName);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef GetFNum
|
|
|
|
PyMac_PRECHECK(GetFNum);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef RealFont
|
|
|
|
PyMac_PRECHECK(RealFont);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
if (!PyArg_ParseTuple(_args, "hh",
|
|
|
|
&fontNum,
|
|
|
|
&size))
|
|
|
|
return NULL;
|
|
|
|
_rv = RealFont(fontNum,
|
|
|
|
size);
|
|
|
|
_res = Py_BuildValue("b",
|
|
|
|
_rv);
|
|
|
|
return _res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *Fm_SetFScaleDisable(PyObject *_self, PyObject *_args)
|
|
|
|
{
|
|
|
|
PyObject *_res = NULL;
|
|
|
|
Boolean fscaleDisable;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef SetFScaleDisable
|
|
|
|
PyMac_PRECHECK(SetFScaleDisable);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef FontMetrics
|
|
|
|
PyMac_PRECHECK(FontMetrics);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef SetFractEnable
|
|
|
|
PyMac_PRECHECK(SetFractEnable);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef GetDefFontSize
|
|
|
|
PyMac_PRECHECK(GetDefFontSize);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef IsOutline
|
|
|
|
PyMac_PRECHECK(IsOutline);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef SetOutlinePreferred
|
|
|
|
PyMac_PRECHECK(SetOutlinePreferred);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef GetOutlinePreferred
|
|
|
|
PyMac_PRECHECK(GetOutlinePreferred);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef SetPreserveGlyph
|
|
|
|
PyMac_PRECHECK(SetPreserveGlyph);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef GetPreserveGlyph
|
|
|
|
PyMac_PRECHECK(GetPreserveGlyph);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
if (!PyArg_ParseTuple(_args, ""))
|
|
|
|
return NULL;
|
|
|
|
_rv = GetPreserveGlyph();
|
|
|
|
_res = Py_BuildValue("b",
|
|
|
|
_rv);
|
|
|
|
return _res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *Fm_GetSysFont(PyObject *_self, PyObject *_args)
|
|
|
|
{
|
|
|
|
PyObject *_res = NULL;
|
|
|
|
short _rv;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef GetSysFont
|
|
|
|
PyMac_PRECHECK(GetSysFont);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
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;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef GetAppFont
|
|
|
|
PyMac_PRECHECK(GetAppFont);
|
|
|
|
#endif
|
2001-08-23 11:02:09 -03:00
|
|
|
if (!PyArg_ParseTuple(_args, ""))
|
|
|
|
return NULL;
|
|
|
|
_rv = GetAppFont();
|
|
|
|
_res = Py_BuildValue("h",
|
|
|
|
_rv);
|
|
|
|
return _res;
|
|
|
|
}
|
|
|
|
|
2002-01-07 10:15:02 -04:00
|
|
|
static PyObject *Fm_QDTextBounds(PyObject *_self, PyObject *_args)
|
|
|
|
{
|
|
|
|
PyObject *_res = NULL;
|
|
|
|
char *inText__in__;
|
|
|
|
int inText__len__;
|
|
|
|
int inText__in_len__;
|
|
|
|
Rect bounds;
|
2002-03-24 19:04:18 -04:00
|
|
|
#ifndef QDTextBounds
|
|
|
|
PyMac_PRECHECK(QDTextBounds);
|
|
|
|
#endif
|
2002-01-07 10:15:02 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-08-23 11:02:09 -03:00
|
|
|
static PyMethodDef Fm_methods[] = {
|
|
|
|
{"GetFontName", (PyCFunction)Fm_GetFontName, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("(short familyID) -> (Str255 name)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"GetFNum", (PyCFunction)Fm_GetFNum, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("(Str255 name) -> (short familyID)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"RealFont", (PyCFunction)Fm_RealFont, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("(short fontNum, short size) -> (Boolean _rv)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"SetFScaleDisable", (PyCFunction)Fm_SetFScaleDisable, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("(Boolean fscaleDisable) -> None")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"FontMetrics", (PyCFunction)Fm_FontMetrics, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("() -> (FMetricRec theMetrics)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"SetFractEnable", (PyCFunction)Fm_SetFractEnable, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("(Boolean fractEnable) -> None")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"GetDefFontSize", (PyCFunction)Fm_GetDefFontSize, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("() -> (short _rv)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"IsOutline", (PyCFunction)Fm_IsOutline, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("(Point numer, Point denom) -> (Boolean _rv)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"SetOutlinePreferred", (PyCFunction)Fm_SetOutlinePreferred, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("(Boolean outlinePreferred) -> None")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"GetOutlinePreferred", (PyCFunction)Fm_GetOutlinePreferred, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("() -> (Boolean _rv)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"SetPreserveGlyph", (PyCFunction)Fm_SetPreserveGlyph, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("(Boolean preserveGlyph) -> None")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"GetPreserveGlyph", (PyCFunction)Fm_GetPreserveGlyph, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("() -> (Boolean _rv)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"GetSysFont", (PyCFunction)Fm_GetSysFont, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("() -> (short _rv)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{"GetAppFont", (PyCFunction)Fm_GetAppFont, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("() -> (short _rv)")},
|
2002-01-07 10:15:02 -04:00
|
|
|
{"QDTextBounds", (PyCFunction)Fm_QDTextBounds, 1,
|
2002-08-16 06:09:31 -03:00
|
|
|
PyDoc_STR("(Buffer inText) -> (Rect bounds)")},
|
2001-08-23 11:02:09 -03:00
|
|
|
{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 ========================= */
|
|
|
|
|