allow the user to override the rootCommand from their ~/.blackboxrc
[blackbox.git] / lib / Font.hh
blob968abeb6b93497995690c6ad680913a5ddc0b87b
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Font.hh for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000, 2002 - 2005
5 // Bradley T Hughes <bhughes at trolltech.com>
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
25 #ifndef __Font_hh
26 #define __Font_hh
28 #include "Unicode.hh"
29 #include "Util.hh"
31 namespace bt {
33 // forward declarations
34 class Display;
35 class Font;
36 class Pen;
37 class Rect;
38 class Resource;
40 enum Alignment {
41 AlignLeft,
42 AlignCenter,
43 AlignRight
46 unsigned int textHeight(unsigned int screen, const Font &font);
48 Rect textRect(unsigned int screen, const Font &font,
49 const bt::ustring &text);
51 void drawText(const Font &font, const Pen &pen,
52 Drawable drawable, const Rect &rect,
53 Alignment alignment, const ustring &text);
56 * Take a string and make it 'count' chars long by removing the
57 * middle and replacing it with the string in 'ellide'.
59 ustring ellideText(const ustring &text, size_t count,
60 const ustring &ellide);
63 * Take a string and make no more than 'max_width' pixels wide by
64 * removing the middle and replacing it with the string in 'ellide'.
65 * The on-screen size of the string font is determined using the
66 * specified font on the specified screen.
68 ustring ellideText(const ustring &text,
69 unsigned int max_width,
70 const ustring &ellide,
71 unsigned int screen,
72 const bt::Font &font);
74 Alignment alignResource(const Resource &resource,
75 const char* name, const char* classname,
76 Alignment default_align = AlignLeft);
78 class Font {
79 public:
80 static void clearCache(void);
82 explicit inline Font(const std::string &name = std::string())
83 : _fontname(name), _fontset(0), _xftfont(0), _screen(~0u)
84 { }
85 inline ~Font(void)
86 { unload(); }
88 inline const std::string& fontName(void) const
89 { return _fontname; }
90 inline void setFontName(const std::string &new_fontname)
91 { unload(); _fontname = new_fontname; }
93 XFontSet fontSet(void) const;
94 XftFont *xftFont(unsigned int screen) const;
96 inline Font& operator=(const Font &f)
97 { setFontName(f.fontName()); return *this; }
98 inline bool operator==(const Font &f) const
99 { return _fontname == f._fontname; }
100 inline bool operator!=(const Font &f) const
101 { return (!operator==(f)); }
103 private:
104 void unload(void);
106 std::string _fontname;
107 mutable XFontSet _fontset;
108 mutable XftFont *_xftfont;
109 mutable unsigned int _screen; // only used for Xft
112 } // namespace bt
114 #endif // __Font_hh