]> icculus.org git repositories - mikachu/openbox.git/blob - otk/font.hh
dont need unistd for gettimeofday
[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
7 extern "C" {
8 #include <X11/Xlib.h>
9 #define _XFT_NO_COMPAT_ // no Xft 1 API
10 #include <X11/Xft/Xft.h>
11 }
12
13 #include <assert.h>
14
15 namespace otk {
16
17 class Color;
18
19 class Font {
20   /*
21    * static members
22    */
23 private:
24   static std::string  _fallback_font;
25   static bool         _xft_init;
26
27 public:
28   // the fallback is only used for X fonts, not for Xft fonts, since it is
29   // assumed that X fonts will be the fallback from Xft.
30   inline static std::string fallbackFont(void) { return _fallback_font; }
31   inline static void setFallbackFont(const std::string &f)
32     { _fallback_font = f; }
33
34   /*
35    * instance members
36    */
37 private:
38   int               _screen_num;
39
40   std::string       _fontstring;
41
42   bool              _shadow;
43   unsigned char     _offset;
44   unsigned char     _tint;
45
46   XftFont          *_xftfont;
47
48   bool createXftFont(void);
49   
50 public:
51   // loads an Xft font
52   Font(int screen_num, const std::string &fontstring, bool shadow,
53         unsigned char offset, unsigned char tint);
54   virtual ~Font();
55
56   inline const std::string &fontstring() const { return _fontstring; }
57
58   unsigned int height() const;
59   unsigned int maxCharWidth() const;
60
61   unsigned int measureString(const ustring &string) 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 ustring &string) const;
70 };
71
72 }
73
74 #endif // __font_hh