]>
Dogcows Code - chaz/openbox/blob - otk/font.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
10 #endif // HAVE_STDLIB_H
16 #include "screeninfo.hh"
21 #endif // HAVE_STDIO_H
24 #define _(str) gettext(str)
29 std::string
Font::_fallback_font
= "fixed";
30 bool Font::_xft_init
= false;
32 Font::Font(int screen_num
, const std::string
&fontstring
,
33 bool shadow
, unsigned char offset
, unsigned char tint
)
34 : _screen_num(screen_num
),
35 _fontstring(fontstring
),
41 assert(screen_num
>= 0);
42 assert(tint
<= CHAR_MAX
);
46 printf(_("Couldn't initialize Xft.\n\n"));
49 int version
= XftGetVersion();
50 printf(_("Using Xft %d.%d.%d.\n"),
51 version
/ 10000 % 100, version
/ 100 % 100, version
% 100);
55 if ((_xftfont
= XftFontOpenName(Display::display
, _screen_num
,
56 _fontstring
.c_str())))
59 printf(_("Unable to load font: %s\n"), _fontstring
.c_str());
60 printf(_("Trying fallback font: %s\n"), _fallback_font
.c_str());
62 if ((_xftfont
= XftFontOpenName(Display::display
, _screen_num
,
63 _fallback_font
.c_str())))
66 printf(_("Unable to load font: %s\n"), _fallback_font
.c_str());
67 printf(_("Aborting!.\n"));
69 ::exit(3); // can't continue without a font
76 XftFontClose(Display::display
, _xftfont
);
80 void Font::drawString(XftDraw
*d
, int x
, int y
, const Color
&color
,
81 const userstring
&string
) const
90 c
.color
.alpha
= _tint
| _tint
<< 8; // transparent shadow
91 c
.pixel
= BlackPixel(Display::display
, _screen_num
);
94 XftDrawStringUtf8(d
, &c
, _xftfont
, x
+ _offset
,
95 _xftfont
->ascent
+ y
+ _offset
,
96 (FcChar8
*)string
.c_str(), string
.size());
98 XftDrawString8(d
, &c
, _xftfont
, x
+ _offset
,
99 _xftfont
->ascent
+ y
+ _offset
,
100 (FcChar8
*)string
.c_str(), string
.size());
104 c
.color
.red
= color
.red() | color
.red() << 8;
105 c
.color
.green
= color
.green() | color
.green() << 8;
106 c
.color
.blue
= color
.blue() | color
.blue() << 8;
107 c
.pixel
= color
.pixel();
108 c
.color
.alpha
= 0xff | 0xff << 8; // no transparency in Color yet
111 XftDrawStringUtf8(d
, &c
, _xftfont
, x
, _xftfont
->ascent
+ y
,
112 (FcChar8
*)string
.c_str(), string
.size());
114 XftDrawString8(d
, &c
, _xftfont
, x
, _xftfont
->ascent
+ y
,
115 (FcChar8
*)string
.c_str(), string
.size());
121 unsigned int Font::measureString(const userstring
&string
) const
126 XftTextExtentsUtf8(Display::display
, _xftfont
,
127 (FcChar8
*)string
.c_str(), string
.size(), &info
);
129 XftTextExtents8(Display::display
, _xftfont
,
130 (FcChar8
*)string
.c_str(), string
.size(), &info
);
132 return info
.xOff
+ (_shadow
? _offset
: 0);
136 unsigned int Font::height(void) const
138 return _xftfont
->height
+ (_shadow
? _offset
: 0);
142 unsigned int Font::maxCharWidth(void) const
144 return _xftfont
->max_advance_width
;
This page took 0.042159 seconds and 5 git commands to generate.