aboutsummaryrefslogtreecommitdiff
path: root/src/Font.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/Font.hh')
-rw-r--r--src/Font.hh93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/Font.hh b/src/Font.hh
new file mode 100644
index 0000000..66cd6cf
--- /dev/null
+++ b/src/Font.hh
@@ -0,0 +1,93 @@
1// Font.cc
2// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22//$Id: Font.hh,v 1.4 2002/08/04 15:55:13 fluxgen Exp $
23
24#ifndef FBTK_FONT_HH
25#define FBTK_FONT_HH
26
27#include <X11/Xlib.h>
28#include <X11/Xresource.h>
29
30namespace FbTk
31{
32
33/**
34 Handles loading of font.
35*/
36class Font
37{
38public:
39 Font(Display *display, const char *name=0);
40 virtual ~Font();
41 /**
42 Load a font
43 @return true on success, else false and it'll fall back on the last
44 loaded font
45 */
46 bool load(const char *name);
47 /**
48 Loads a font from database
49 @return true on success, else false and it'll fall back on the last
50 loaded font
51 @see load(const char *name)
52 */
53 bool loadFromDatabase(XrmDatabase &database, const char *rname, const char *rclass);
54 /// @return true if a font is loaded, else false
55 inline bool isLoaded() const { return m_loaded; }
56 /// @return XFontStruct of font, note: can be 0
57 inline const XFontStruct *fontStruct() const { return m_font.fontstruct; }
58 /// @return XFontSet of font, note: check isLoaded
59 inline const XFontSet &fontSet() const { return m_font.set; }
60 /// @return XFontSetExtents of font, note: can be 0
61 inline const XFontSetExtents *fontSetExtents() const { return m_font.set_extents; }
62 /// @return true if multibyte is enabled, else false
63 static inline bool multibyte() { return m_multibyte; }
64 /**
65 @param text text to check size
66 @param size length of text in bytes
67 @return size of text in pixels
68 */
69 unsigned int textWidth(const char *text, unsigned int size) const;
70 unsigned int height() const;
71 /// @return display connection
72 Display *display() const { return m_display; }
73private:
74 void freeFont();
75 static XFontSet createFontSet(Display *display, const char *fontname);
76 static const char *getFontSize(const char *pattern, int *size);
77 static const char *getFontElement(const char *pattern, char *buf, int bufsiz, ...);
78
79 struct FontType
80 {
81 XFontSet set;
82 XFontSetExtents *set_extents;
83 XFontStruct *fontstruct;
84 } m_font;
85
86 bool m_loaded;
87 static bool m_multibyte;
88 Display *m_display;
89};
90
91}; //end namespace FbTk
92
93#endif //FBTK_FONT_HH