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 ObFont *font_open(char *fontstring)
31 if ((xf = XftFontOpenName(ob_display, ob_screen, fontstring))) {
32 out = malloc(sizeof(ObFont));
36 g_warning(_("Unable to load font: %s\n"), fontstring);
37 g_warning(_("Trying fallback font: %s\n"), "fixed");
39 if ((xf = XftFontOpenName(ob_display, ob_screen, "fixed"))) {
40 out = malloc(sizeof(ObFont));
44 g_warning(_("Unable to load font: %s\n"), "fixed");
45 g_warning(_("Aborting!.\n"));
47 exit(3); // can't continue without a font
51 void font_close(ObFont *f)
53 XftFontClose(ob_display, f->xftfont);
57 int font_measure_string(ObFont *f, const char *str, int shadow, int offset)
61 XftTextExtentsUtf8(ob_display, f->xftfont,
62 (FcChar8*)str, strlen(str), &info);
64 return (signed) info.xOff + (shadow ? offset : 0);
68 int font_height(ObFont *f, int shadow, int offset)
70 return (signed) f->xftfont->height + (shadow ? offset : 0);
74 int font_max_char_width(ObFont *f)
76 return (signed) f->xftfont->max_advance_width;