]>
Dogcows Code - chaz/openbox/blob - otk/font.cc
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 std::string
Font::_fallback_font
= "fixed";
24 bool Font::_xft_init
= false;
26 Font::Font(int screen_num
, const std::string
&fontstring
,
27 bool shadow
, unsigned char offset
, unsigned char tint
)
28 : _screen_num(screen_num
),
29 _fontstring(fontstring
),
35 assert(screen_num
>= 0);
36 assert(tint
<= CHAR_MAX
);
40 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
);
50 if ((_xftfont
= XftFontOpenName(**display
, _screen_num
,
51 _fontstring
.c_str())))
54 printf(_("Unable to load font: %s\n"), _fontstring
.c_str());
55 printf(_("Trying fallback font: %s\n"), _fallback_font
.c_str());
57 if ((_xftfont
= XftFontOpenName(**display
, _screen_num
,
58 _fallback_font
.c_str())))
61 printf(_("Unable to load font: %s\n"), _fallback_font
.c_str());
62 printf(_("Aborting!.\n"));
64 ::exit(3); // can't continue without a font
71 XftFontClose(**display
, _xftfont
);
75 int Font::measureString(const ustring
&string
) const
80 XftTextExtentsUtf8(**display
, _xftfont
,
81 (FcChar8
*)string
.c_str(), string
.bytes(), &info
);
83 XftTextExtents8(**display
, _xftfont
,
84 (FcChar8
*)string
.c_str(), string
.bytes(), &info
);
86 return (signed) info
.xOff
+ (_shadow
? _offset
: 0);
90 int Font::height(void) const
92 return (signed) _xftfont
->height
+ (_shadow
? _offset
: 0);
96 int Font::maxCharWidth(void) const
98 return (signed) _xftfont
->max_advance_width
;
This page took 0.043849 seconds and 5 git commands to generate.