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>
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.
33 // forward declarations
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
,
78 const bt::Font
&font
);
80 Alignment
alignResource(const Resource
&resource
,
81 const char* name
, const char* classname
,
82 Alignment default_align
= AlignLeft
);
86 static void clearCache(void);
88 explicit inline Font(const std::string
&name
= std::string())
89 : _fontname(name
), _fontset(0), _xftfont(0), _screen(~0u)
94 inline const std::string
& fontName(void) const
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
)); }
112 std::string _fontname
;
113 mutable XFontSet _fontset
;
114 mutable XftFont
*_xftfont
;
115 mutable unsigned int _screen
; // only used for Xft