2 #include <X11/Xft/Xft.h>
3 #include "../kernel/openbox.h"
6 #include "../src/gettext.h"
7 #define _(str) gettext(str)
9 void font_startup(void)
15 g_warning(_("Couldn't initialize Xft.\n\n"));
19 version = XftGetVersion();
20 g_message("Using Xft %d.%d.%d (Built against %d.%d.%d).\n",
21 version / 10000 % 100, version / 100 % 100, version % 100,
22 XFT_MAJOR, XFT_MINOR, XFT_REVISION);
26 static void measure_height(ObFont *f)
31 /* XXX add some extended UTF8 characters in here? */
32 str = "12345678900-qwertyuiopasdfghjklzxcvbnm"
33 "!@#$%^&*()_+QWERTYUIOPASDFGHJKLZXCVBNM"
34 "`~[]\\;',./{}|:\"<>?";
36 XftTextExtentsUtf8(ob_display, f->xftfont,
37 (FcChar8*)str, strlen(str), &info);
38 g_message("measured: %d", info.height);
39 f->height = (signed) info.height;
42 ObFont *font_open(char *fontstring)
47 if ((xf = XftFontOpenName(ob_display, ob_screen, fontstring))) {
48 out = malloc(sizeof(ObFont));
53 g_warning(_("Unable to load font: %s\n"), fontstring);
54 g_warning(_("Trying fallback font: %s\n"), "fixed");
56 if ((xf = XftFontOpenName(ob_display, ob_screen, "fixed"))) {
57 out = malloc(sizeof(ObFont));
62 g_warning(_("Unable to load font: %s\n"), "fixed");
63 g_warning(_("Aborting!.\n"));
65 exit(3); // can't continue without a font
68 void font_close(ObFont *f)
70 XftFontClose(ob_display, f->xftfont);
73 int font_measure_string(ObFont *f, const char *str, int shadow, int offset)
77 XftTextExtentsUtf8(ob_display, f->xftfont,
78 (FcChar8*)str, strlen(str), &info);
80 return (signed) info.xOff + (shadow ? offset : 0);
83 int font_height(ObFont *f, int shadow, int offset)
85 return f->height + (shadow ? offset : 0);
88 int font_max_char_width(ObFont *f)
90 return (signed) f->xftfont->max_advance_width;
93 void font_draw(XftDraw *d, TextureText *t, int x, int y, int w, int h)
97 /* accomidate for areas bigger/smaller than Xft thinks the font is tall */
98 y += (h - t->font->xftfont->height) / 2;
100 x += 3; /* XXX figure out X with justification */
106 c.color.alpha = t->tint | t->tint << 8; // transparent shadow
107 c.pixel = BlackPixel(ob_display, ob_screen);
109 XftDrawStringUtf8(d, &c, t->font->xftfont, x + t->offset,
110 t->font->xftfont->ascent + y + t->offset,
111 (FcChar8*)t->string, strlen(t->string));
113 c.color.red = t->color->r | t->color->r << 8;
114 c.color.green = t->color->g | t->color->g << 8;
115 c.color.blue = t->color->b | t->color->b << 8;
116 c.pixel = t->color->pixel;
117 c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
119 XftDrawStringUtf8(d, &c, t->font->xftfont, x,
120 t->font->xftfont->ascent + y -
121 (t->font->xftfont->height - t->font->height) / 2,
122 (FcChar8*)t->string, strlen(t->string));