]>
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
24 #include "screeninfo.hh"
29 #endif // HAVE_STDIO_H
32 #define _(str) gettext(str)
37 string
BFont::_fallback_font
= "fixed";
38 bool BFont::_xft_init
= false;
40 BFont::BFont(int screen_num
, const string
&fontstring
,
41 bool shadow
, unsigned char offset
, unsigned char tint
)
42 : _screen_num(screen_num
),
43 _fontstring(fontstring
),
49 assert(screen_num
>= 0);
50 assert(tint
<= CHAR_MAX
);
54 printf(_("Couldn't initialize Xft version %d.\n\n"), XftVersion
);
57 printf(_("Using Xft %d.\n"), XftVersion
);
61 if ((_xftfont
= XftFontOpenName(OBDisplay::display
, _screen_num
,
62 _fontstring
.c_str())))
65 printf(_("Unable to load font: %s"), _fontstring
.c_str());
66 printf(_("Trying fallback font: %s\n"), _fallback_font
.c_str());
68 if ((_xftfont
= XftFontOpenName(OBDisplay::display
, _screen_num
,
69 _fallback_font
.c_str())))
72 printf(_("Unable to load font: %s"), _fallback_font
.c_str());
73 printf(_("Aborting!.\n"));
75 ::exit(3); // can't continue without a font
82 XftFontClose(OBDisplay::display
, _xftfont
);
86 void BFont::drawString(XftDraw
*d
, int x
, int y
, const BColor
&color
,
87 const string
&string
, bool utf8
) const
96 c
.color
.alpha
= _tint
| _tint
<< 8; // transparent shadow
97 c
.pixel
= BlackPixel(OBDisplay::display
, _screen_num
);
100 XftDrawStringUtf8(d
, &c
, _xftfont
, x
+ _offset
,
101 _xftfont
->ascent
+ y
+ _offset
,
102 (const FcChar8
*)string
.c_str(), string
.size());
104 XftDrawString8(d
, &c
, _xftfont
, x
+ _offset
,
105 _xftfont
->ascent
+ y
+ _offset
,
106 (const FcChar8
*)string
.c_str(), string
.size());
110 c
.color
.red
= color
.red() | color
.red() << 8;
111 c
.color
.green
= color
.green() | color
.green() << 8;
112 c
.color
.blue
= color
.blue() | color
.blue() << 8;
113 c
.pixel
= color
.pixel();
114 c
.color
.alpha
= 0xff | 0xff << 8; // no transparency in BColor yet
117 XftDrawStringUtf8(d
, &c
, _xftfont
, x
, _xftfont
->ascent
+ y
,
118 (const FcChar8
*)string
.c_str(), string
.size());
120 XftDrawString8(d
, &c
, _xftfont
, x
, _xftfont
->ascent
+ y
,
121 (const FcChar8
*)string
.c_str(), string
.size());
127 unsigned int BFont::measureString(const string
&string
, bool utf8
) const
132 XftTextExtentsUtf8(OBDisplay::display
, _xftfont
,
133 (const FcChar8
*)string
.c_str(), string
.size(), &info
);
135 XftTextExtents8(OBDisplay::display
, _xftfont
,
136 (const FcChar8
*)string
.c_str(), string
.size(), &info
);
138 return info
.xOff
+ (_shadow
? _offset
: 0);
142 unsigned int BFont::height(void) const
144 return _xftfont
->height
+ (_shadow
? _offset
: 0);
148 unsigned int BFont::maxCharWidth(void) const
150 return _xftfont
->max_advance_width
;
This page took 0.041813 seconds and 5 git commands to generate.