]> icculus.org git repositories - mikachu/openbox.git/blob - src/Font.hh
no more menus, at last. woop
[mikachu/openbox.git] / src / Font.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // Font.hh 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)
5 //
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:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
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.
23
24 #ifndef   __Font_hh
25 #define   __Font_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29
30 #ifdef XFT
31 #  include <X11/Xft/Xft.h>
32 #endif
33 }
34
35 #include <assert.h>
36
37 #include <string>
38
39 class BGCCache;
40 class BGCCacheItem;
41 class BColor;
42
43 #include "Screen.hh"
44
45 class BFont {
46   /*
47    * static members
48    */
49 private:
50   static std::string  _fallback_font;
51
52 public:
53   // the fallback is only used for X fonts, not for Xft fonts, since it is
54   // assumed that X fonts will be the fallback from Xft.
55   inline static std::string fallbackFont(void) { return _fallback_font; }
56   inline static void setFallbackFont(const std::string &f)
57     { _fallback_font = f; }
58
59   /*
60    * instance members
61    */
62 private:
63   Display          *_display;
64   BScreen          *_screen;
65
66   std::string       _family;
67   bool              _simplename;  // true if not spec'd as a -*-* string
68   int               _size;
69   bool              _bold;
70   bool              _italic;
71
72 #ifdef XFT
73   bool              _antialias;
74   bool              _shadow;
75   unsigned char     _offset;
76   int               _tint;
77
78   XftFont          *_xftfont;
79
80   bool createXftFont(void);
81 #endif
82   
83   // standard
84   XFontStruct      *_font;
85   // multibyte
86   XFontSet          _fontset;
87   XFontSetExtents  *_fontset_extents;
88
89   std::string buildXlfd(void) const;
90   std::string buildMultibyteXlfd(void) const;
91
92   bool createXFont(const std::string &xlfd);
93   bool parseXlfd(const std::string &xlfd);
94   
95   bool              _valid;
96
97 public:
98 #ifdef XFT
99   // loads an Xft font
100   BFont(Display *d, BScreen *screen, const std::string &family, int size,
101         bool bold, bool italic, bool shadow, unsigned char offset, 
102         int tint, bool antialias = True);
103 #endif
104   // loads a standard X font
105   BFont(Display *d, BScreen *screen, const std::string &xlfd);
106   virtual ~BFont(void);
107
108   inline bool valid(void) const { return _valid; }
109
110   inline std::string family(void) const { assert(_valid); return _family; }
111   inline int size(void) const { assert(_valid); return _size; }
112   inline bool bold(void) const { assert(_valid); return _bold; }
113   inline bool italic(void) const { assert(_valid); return _italic; }
114
115   unsigned int height(void) const;
116   unsigned int maxCharWidth(void) const;
117
118   unsigned int measureString(const std::string &string) const;
119
120   void drawString(Drawable d, int x, int y, const BColor &color,
121                   const std::string &string) const;
122 };
123
124 #endif // __Font_hh