]>
Dogcows Code - chaz/openbox/blob - src/font.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Font.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
25 # include "../config.h"
26 #endif // HAVE_CONFIG_H
31 #endif // HAVE_STDLIB_H
46 string
BFont::_fallback_font
= "fixed";
48 BFont::BFont(Display
*d
, BScreen
*screen
, const string
&family
, int size
,
49 bool bold
, bool italic
, bool shadow
, unsigned char offset
,
50 unsigned char tint
, bool antialias
) :
58 _antialias(antialias
),
65 _xftfont
= XftFontOpen(_display
, _screen
->getScreenNumber(),
66 XFT_FAMILY
, XftTypeString
, _family
.c_str(),
67 XFT_SIZE
, XftTypeInteger
, _size
,
68 XFT_WEIGHT
, XftTypeInteger
, (_bold
?
71 XFT_SLANT
, XftTypeInteger
, (_italic
?
74 XFT_ANTIALIAS
, XftTypeBool
, _antialias
,
85 XftFontClose(_display
, _xftfont
);
89 void BFont::drawString(Drawable d
, int x
, int y
, const BColor
&color
,
90 const string
&string
) const {
93 XftDraw
*draw
= XftDrawCreate(_display
, d
, _screen
->getVisual(),
94 _screen
->getColormap());
102 c
.color
.alpha
= _tint
| _tint
<< 8; // transparent shadow
103 c
.pixel
= BlackPixel(_display
, _screen
->getScreenNumber());
105 XftDrawStringUtf8(draw
, &c
, _xftfont
, x
+ _offset
,
106 _xftfont
->ascent
+ y
+ _offset
,
107 (XftChar8
*) string
.c_str(),
112 c
.color
.red
= color
.red() | color
.red() << 8;
113 c
.color
.green
= color
.green() | color
.green() << 8;
114 c
.color
.blue
= color
.blue() | color
.blue() << 8;
115 c
.pixel
= color
.pixel();
116 c
.color
.alpha
= 0xff | 0xff << 8; // no transparency in BColor yet
118 XftDrawStringUtf8(draw
, &c
, _xftfont
, x
, _xftfont
->ascent
+ y
,
119 (XftChar8
*) string
.c_str(), string
.size());
121 XftDrawDestroy(draw
);
126 unsigned int BFont::measureString(const string
&string
) const {
131 XftTextExtentsUtf8(_display
, _xftfont
, (XftChar8
*) string
.c_str(),
132 string
.size(), &info
);
134 return info
.xOff
+ (_shadow
? _offset
: 0);
138 unsigned int BFont::height(void) const {
141 return _xftfont
->height
+ (_shadow
? _offset
: 0);
145 unsigned int BFont::maxCharWidth(void) const {
148 return _xftfont
->max_advance_width
;
This page took 0.047654 seconds and 5 git commands to generate.