1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
9 #include "screeninfo.hh"
12 #include "../src/gettext.h"
13 #define _(str) gettext(str)
23 bool Font::_xft_init = false;
25 Font::Font(int screen_num, const std::string &fontstring,
26 bool shadow, unsigned char offset, unsigned char tint)
27 : _screen_num(screen_num),
28 _fontstring(fontstring),
34 assert(screen_num >= 0);
35 assert(tint <= CHAR_MAX);
39 printf(_("Couldn't initialize Xft.\n\n"));
43 int version = XftGetVersion();
44 printf("Using Xft %d.%d.%d (Built against %d.%d.%d).\n",
45 version / 10000 % 100, version / 100 % 100, version % 100,
46 XFT_MAJOR, XFT_MINOR, XFT_REVISION);
51 if ((_xftfont = XftFontOpenName(**display, _screen_num,
52 _fontstring.c_str())))
55 printf(_("Unable to load font: %s\n"), _fontstring.c_str());
56 printf(_("Trying fallback font: %s\n"), "fixed");
58 if ((_xftfont = XftFontOpenName(**display, _screen_num,
62 printf(_("Unable to load font: %s\n"), "fixed");
63 printf(_("Aborting!.\n"));
65 ::exit(3); // can't continue without a font
72 XftFontClose(**display, _xftfont);
76 int Font::measureString(const ustring &string) const
81 XftTextExtentsUtf8(**display, _xftfont,
82 (FcChar8*)string.c_str(), string.bytes(), &info);
84 XftTextExtents8(**display, _xftfont,
85 (FcChar8*)string.c_str(), string.bytes(), &info);
87 return (signed) info.xOff + (_shadow ? _offset : 0);
91 int Font::height(void) const
93 return (signed) _xftfont->height + (_shadow ? _offset : 0);
97 int Font::maxCharWidth(void) const
99 return (signed) _xftfont->max_advance_width;