]>
Dogcows Code - chaz/openbox/blob - src/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
25 string
BFont::_fallback_font
= "fixed";
27 BFont::BFont(Display
*d
, BScreen
*screen
, const string
&family
, int size
,
28 bool bold
, bool italic
, bool shadow
, unsigned char offset
,
29 unsigned char tint
, bool antialias
) :
37 _antialias(antialias
),
44 _xftfont
= XftFontOpen(_display
, _screen
->getScreenNumber(),
45 XFT_FAMILY
, XftTypeString
, _family
.c_str(),
46 XFT_SIZE
, XftTypeInteger
, _size
,
47 XFT_WEIGHT
, XftTypeInteger
, (_bold
?
50 XFT_SLANT
, XftTypeInteger
, (_italic
?
53 XFT_ANTIALIAS
, XftTypeBool
, _antialias
,
64 XftFontClose(_display
, _xftfont
);
68 void BFont::drawString(Drawable d
, int x
, int y
, const BColor
&color
,
69 const string
&string
) const {
72 XftDraw
*draw
= XftDrawCreate(_display
, d
, _screen
->getVisual(),
73 _screen
->getColormap());
81 c
.color
.alpha
= _tint
| _tint
<< 8; // transparent shadow
82 c
.pixel
= BlackPixel(_display
, _screen
->getScreenNumber());
84 XftDrawStringUtf8(draw
, &c
, _xftfont
, x
+ _offset
,
85 _xftfont
->ascent
+ y
+ _offset
,
86 (XftChar8
*) string
.c_str(),
91 c
.color
.red
= color
.red() | color
.red() << 8;
92 c
.color
.green
= color
.green() | color
.green() << 8;
93 c
.color
.blue
= color
.blue() | color
.blue() << 8;
94 c
.pixel
= color
.pixel();
95 c
.color
.alpha
= 0xff | 0xff << 8; // no transparency in BColor yet
97 XftDrawStringUtf8(draw
, &c
, _xftfont
, x
, _xftfont
->ascent
+ y
,
98 (XftChar8
*) string
.c_str(), string
.size());
100 XftDrawDestroy(draw
);
105 unsigned int BFont::measureString(const string
&string
) const {
110 XftTextExtentsUtf8(_display
, _xftfont
, (XftChar8
*) string
.c_str(),
111 string
.size(), &info
);
113 return info
.xOff
+ (_shadow
? _offset
: 0);
117 unsigned int BFont::height(void) const {
120 return _xftfont
->height
+ (_shadow
? _offset
: 0);
124 unsigned int BFont::maxCharWidth(void) const {
127 return _xftfont
->max_advance_width
;
This page took 0.040384 seconds and 5 git commands to generate.