]> Dogcows Code - chaz/openbox/blob - otk/font.hh
default to drawing as utf8
[chaz/openbox] / otk / font.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __font_hh
3 #define __font_hh
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 #define _XFT_NO_COMPAT_ // no Xft 1 API
8 #include <X11/Xft/Xft.h>
9 }
10
11 #include <assert.h>
12 #include <string>
13
14 namespace otk {
15
16 class Color;
17
18 class Font {
19 /*
20 * static members
21 */
22 private:
23 static std::string _fallback_font;
24 static bool _xft_init;
25
26 public:
27 // the fallback is only used for X fonts, not for Xft fonts, since it is
28 // assumed that X fonts will be the fallback from Xft.
29 inline static std::string fallbackFont(void) { return _fallback_font; }
30 inline static void setFallbackFont(const std::string &f)
31 { _fallback_font = f; }
32
33 /*
34 * instance members
35 */
36 private:
37 int _screen_num;
38
39 std::string _fontstring;
40
41 bool _shadow;
42 unsigned char _offset;
43 unsigned char _tint;
44
45 XftFont *_xftfont;
46
47 bool createXftFont(void);
48
49 public:
50 // loads an Xft font
51 Font(int screen_num, const std::string &fontstring, bool shadow,
52 unsigned char offset, unsigned char tint);
53 virtual ~Font();
54
55 inline const std::string &fontstring() const { return _fontstring; }
56
57 unsigned int height() const;
58 unsigned int maxCharWidth() const;
59
60 unsigned int measureString(const std::string &string,
61 bool utf8 = true) const;
62
63 //! Draws a string into an XftDraw object
64 /*!
65 Be Warned: If you use an XftDraw object and a color, or a font from
66 different screens, you WILL have unpredictable results! :)
67 */
68 void drawString(XftDraw *d, int x, int y, const Color &color,
69 const std::string &string, bool utf8 = true) const;
70 };
71
72 }
73
74 #endif // __font_hh
This page took 0.038178 seconds and 4 git commands to generate.