1991-04-03 15:02:31 -04:00
|
|
|
|
|
|
|
/* Font Manager module */
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
#include "Python.h"
|
1991-04-03 15:02:31 -04:00
|
|
|
|
|
|
|
#include <gl.h>
|
|
|
|
#include <device.h>
|
|
|
|
#include <fmclient.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* Font Handle object implementation */
|
|
|
|
|
|
|
|
typedef struct {
|
2010-05-09 11:46:46 -03:00
|
|
|
PyObject_HEAD
|
|
|
|
fmfonthandle fh_fh;
|
1991-04-03 15:02:31 -04:00
|
|
|
} fhobject;
|
|
|
|
|
2002-07-17 13:30:39 -03:00
|
|
|
static PyTypeObject Fhtype;
|
1991-04-03 15:02:31 -04:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
#define is_fhobject(v) ((v)->ob_type == &Fhtype)
|
1991-04-03 15:02:31 -04:00
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
newfhobject(fmfonthandle fh)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
fhobject *fhp;
|
|
|
|
if (fh == NULL) {
|
|
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
|
|
"error creating new font handle");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fhp = PyObject_New(fhobject, &Fhtype);
|
|
|
|
if (fhp == NULL)
|
|
|
|
return NULL;
|
|
|
|
fhp->fh_fh = fh;
|
|
|
|
return (PyObject *)fhp;
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Font Handle methods */
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
fh_scalefont(fhobject *self, PyObject *args)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
double size;
|
|
|
|
if (!PyArg_ParseTuple(args, "d", &size))
|
|
|
|
return NULL;
|
|
|
|
return newfhobject(fmscalefont(self->fh_fh, size));
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX fmmakefont */
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2002-03-31 10:57:24 -04:00
|
|
|
fh_setfont(fhobject *self)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
fmsetfont(self->fh_fh);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2002-03-31 10:57:24 -04:00
|
|
|
fh_getfontname(fhobject *self)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
char fontname[256];
|
|
|
|
int len;
|
|
|
|
len = fmgetfontname(self->fh_fh, sizeof fontname, fontname);
|
|
|
|
if (len < 0) {
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontname");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyString_FromStringAndSize(fontname, len);
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2002-03-31 10:57:24 -04:00
|
|
|
fh_getcomment(fhobject *self)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
char comment[256];
|
|
|
|
int len;
|
|
|
|
len = fmgetcomment(self->fh_fh, sizeof comment, comment);
|
|
|
|
if (len < 0) {
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "error in fmgetcomment");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyString_FromStringAndSize(comment, len);
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2002-03-31 10:57:24 -04:00
|
|
|
fh_getfontinfo(fhobject *self)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
fmfontinfo info;
|
|
|
|
if (fmgetfontinfo(self->fh_fh, &info) < 0) {
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontinfo");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return Py_BuildValue("(llllllll)",
|
|
|
|
info.printermatched,
|
|
|
|
info.fixed_width,
|
|
|
|
info.xorig,
|
|
|
|
info.yorig,
|
|
|
|
info.xsize,
|
|
|
|
info.ysize,
|
|
|
|
info.height,
|
|
|
|
info.nglyphs);
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
fh_getwholemetrics(fhobject *self, PyObject *args)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
fh_getstrwidth(fhobject *self, PyObject *args)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
char *str;
|
|
|
|
if (!PyArg_ParseTuple(args, "s", &str))
|
|
|
|
return NULL;
|
|
|
|
return PyInt_FromLong(fmgetstrwidth(self->fh_fh, str));
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyMethodDef fh_methods[] = {
|
2010-05-09 11:46:46 -03:00
|
|
|
{"scalefont", (PyCFunction)fh_scalefont, METH_VARARGS},
|
|
|
|
{"setfont", (PyCFunction)fh_setfont, METH_NOARGS},
|
|
|
|
{"getfontname", (PyCFunction)fh_getfontname, METH_NOARGS},
|
|
|
|
{"getcomment", (PyCFunction)fh_getcomment, METH_NOARGS},
|
|
|
|
{"getfontinfo", (PyCFunction)fh_getfontinfo, METH_NOARGS},
|
1991-04-03 15:02:31 -04:00
|
|
|
#if 0
|
2010-05-09 11:46:46 -03:00
|
|
|
{"getwholemetrics", (PyCFunction)fh_getwholemetrics, METH_VARARGS},
|
1991-04-03 15:02:31 -04:00
|
|
|
#endif
|
2010-05-09 11:46:46 -03:00
|
|
|
{"getstrwidth", (PyCFunction)fh_getstrwidth, METH_VARARGS},
|
|
|
|
{NULL, NULL} /* sentinel */
|
1991-04-03 15:02:31 -04:00
|
|
|
};
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
fh_getattr(fhobject *fhp, char *name)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
return Py_FindMethod(fh_methods, (PyObject *)fhp, name);
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-10 14:04:33 -03:00
|
|
|
fh_dealloc(fhobject *fhp)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
fmfreefont(fhp->fh_fh);
|
|
|
|
PyObject_Del(fhp);
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyTypeObject Fhtype = {
|
2010-05-09 11:46:46 -03:00
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
|
|
0, /*ob_size*/
|
|
|
|
"fm.font handle", /*tp_name*/
|
|
|
|
sizeof(fhobject), /*tp_size*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
|
|
|
(destructor)fh_dealloc, /*tp_dealloc*/
|
|
|
|
0, /*tp_print*/
|
|
|
|
(getattrfunc)fh_getattr, /*tp_getattr*/
|
|
|
|
0, /*tp_setattr*/
|
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
1991-04-03 15:02:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Font Manager functions */
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2002-03-31 10:57:24 -04:00
|
|
|
fm_init(PyObject *self)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
fminit();
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2000-07-12 07:43:11 -03:00
|
|
|
fm_findfont(PyObject *self, PyObject *args)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
char *str;
|
|
|
|
if (!PyArg_ParseTuple(args, "s", &str))
|
|
|
|
return NULL;
|
|
|
|
return newfhobject(fmfindfont(str));
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2000-07-12 07:43:11 -03:00
|
|
|
fm_prstr(PyObject *self, PyObject *args)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
char *str;
|
|
|
|
if (!PyArg_ParseTuple(args, "s", &str))
|
|
|
|
return NULL;
|
|
|
|
fmprstr(str);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX This uses a global variable as temporary! Not re-entrant! */
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *fontlist;
|
1991-04-03 15:02:31 -04:00
|
|
|
|
|
|
|
static void
|
2000-07-10 14:04:33 -03:00
|
|
|
clientproc(char *fontname)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
int err;
|
|
|
|
PyObject *v;
|
|
|
|
if (fontlist == NULL)
|
|
|
|
return;
|
|
|
|
v = PyString_FromString(fontname);
|
|
|
|
if (v == NULL)
|
|
|
|
err = -1;
|
|
|
|
else {
|
|
|
|
err = PyList_Append(fontlist, v);
|
|
|
|
Py_DECREF(v);
|
|
|
|
}
|
|
|
|
if (err != 0) {
|
|
|
|
Py_DECREF(fontlist);
|
|
|
|
fontlist = NULL;
|
|
|
|
}
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2002-03-31 10:57:24 -04:00
|
|
|
fm_enumerate(PyObject *self)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
PyObject *res;
|
|
|
|
fontlist = PyList_New(0);
|
|
|
|
if (fontlist == NULL)
|
|
|
|
return NULL;
|
|
|
|
fmenumerate(clientproc);
|
|
|
|
res = fontlist;
|
|
|
|
fontlist = NULL;
|
|
|
|
return res;
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2000-07-10 14:04:33 -03:00
|
|
|
fm_setpath(PyObject *self, PyObject *args)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
char *str;
|
|
|
|
if (!PyArg_ParseTuple(args, "s", &str))
|
|
|
|
return NULL;
|
|
|
|
fmsetpath(str);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyObject *
|
2002-03-31 10:57:24 -04:00
|
|
|
fm_fontpath(PyObject *self)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
return PyString_FromString(fmfontpath());
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|
|
|
|
|
1997-01-17 12:08:55 -04:00
|
|
|
static PyMethodDef fm_methods[] = {
|
2010-05-09 11:46:46 -03:00
|
|
|
{"init", fm_init, METH_NOARGS},
|
|
|
|
{"findfont", fm_findfont, METH_VARARGS},
|
|
|
|
{"enumerate", fm_enumerate, METH_NOARGS},
|
|
|
|
{"prstr", fm_prstr, METH_VARARGS},
|
|
|
|
{"setpath", fm_setpath, METH_VARARGS},
|
|
|
|
{"fontpath", fm_fontpath, METH_NOARGS},
|
|
|
|
{NULL, NULL} /* sentinel */
|
1991-04-03 15:02:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-07-21 03:00:07 -03:00
|
|
|
initfm(void)
|
1991-04-03 15:02:31 -04:00
|
|
|
{
|
2008-05-15 00:23:17 -03:00
|
|
|
if (PyErr_WarnPy3k("the fm module has been removed in "
|
|
|
|
"Python 3.0", 2) < 0)
|
2016-09-17 04:54:55 -03:00
|
|
|
return;
|
2010-05-09 11:46:46 -03:00
|
|
|
|
|
|
|
Py_InitModule("fm", fm_methods);
|
|
|
|
if (m == NULL)
|
2008-05-15 00:23:17 -03:00
|
|
|
return;
|
2010-05-09 11:46:46 -03:00
|
|
|
fminit();
|
1991-04-03 15:02:31 -04:00
|
|
|
}
|