]>
Dogcows Code - chaz/openbox/blob - otk/font.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
13 #include "screeninfo.hh"
18 #endif // HAVE_STDIO_H
20 #include "../src/gettext.h"
21 #define _(str) gettext(str)
26 std::string
Font::_fallback_font
= "fixed";
27 bool Font::_xft_init
= false;
29 Font::Font(int screen_num
, const std::string
&fontstring
,
30 bool shadow
, unsigned char offset
, unsigned char tint
)
31 : _screen_num(screen_num
),
32 _fontstring(fontstring
),
38 assert(screen_num
>= 0);
39 assert(tint
<= CHAR_MAX
);
43 printf(_("Couldn't initialize Xft.\n\n"));
46 int version
= XftGetVersion();
47 printf(_("Using Xft %d.%d.%d (Built against %d.%d.%d).\n"),
48 version
/ 10000 % 100, version
/ 100 % 100, version
% 100,
49 XFT_MAJOR
, XFT_MINOR
, XFT_REVISION
);
53 if ((_xftfont
= XftFontOpenName(**display
, _screen_num
,
54 _fontstring
.c_str())))
57 printf(_("Unable to load font: %s\n"), _fontstring
.c_str());
58 printf(_("Trying fallback font: %s\n"), _fallback_font
.c_str());
60 if ((_xftfont
= XftFontOpenName(**display
, _screen_num
,
61 _fallback_font
.c_str())))
64 printf(_("Unable to load font: %s\n"), _fallback_font
.c_str());
65 printf(_("Aborting!.\n"));
67 ::exit(3); // can't continue without a font
74 XftFontClose(**display
, _xftfont
);
78 int Font::measureString(const ustring
&string
) const
83 XftTextExtentsUtf8(**display
, _xftfont
,
84 (FcChar8
*)string
.c_str(), string
.bytes(), &info
);
86 XftTextExtents8(**display
, _xftfont
,
87 (FcChar8
*)string
.c_str(), string
.bytes(), &info
);
89 return (signed) info
.xOff
+ (_shadow
? _offset
: 0);
93 int Font::height(void) const
95 return (signed) _xftfont
->height
+ (_shadow
? _offset
: 0);
99 int Font::maxCharWidth(void) const
101 return (signed) _xftfont
->max_advance_width
;
This page took 0.037831 seconds and 4 git commands to generate.