]> icculus.org git repositories - mikachu/openbox.git/blob - otk/font.hh
import config
[mikachu/openbox.git] / otk / font.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef   __font_hh
3 #define   __font_hh
4
5 #include "ustring.hh"
6 #include "truerendercontrol.hh"
7
8 extern "C" {
9 #include <X11/Xlib.h>
10 #define _XFT_NO_COMPAT_ // no Xft 1 API
11 #include <X11/Xft/Xft.h>
12 }
13
14 #include <assert.h>
15
16 namespace otk {
17
18 class Color;
19 class Surface;
20
21 class Font {
22   /*
23    * static members
24    */
25 private:
26   static std::string  _fallback_font;
27   static bool         _xft_init;
28
29 public:
30   // the fallback is only used for X fonts, not for Xft fonts, since it is
31   // assumed that X fonts will be the fallback from Xft.
32   inline static std::string fallbackFont(void) { return _fallback_font; }
33   inline static void setFallbackFont(const std::string &f)
34     { _fallback_font = f; }
35
36   /*
37    * instance members
38    */
39 private:
40   int               _screen_num;
41
42   std::string       _fontstring;
43
44   bool              _shadow;
45   unsigned char     _offset;
46   unsigned char     _tint;
47
48   XftFont          *_xftfont;
49
50   bool createXftFont(void);
51   
52 public:
53   // loads an Xft font
54   Font(int screen_num, const std::string &fontstring, bool shadow,
55         unsigned char offset, unsigned char tint);
56   virtual ~Font();
57
58   inline const std::string &fontstring() const { return _fontstring; }
59
60   int height() const;
61   int maxCharWidth() const;
62
63   int measureString(const ustring &string) const;
64
65   // The RenderControl classes use the internal data to render the fonts, but
66   // noone else needs it, so its private.
67   friend class RenderControl;
68 };
69
70 }
71
72 #endif // __font_hh