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"
28 string BFont::_fallback_font = "fixed";
30 BFont::BFont(int screen_num, const string &family, int size,
31 bool bold, bool italic, bool shadow, unsigned char offset,
32 unsigned char tint, bool antialias) :
33 _screen_num(screen_num),
39 _antialias(antialias),
46 _xftfont = XftFontOpen(OBDisplay::display, _screen_num,
47 XFT_FAMILY, XftTypeString, _family.c_str(),
48 XFT_SIZE, XftTypeInteger, _size,
49 XFT_WEIGHT, XftTypeInteger, (_bold ?
52 XFT_SLANT, XftTypeInteger, (_italic ?
55 XFT_ANTIALIAS, XftTypeBool, _antialias,
66 XftFontClose(OBDisplay::display, _xftfont);
70 void BFont::drawString(Drawable d, int x, int y, const BColor &color,
71 const string &string) const {
74 const ScreenInfo *info = OBDisplay::screenInfo(_screen_num);
75 XftDraw *draw = XftDrawCreate(OBDisplay::display, d,
76 info->getVisual(), info->getColormap());
84 c.color.alpha = _tint | _tint << 8; // transparent shadow
85 c.pixel = BlackPixel(OBDisplay::display, _screen_num);
87 XftDrawString8(draw, &c, _xftfont, x + _offset,
88 _xftfont->ascent + y + _offset,
89 (XftChar8 *) string.c_str(),
94 c.color.red = color.red() | color.red() << 8;
95 c.color.green = color.green() | color.green() << 8;
96 c.color.blue = color.blue() | color.blue() << 8;
97 c.pixel = color.pixel();
98 c.color.alpha = 0xff | 0xff << 8; // no transparency in BColor yet
100 XftDrawString8(draw, &c, _xftfont, x, _xftfont->ascent + y,
101 (XftChar8 *) string.c_str(), string.size());
103 XftDrawDestroy(draw);
108 unsigned int BFont::measureString(const string &string) const {
113 XftTextExtents8(OBDisplay::display, _xftfont,
114 (XftChar8 *) string.c_str(), string.size(), &info);
116 return info.xOff + (_shadow ? _offset : 0);
120 unsigned int BFont::height(void) const {
123 return _xftfont->height + (_shadow ? _offset : 0);
127 unsigned int BFont::maxCharWidth(void) const {
130 return _xftfont->max_advance_width;