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"));
42 int version = XftGetVersion();
43 printf(_("Using Xft %d.%d.%d (Built against %d.%d.%d).\n"),
44 version / 10000 % 100, version / 100 % 100, version % 100,
45 XFT_MAJOR, XFT_MINOR, XFT_REVISION);
49 if ((_xftfont = XftFontOpenName(**display, _screen_num,
50 _fontstring.c_str())))
53 printf(_("Unable to load font: %s\n"), _fontstring.c_str());
54 printf(_("Trying fallback font: %s\n"), "fixed");
56 if ((_xftfont = XftFontOpenName(**display, _screen_num,
60 printf(_("Unable to load font: %s\n"), "fixed");
61 printf(_("Aborting!.\n"));
63 ::exit(3); // can't continue without a font
70 XftFontClose(**display, _xftfont);
74 int Font::measureString(const ustring &string) const
79 XftTextExtentsUtf8(**display, _xftfont,
80 (FcChar8*)string.c_str(), string.bytes(), &info);
82 XftTextExtents8(**display, _xftfont,
83 (FcChar8*)string.c_str(), string.bytes(), &info);
85 return (signed) info.xOff + (_shadow ? _offset : 0);
89 int Font::height(void) const
91 return (signed) _xftfont->height + (_shadow ? _offset : 0);
95 int Font::maxCharWidth(void) const
97 return (signed) _xftfont->max_advance_width;