]> Dogcows Code - chaz/openbox/blob - render/font.c
merge the C branch into HEAD
[chaz/openbox] / render / font.c
1 #include "font.h"
2
3 #include "../src/gettext.h"
4 #define _(str) gettext(str)
5
6 font_open(const std::string &fontstring,
7 bool shadow, unsigned char offset, unsigned char tint)
8 {
9 assert(screen_num >= 0);
10 assert(tint <= CHAR_MAX);
11
12 if (!_xft_init) {
13 if (!XftInit(0)) {
14 printf(_("Couldn't initialize Xft.\n\n"));
15 ::exit(3);
16 }
17 #ifdef DEBUG
18 int version = XftGetVersion();
19 printf("Using Xft %d.%d.%d (Built against %d.%d.%d).\n",
20 version / 10000 % 100, version / 100 % 100, version % 100,
21 XFT_MAJOR, XFT_MINOR, XFT_REVISION);
22 #endif
23 _xft_init = true;
24 }
25
26 if ((_xftfont = XftFontOpenName(ob_display, _screen_num,
27 fontstring)))
28 return;
29
30 printf(_("Unable to load font: %s\n"), _fontstring.c_str());
31 printf(_("Trying fallback font: %s\n"), "fixed");
32
33 if ((_xftfont = XftFontOpenName(ob_display, _screen_num,
34 "fixed")))
35 return;
36
37 printf(_("Unable to load font: %s\n"), "fixed");
38 printf(_("Aborting!.\n"));
39
40 exit(3); // can't continue without a font
41 }
42
43
44 destroy_fonts(void)
45 {
46 if (_xftfont)
47 XftFontClose(ob_display, _xftfont);
48 }
49
50
51 int font_measure_string(const char *)
52 {
53 XGlyphInfo info;
54
55 if (string.utf8())
56 XftTextExtentsUtf8(**display, _xftfont,
57 (FcChar8*)string.c_str(), string.bytes(), &info);
58 else
59 XftTextExtents8(ob_display, _xftfont,
60 (FcChar8*)string.c_str(), string.bytes(), &info);
61
62 return (signed) info.xOff + (_shadow ? _offset : 0);
63 }
64
65
66 int font_height(void)
67 {
68 return (signed) _xftfont->height + (_shadow ? _offset : 0);
69 }
70
71
72 int font_max_char_width(void)
73 {
74 return (signed) _xftfont->max_advance_width;
75 }
This page took 0.036045 seconds and 4 git commands to generate.