diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1996-01-09 17:15:16 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1996-01-09 17:15:16 (GMT) |
commit | 6259af9bbbb0968abce4b91b966139fb7b3d386e (patch) | |
tree | 4b43d29e3a8301bcf01e57c4ff71173d3c870b18 /Mac/Modules/fm | |
parent | c8a9949407b753205b3db58719f0be787a039db8 (diff) | |
download | cpython-6259af9bbbb0968abce4b91b966139fb7b3d386e.zip cpython-6259af9bbbb0968abce4b91b966139fb7b3d386e.tar.gz cpython-6259af9bbbb0968abce4b91b966139fb7b3d386e.tar.bz2 |
An interface to the font manager
Diffstat (limited to 'Mac/Modules/fm')
-rw-r--r-- | Mac/Modules/fm/Fmgen.py | 84 | ||||
-rw-r--r-- | Mac/Modules/fm/Fmmodule.c | 400 | ||||
-rw-r--r-- | Mac/Modules/fm/fmscan.py | 46 | ||||
-rw-r--r-- | Mac/Modules/fm/fmsupport.py | 75 |
4 files changed, 605 insertions, 0 deletions
diff --git a/Mac/Modules/fm/Fmgen.py b/Mac/Modules/fm/Fmgen.py new file mode 100644 index 0000000..7d9203f --- /dev/null +++ b/Mac/Modules/fm/Fmgen.py @@ -0,0 +1,84 @@ +# Generated from 'flap:CodeWarrior:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:Fonts.h' + +f = Function(void, 'InitFonts', +) +functions.append(f) + +f = Function(void, 'GetFontName', + (short, 'familyID', InMode), + (Str255, 'name', OutMode), +) +functions.append(f) + +f = Function(void, 'GetFNum', + (ConstStr255Param, 'name', InMode), + (short, 'familyID', OutMode), +) +functions.append(f) + +f = Function(Boolean, 'RealFont', + (short, 'fontNum', InMode), + (short, 'size', InMode), +) +functions.append(f) + +f = Function(void, 'SetFontLock', + (Boolean, 'lockFlag', InMode), +) +functions.append(f) + +f = Function(void, 'SetFScaleDisable', + (Boolean, 'fscaleDisable', InMode), +) +functions.append(f) + +f = Function(void, 'FontMetrics', + (FMetricRecPtr, 'theMetrics', OutMode), +) +functions.append(f) + +f = Function(void, 'SetFractEnable', + (Boolean, 'fractEnable', InMode), +) +functions.append(f) + +f = Function(short, 'GetDefFontSize', +) +functions.append(f) + +f = Function(Boolean, 'IsOutline', + (Point, 'numer', InMode), + (Point, 'denom', InMode), +) +functions.append(f) + +f = Function(void, 'SetOutlinePreferred', + (Boolean, 'outlinePreferred', InMode), +) +functions.append(f) + +f = Function(Boolean, 'GetOutlinePreferred', +) +functions.append(f) + +f = Function(void, 'SetPreserveGlyph', + (Boolean, 'preserveGlyph', InMode), +) +functions.append(f) + +f = Function(Boolean, 'GetPreserveGlyph', +) +functions.append(f) + +f = Function(OSErr, 'FlushFonts', +) +functions.append(f) + +f = Function(short, 'GetSysFont', +) +functions.append(f) + +f = Function(short, 'GetAppFont', +) +functions.append(f) + diff --git a/Mac/Modules/fm/Fmmodule.c b/Mac/Modules/fm/Fmmodule.c new file mode 100644 index 0000000..ef264bc --- /dev/null +++ b/Mac/Modules/fm/Fmmodule.c @@ -0,0 +1,400 @@ + +/* =========================== Module Fm ============================ */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); +extern PyObject *OptResObj_New(Handle); +extern int OptResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); +extern PyTypeObject Window_Type; +#define WinObj_Check(x) ((x)->ob_type == &Window_Type) + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *GrafObj_New(GrafPtr); +extern int GrafObj_Convert(PyObject *, GrafPtr *); + +extern PyObject *BMObj_New(BitMapPtr); +extern int BMObj_Convert(PyObject *, BitMapPtr *); + +extern PyObject *PMObj_New(PixMapHandle); +extern int PMObj_Convert(PyObject *, PixMapHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include <Fonts.h> + +/* +** Parse/generate ComponentDescriptor records +*/ +PyObject *FMRec_New(itself) + 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... */ +FMRec_Convert(v, p_itself) + 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; + +static PyObject *Fm_InitFonts(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + InitFonts(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Fm_GetFontName(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short familyID; + Str255 name; + if (!PyArg_ParseTuple(_args, "h", + &familyID)) + return NULL; + GetFontName(familyID, + name); + _res = Py_BuildValue("O&", + PyMac_BuildStr255, name); + return _res; +} + +static PyObject *Fm_GetFNum(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 name; + short familyID; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, name)) + return NULL; + GetFNum(name, + &familyID); + _res = Py_BuildValue("h", + familyID); + return _res; +} + +static PyObject *Fm_RealFont(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + short fontNum; + short size; + if (!PyArg_ParseTuple(_args, "hh", + &fontNum, + &size)) + return NULL; + _rv = RealFont(fontNum, + size); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Fm_SetFontLock(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean lockFlag; + if (!PyArg_ParseTuple(_args, "b", + &lockFlag)) + return NULL; + SetFontLock(lockFlag); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Fm_SetFScaleDisable(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean fscaleDisable; + if (!PyArg_ParseTuple(_args, "b", + &fscaleDisable)) + return NULL; + SetFScaleDisable(fscaleDisable); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Fm_FontMetrics(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + FMetricRec theMetrics; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + FontMetrics(&theMetrics); + _res = Py_BuildValue("O&", + FMRec_New, &theMetrics); + return _res; +} + +static PyObject *Fm_SetFractEnable(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean fractEnable; + if (!PyArg_ParseTuple(_args, "b", + &fractEnable)) + return NULL; + SetFractEnable(fractEnable); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Fm_GetDefFontSize(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetDefFontSize(); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Fm_IsOutline(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + Point numer; + Point denom; + 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(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean outlinePreferred; + if (!PyArg_ParseTuple(_args, "b", + &outlinePreferred)) + return NULL; + SetOutlinePreferred(outlinePreferred); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Fm_GetOutlinePreferred(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetOutlinePreferred(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Fm_SetPreserveGlyph(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean preserveGlyph; + if (!PyArg_ParseTuple(_args, "b", + &preserveGlyph)) + return NULL; + SetPreserveGlyph(preserveGlyph); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Fm_GetPreserveGlyph(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetPreserveGlyph(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Fm_FlushFonts(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = FlushFonts(); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Fm_GetSysFont(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetSysFont(); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Fm_GetAppFont(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetAppFont(); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyMethodDef Fm_methods[] = { + {"InitFonts", (PyCFunction)Fm_InitFonts, 1, + "() -> None"}, + {"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)"}, + {"SetFontLock", (PyCFunction)Fm_SetFontLock, 1, + "(Boolean lockFlag) -> None"}, + {"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)"}, + {"FlushFonts", (PyCFunction)Fm_FlushFonts, 1, + "() -> None"}, + {"GetSysFont", (PyCFunction)Fm_GetSysFont, 1, + "() -> (short _rv)"}, + {"GetAppFont", (PyCFunction)Fm_GetAppFont, 1, + "() -> (short _rv)"}, + {NULL, NULL, 0} +}; + + + + +void initFm() +{ + 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) + Py_FatalError("can't initialize Fm.Error"); +} + +/* ========================= End module Fm ========================== */ + diff --git a/Mac/Modules/fm/fmscan.py b/Mac/Modules/fm/fmscan.py new file mode 100644 index 0000000..adbb3dc --- /dev/null +++ b/Mac/Modules/fm/fmscan.py @@ -0,0 +1,46 @@ +# Scan an Apple header file, generating a Python file of generator calls. + +import addpack +addpack.addpack(':tools:bgen:bgen') +from scantools import Scanner + +LONG = "Fonts" +SHORT = "Fm" + +def main(): + input = "Fonts.h" + output = SHORT + "gen.py" + defsoutput = LONG + ".py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now importing the generated code... ===" + exec "import " + SHORT + "support" + print "=== Done. It's up to you to compile it now! ===" + +class MyScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + return classname, listname + + def makeblacklistnames(self): + return [ + "OutlineMetrics", # Too complicated + ] + + def makeblacklisttypes(self): + return [ + "FMInput_ptr", # Not needed for now + "FMOutPtr", # Ditto + ] + + def makerepairinstructions(self): + return [ + ([('Str255', '*', 'InMode')], [('Str255', '*', 'OutMode')]), + ([('FMetricRecPtr', 'theMetrics', 'InMode')], [('FMetricRecPtr', 'theMetrics', 'OutMode')]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/fm/fmsupport.py b/Mac/Modules/fm/fmsupport.py new file mode 100644 index 0000000..f0b1e29 --- /dev/null +++ b/Mac/Modules/fm/fmsupport.py @@ -0,0 +1,75 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Fonts.h' # The Apple header file +MODNAME = 'Fm' # The name of the module + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner +OUTPUTFILE = MODNAME + "module.c" # The file generated by this program + +from macsupport import * + +# Create the type objects + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ + +/* +** Parse/generate ComponentDescriptor records +*/ +PyObject *FMRec_New(itself) + 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... */ +FMRec_Convert(v, p_itself) + 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 + +""" + +FMetricRecPtr = OpaqueType('FMetricRec', 'FMRec') + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator + +# Create and populate the lists +functions = [] +execfile(INPUTFILE) + +# add the populated lists to the generator groups +# (in a different wordl the scan program would generate this) +for f in functions: module.add(f) + +# generate output (open the output file as late as possible) +SetOutputFileName(OUTPUTFILE) +module.generate() + |