1 // -*- mode: C; indent-tabs-mode: nil; -*-
8 #include "../src/gettext.h"
10 static Bool xft_init = False;
11 static const char *fallback = "fixed";
13 void OtkFont_Initialize()
16 printf(_("Couldn't initialize Xft version %d.%d.%d.\n\n"),
17 XFT_MAJOR, XFT_MINOR, XFT_REVISION);
20 printf(_("Using Xft %d.%d.%d.\n"), XFT_MAJOR, XFT_MINOR, XFT_REVISION);
24 PyObject *OtkFont_New(int screen, const char *fontstring, Bool shadow,
25 unsigned char offset, unsigned char tint)
27 OtkFont *self = PyObject_New(OtkFont, &OtkFont_Type);
33 self->screen = screen;
34 self->shadow = shadow;
35 self->offset = offset;
38 if (!(self->xftfont = XftFontOpenName(OBDisplay->display, screen,
40 printf(_("Unable to load font: %s"), fontstring);
41 printf(_("Trying fallback font: %s\n"), fallback);
43 XftFontOpenName(OBDisplay->display, screen, fallback))) {
44 printf(_("Unable to load font: %s"), fallback);
45 printf(_("Aborting!.\n"));
47 exit(3); // can't continue without a font
51 return (PyObject*)self;
54 int OtkFont_MeasureString(OtkFont *self, const char *string)//, Bool utf8)
59 XftTextExtentsUtf8(OBDisplay->display, self->xftfont,
60 (const FcChar8*)string, strlen(string), &info);
62 XftTextExtents8(OBDisplay->display, self->xftfont,
63 (const FcChar8*)string, strlen(string), &info);*/
65 return info.xOff + (self->shadow ? self->offset : 0);
68 void OtkFont_DrawString(OtkFont *self, XftDraw *d, int x, int y,
69 OtkColor *color, const char *string)//, Bool utf8)
79 c.color.alpha = self->tint | self->tint << 8; // transparent shadow
80 c.pixel = BlackPixel(OBDisplay->display, self->screen);
83 XftDrawStringUtf8(d, &c, self->xftfont, x + self->offset,
84 self->xftfont->ascent + y + self->offset,
85 (const FcChar8*)string, strlen(string));
87 XftDrawString8(d, &c, self->xftfont, x + self->offset,
88 self->xftfont->ascent + y + self->offset,
89 (const FcChar8*)string, strlen(string));*/
93 c.color.red = color->red | color->red << 8;
94 c.color.green = color->green | color->green << 8;
95 c.color.blue = color->blue | color->blue << 8;
96 c.pixel = color->pixel;
97 c.color.alpha = 0xff | 0xff << 8; // no transparency in BColor yet
100 XftDrawStringUtf8(d, &c, self->xftfont, x, self->xftfont->ascent + y,
101 (const FcChar8*)string, strlen(string));
103 XftDrawString8(d, &c, self->xftfont, x, self->xftfont->ascent + y,
104 (const FcChar8*)string, strlen(string));*/
110 static PyObject *otkfont_measurestring(OtkFont* self, PyObject* args)
114 if (!PyArg_ParseTuple(args, "s", &s))
116 return PyInt_FromLong(OtkFont_MeasureString(self, s));
119 static PyMethodDef get_methods[] = {
120 {"measureString", (PyCFunction)otkfont_measurestring, METH_VARARGS,
121 "Measure the length of a string with a font."},
122 {NULL, NULL, 0, NULL}
126 static void otkfont_dealloc(OtkFont* self)
128 // this is always set. cuz if it failed.. the app would exit!
129 XftFontClose(OBDisplay->display, self->xftfont);
130 PyObject_Del((PyObject*)self);
133 static PyObject *otkfont_getattr(PyObject *obj, char *name)
135 return Py_FindMethod(get_methods, obj, name);
138 PyTypeObject Otkfont_Type = {
139 PyObject_HEAD_INIT(NULL)
144 (destructor)otkfont_dealloc, /*tp_dealloc*/
146 otkfont_getattr, /*tp_getattr*/
151 0, /*tp_as_sequence*/