Kaydet (Commit) ed648a25 authored tarafından Roger E. Masse's avatar Roger E. Masse

Renamed, but not tested. Guido will you try your test script on this?

üst e474fb36
...@@ -31,9 +31,7 @@ PERFORMANCE OF THIS SOFTWARE. ...@@ -31,9 +31,7 @@ PERFORMANCE OF THIS SOFTWARE.
/* Font Manager module */ /* Font Manager module */
#include "allobjects.h" #include "Python.h"
#include "modsupport.h"
#include <gl.h> #include <gl.h>
#include <device.h> #include <device.h>
...@@ -43,153 +41,154 @@ PERFORMANCE OF THIS SOFTWARE. ...@@ -43,153 +41,154 @@ PERFORMANCE OF THIS SOFTWARE.
/* Font Handle object implementation */ /* Font Handle object implementation */
typedef struct { typedef struct {
OB_HEAD PyObject_HEAD
fmfonthandle fh_fh; fmfonthandle fh_fh;
} fhobject; } fhobject;
staticforward typeobject Fhtype; staticforward PyTypeObject Fhtype;
#define is_fhobject(v) ((v)->ob_type == &Fhtype) #define is_fhobject(v) ((v)->ob_type == &Fhtype)
static object * static PyObject *
newfhobject(fh) newfhobject(fh)
fmfonthandle fh; fmfonthandle fh;
{ {
fhobject *fhp; fhobject *fhp;
if (fh == NULL) { if (fh == NULL) {
err_setstr(RuntimeError, "error creating new font handle"); PyErr_SetString(PyExc_RuntimeError,
"error creating new font handle");
return NULL; return NULL;
} }
fhp = NEWOBJ(fhobject, &Fhtype); fhp = PyObject_NEW(fhobject, &Fhtype);
if (fhp == NULL) if (fhp == NULL)
return NULL; return NULL;
fhp->fh_fh = fh; fhp->fh_fh = fh;
return (object *)fhp; return (PyObject *)fhp;
} }
/* Font Handle methods */ /* Font Handle methods */
static object * static PyObject *
fh_scalefont(self, args) fh_scalefont(self, args)
fhobject *self; fhobject *self;
object *args; PyObject *args;
{ {
double size; double size;
if (!getargs(args, "d", &size)) if (!PyArg_Parse(args, "d", &size))
return NULL; return NULL;
return newfhobject(fmscalefont(self->fh_fh, size)); return newfhobject(fmscalefont(self->fh_fh, size));
} }
/* XXX fmmakefont */ /* XXX fmmakefont */
static object * static PyObject *
fh_setfont(self, args) fh_setfont(self, args)
fhobject *self; fhobject *self;
object *args; PyObject *args;
{ {
if (!getnoarg(args)) if (!PyArg_NoArgs(args))
return NULL; return NULL;
fmsetfont(self->fh_fh); fmsetfont(self->fh_fh);
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
static object * static PyObject *
fh_getfontname(self, args) fh_getfontname(self, args)
fhobject *self; fhobject *self;
object *args; PyObject *args;
{ {
char fontname[256]; char fontname[256];
int len; int len;
if (!getnoarg(args)) if (!PyArg_NoArgs(args))
return NULL; return NULL;
len = fmgetfontname(self->fh_fh, sizeof fontname, fontname); len = fmgetfontname(self->fh_fh, sizeof fontname, fontname);
if (len < 0) { if (len < 0) {
err_setstr(RuntimeError, "error in fmgetfontname"); PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontname");
return NULL; return NULL;
} }
return newsizedstringobject(fontname, len); return PyString_FromStringAndSize(fontname, len);
} }
static object * static PyObject *
fh_getcomment(self, args) fh_getcomment(self, args)
fhobject *self; fhobject *self;
object *args; PyObject *args;
{ {
char comment[256]; char comment[256];
int len; int len;
if (!getnoarg(args)) if (!PyArg_NoArgs(args))
return NULL; return NULL;
len = fmgetcomment(self->fh_fh, sizeof comment, comment); len = fmgetcomment(self->fh_fh, sizeof comment, comment);
if (len < 0) { if (len < 0) {
err_setstr(RuntimeError, "error in fmgetcomment"); PyErr_SetString(PyExc_RuntimeError, "error in fmgetcomment");
return NULL; return NULL;
} }
return newsizedstringobject(comment, len); return PyString_FromStringAndSize(comment, len);
} }
static object * static PyObject *
fh_getfontinfo(self, args) fh_getfontinfo(self, args)
fhobject *self; fhobject *self;
object *args; PyObject *args;
{ {
fmfontinfo info; fmfontinfo info;
if (!getnoarg(args)) if (!PyArg_NoArgs(args))
return NULL; return NULL;
if (fmgetfontinfo(self->fh_fh, &info) < 0) { if (fmgetfontinfo(self->fh_fh, &info) < 0) {
err_setstr(RuntimeError, "error in fmgetfontinfo"); PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontinfo");
return NULL; return NULL;
} }
return mkvalue("(llllllll)", return Py_BuildValue("(llllllll)",
info.printermatched, info.printermatched,
info.fixed_width, info.fixed_width,
info.xorig, info.xorig,
info.yorig, info.yorig,
info.xsize, info.xsize,
info.ysize, info.ysize,
info.height, info.height,
info.nglyphs); info.nglyphs);
} }
#if 0 #if 0
static object * static PyObject *
fh_getwholemetrics(self, args) fh_getwholemetrics(self, args)
fhobject *self; fhobject *self;
object *args; PyObject *args;
{ {
} }
#endif #endif
static object * static PyObject *
fh_getstrwidth(self, args) fh_getstrwidth(self, args)
fhobject *self; fhobject *self;
object *args; PyObject *args;
{ {
char *str; char *str;
if (!getstrarg(args, &str)) if (!PyArg_Parse(args, "s", &str))
return NULL; return NULL;
return newintobject(fmgetstrwidth(self->fh_fh, str)); return PyInt_FromLong(fmgetstrwidth(self->fh_fh, str));
} }
static struct methodlist fh_methods[] = { static PyMethodDef fh_methods[] = {
{"scalefont", (method)fh_scalefont}, {"scalefont", (PyCFunction)fh_scalefont},
{"setfont", (method)fh_setfont}, {"setfont", (PyCFunction)fh_setfont},
{"getfontname", (method)fh_getfontname}, {"getfontname", (PyCFunction)fh_getfontname},
{"getcomment", (method)fh_getcomment}, {"getcomment", (PyCFunction)fh_getcomment},
{"getfontinfo", (method)fh_getfontinfo}, {"getfontinfo", (PyCFunction)fh_getfontinfo},
#if 0 #if 0
{"getwholemetrics", (method)fh_getwholemetrics}, {"getwholemetrics", (PyCFunction)fh_getwholemetrics},
#endif #endif
{"getstrwidth", (method)fh_getstrwidth}, {"getstrwidth", (PyCFunction)fh_getstrwidth},
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
static object * static PyObject *
fh_getattr(fhp, name) fh_getattr(fhp, name)
fhobject *fhp; fhobject *fhp;
char *name; char *name;
{ {
return findmethod(fh_methods, (object *)fhp, name); return Py_FindMethod(fh_methods, (PyObject *)fhp, name);
} }
static void static void
...@@ -197,11 +196,11 @@ fh_dealloc(fhp) ...@@ -197,11 +196,11 @@ fh_dealloc(fhp)
fhobject *fhp; fhobject *fhp;
{ {
fmfreefont(fhp->fh_fh); fmfreefont(fhp->fh_fh);
DEL(fhp); PyMem_DEL(fhp);
} }
static typeobject Fhtype = { static PyTypeObject Fhtype = {
OB_HEAD_INIT(&Typetype) PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/ 0, /*ob_size*/
"font handle", /*tp_name*/ "font handle", /*tp_name*/
sizeof(fhobject), /*tp_size*/ sizeof(fhobject), /*tp_size*/
...@@ -218,72 +217,72 @@ static typeobject Fhtype = { ...@@ -218,72 +217,72 @@ static typeobject Fhtype = {
/* Font Manager functions */ /* Font Manager functions */
static object * static PyObject *
fm_init(self, args) fm_init(self, args)
object *self, *args; PyObject *self, *args;
{ {
if (!getnoarg(args)) if (!PyArg_NoArgs(args))
return NULL; return NULL;
fminit(); fminit();
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
static object * static PyObject *
fm_findfont(self, args) fm_findfont(self, args)
object *self, *args; PyObject *self, *args;
{ {
char *str; char *str;
if (!getstrarg(args, &str)) if (!PyArg_Parse(args, "s", &str))
return NULL; return NULL;
return newfhobject(fmfindfont(str)); return newfhobject(fmfindfont(str));
} }
static object * static PyObject *
fm_prstr(self, args) fm_prstr(self, args)
object *self, *args; PyObject *self, *args;
{ {
char *str; char *str;
if (!getstrarg(args, &str)) if (!PyArg_Parse(args, "s", &str))
return NULL; return NULL;
fmprstr(str); fmprstr(str);
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
/* XXX This uses a global variable as temporary! Not re-entrant! */ /* XXX This uses a global variable as temporary! Not re-entrant! */
static object *fontlist; static PyObject *fontlist;
static void static void
clientproc(fontname) clientproc(fontname)
char *fontname; char *fontname;
{ {
int err; int err;
object *v; PyObject *v;
if (fontlist == NULL) if (fontlist == NULL)
return; return;
v = newstringobject(fontname); v = PyString_FromString(fontname);
if (v == NULL) if (v == NULL)
err = -1; err = -1;
else { else {
err = addlistitem(fontlist, v); err = PyList_Append(fontlist, v);
DECREF(v); Py_DECREF(v);
} }
if (err != 0) { if (err != 0) {
DECREF(fontlist); Py_DECREF(fontlist);
fontlist = NULL; fontlist = NULL;
} }
} }
static object * static PyObject *
fm_enumerate(self, args) fm_enumerate(self, args)
object *self, *args; PyObject *self, *args;
{ {
object *res; PyObject *res;
if (!getnoarg(args)) if (!PyArg_NoArgs(args))
return NULL; return NULL;
fontlist = newlistobject(0); fontlist = PyList_New(0);
if (fontlist == NULL) if (fontlist == NULL)
return NULL; return NULL;
fmenumerate(clientproc); fmenumerate(clientproc);
...@@ -292,28 +291,28 @@ fm_enumerate(self, args) ...@@ -292,28 +291,28 @@ fm_enumerate(self, args)
return res; return res;
} }
static object * static PyObject *
fm_setpath(self, args) fm_setpath(self, args)
object *self, *args; PyObject *self, *args;
{ {
char *str; char *str;
if (!getstrarg(args, &str)) if (!PyArg_Parse(args, "s", &str))
return NULL; return NULL;
fmsetpath(str); fmsetpath(str);
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
static object * static PyObject *
fm_fontpath(self, args) fm_fontpath(self, args)
object *self, *args; PyObject *self, *args;
{ {
if (!getnoarg(args)) if (!PyArg_NoArgs(args))
return NULL; return NULL;
return newstringobject(fmfontpath()); return PyString_FromString(fmfontpath());
} }
static struct methodlist fm_methods[] = { static PyMethodDef fm_methods[] = {
{"init", fm_init}, {"init", fm_init},
{"findfont", fm_findfont}, {"findfont", fm_findfont},
{"enumerate", fm_enumerate}, {"enumerate", fm_enumerate},
...@@ -327,6 +326,6 @@ static struct methodlist fm_methods[] = { ...@@ -327,6 +326,6 @@ static struct methodlist fm_methods[] = {
void void
initfm() initfm()
{ {
initmodule("fm", fm_methods); Py_InitModule("fm", fm_methods);
fminit(); fminit();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment