]>
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
20 #include "screeninfo.hh"
25 #endif // HAVE_STDIO_H
28 #define _(str) gettext(str)
33 std::string
Font::_fallback_font
= "fixed";
34 bool Font::_xft_init
= false;
36 Font::Font(int screen_num
, const std::string
&fontstring
,
37 bool shadow
, unsigned char offset
, unsigned char tint
)
38 : _screen_num(screen_num
),
39 _fontstring(fontstring
),
45 assert(screen_num
>= 0);
46 assert(tint
<= CHAR_MAX
);
50 printf(_("Couldn't initialize Xft.\n\n"));
53 int version
= XftGetVersion();
54 printf(_("Using Xft %d.%d.%d.\n"),
55 version
/ 10000 % 100, version
/ 100 % 100, version
% 100);
59 if ((_xftfont
= XftFontOpenName(**display
, _screen_num
,
60 _fontstring
.c_str())))
63 printf(_("Unable to load font: %s\n"), _fontstring
.c_str());
64 printf(_("Trying fallback font: %s\n"), _fallback_font
.c_str());
66 if ((_xftfont
= XftFontOpenName(**display
, _screen_num
,
67 _fallback_font
.c_str())))
70 printf(_("Unable to load font: %s\n"), _fallback_font
.c_str());
71 printf(_("Aborting!.\n"));
73 ::exit(3); // can't continue without a font
80 XftFontClose(**display
, _xftfont
);
84 void Font::drawString(XftDraw
*d
, int x
, int y
, const Color
&color
,
85 const ustring
&string
) const
94 c
.color
.alpha
= _tint
| _tint
<< 8; // transparent shadow
95 c
.pixel
= BlackPixel(**display
, _screen_num
);
98 XftDrawStringUtf8(d
, &c
, _xftfont
, x
+ _offset
,
99 _xftfont
->ascent
+ y
+ _offset
,
100 (FcChar8
*)string
.c_str(), string
.bytes());
102 XftDrawString8(d
, &c
, _xftfont
, x
+ _offset
,
103 _xftfont
->ascent
+ y
+ _offset
,
104 (FcChar8
*)string
.c_str(), string
.bytes());
108 c
.color
.red
= color
.red() | color
.red() << 8;
109 c
.color
.green
= color
.green() | color
.green() << 8;
110 c
.color
.blue
= color
.blue() | color
.blue() << 8;
111 c
.pixel
= color
.pixel();
112 c
.color
.alpha
= 0xff | 0xff << 8; // no transparency in Color yet
115 XftDrawStringUtf8(d
, &c
, _xftfont
, x
, _xftfont
->ascent
+ y
,
116 (FcChar8
*)string
.c_str(), string
.bytes());
118 XftDrawString8(d
, &c
, _xftfont
, x
, _xftfont
->ascent
+ y
,
119 (FcChar8
*)string
.c_str(), string
.bytes());
125 unsigned int Font::measureString(const ustring
&string
) const
130 XftTextExtentsUtf8(**display
, _xftfont
,
131 (FcChar8
*)string
.c_str(), string
.bytes(), &info
);
133 XftTextExtents8(**display
, _xftfont
,
134 (FcChar8
*)string
.c_str(), string
.bytes(), &info
);
136 return info
.xOff
+ (_shadow
? _offset
: 0);
140 unsigned int Font::height(void) const
142 return _xftfont
->height
+ (_shadow
? _offset
: 0);
146 unsigned int Font::maxCharWidth(void) const
148 return _xftfont
->max_advance_width
;
This page took 0.072766 seconds and 5 git commands to generate.