]> Dogcows Code - chaz/openbox/blob - src/Font.hh
extend the style format to use xft.(font|size|flags) to specify an xft font
[chaz/openbox] / 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 bool _antialias;
51 static std::string _fallback_font;
52
53 public:
54 inline static bool antialias(void) { return _antialias; }
55 inline static void setAntialias(bool a) { _antialias = a; }
56
57 // the fallback is only used for X fonts, not for Xft fonts, since it is
58 // assumed that X fonts will be the fallback from Xft.
59 inline static std::string fallbackFont(void) { return _fallback_font; }
60 inline static void setFallbackFont(const std::string &f)
61 { _fallback_font = f; }
62
63 /*
64 * instance members
65 */
66 private:
67 Display *_display;
68 BScreen *_screen;
69
70 std::string _family;
71 bool _simplename; // true if not spec'd as a -*-* string
72 int _size;
73 bool _bold;
74 bool _italic;
75
76 #ifdef XFT
77 XftFont *_xftfont;
78
79 bool createXftFont(void);
80 #endif
81
82 // standard
83 XFontStruct *_font;
84 // multibyte
85 XFontSet _fontset;
86 XFontSetExtents *_fontset_extents;
87
88 std::string buildXlfd(void) const;
89 std::string buildMultibyteXlfd(void) const;
90
91 bool createXFont(const std::string &xlfd);
92 bool parseXlfd(const std::string &xlfd);
93
94 bool _valid;
95
96 public:
97 #ifdef XFT
98 // loads an Xft font
99 BFont(Display *d, BScreen *screen, const std::string &family, int size,
100 bool bold, bool italic);
101 #endif
102 // loads a standard X font
103 BFont(Display *d, BScreen *screen, const std::string &xlfd);
104 virtual ~BFont(void);
105
106 inline bool valid(void) const { return _valid; }
107
108 inline std::string family(void) const { assert(_valid); return _family; }
109 inline int size(void) const { assert(_valid); return _size; }
110 inline bool bold(void) const { assert(_valid); return _bold; }
111 inline bool italic(void) const { assert(_valid); return _italic; }
112
113 unsigned int height(void) const;
114 unsigned int maxCharWidth(void) const;
115
116 unsigned int measureString(const std::string &string) const;
117
118 void drawString(Drawable d, int x, int y, const BColor &color,
119 const std::string &string) const;
120 };
121
122 #endif // __Font_hh
This page took 0.037653 seconds and 4 git commands to generate.