don't include "cvs" in the version (not using cvs anymore :D)
[blackbox.git] / lib / Font.hh
blob87b3ca89ed548a5211e8006d3a5d3a6816e83ab4
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);
49 Returns the text indent (pad). Note that textRect() and
50 drawText() use this function (so you do not have to).
52 unsigned int textIndent(unsigned int screen, const Font &font);
54 Rect textRect(unsigned int screen, const Font &font,
55 const bt::ustring &text);
57 void drawText(const Font &font, const Pen &pen,
58 Drawable drawable, const Rect &rect,
59 Alignment alignment, const ustring &text);
62 * Take a string and make it 'count' chars long by removing the
63 * middle and replacing it with the string in 'ellide'.
65 ustring ellideText(const ustring &text, size_t count,
66 const ustring &ellide);
69 * Take a string and make no more than 'max_width' pixels wide by
70 * removing the middle and replacing it with the string in 'ellide'.
71 * The on-screen size of the string font is determined using the
72 * specified font on the specified screen.
74 ustring ellideText(const ustring &text,
75 unsigned int max_width,
76 const ustring &ellide,
77 unsigned int screen,
78 const bt::Font &font);
80 Alignment alignResource(const Resource &resource,
81 const char* name, const char* classname,
82 Alignment default_align = AlignLeft);
84 class Font {
85 public:
86 static void clearCache(void);
88 explicit inline Font(const std::string &name = std::string())
89 : _fontname(name), _fontset(0), _xftfont(0), _screen(~0u)
90 { }
91 inline ~Font(void)
92 { unload(); }
94 inline const std::string& fontName(void) const
95 { return _fontname; }
96 inline void setFontName(const std::string &new_fontname)
97 { unload(); _fontname = new_fontname; }
99 XFontSet fontSet(void) const;
100 XftFont *xftFont(unsigned int screen) const;
102 inline Font& operator=(const Font &f)
103 { setFontName(f.fontName()); return *this; }
104 inline bool operator==(const Font &f) const
105 { return _fontname == f._fontname; }
106 inline bool operator!=(const Font &f) const
107 { return (!operator==(f)); }
109 private:
110 void unload(void);
112 std::string _fontname;
113 mutable XFontSet _fontset;
114 mutable XftFont *_xftfont;
115 mutable unsigned int _screen; // only used for Xft
118 } // namespace bt
120 #endif // __Font_hh