diff options
Diffstat (limited to 'src/FbTk/Font.hh')
-rw-r--r-- | src/FbTk/Font.hh | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/FbTk/Font.hh b/src/FbTk/Font.hh new file mode 100644 index 0000000..8ecb5ce --- /dev/null +++ b/src/FbTk/Font.hh | |||
@@ -0,0 +1,104 @@ | |||
1 | // Font.cc for FbTk | ||
2 | // Copyright (c) 2002 Henrik Kinnunen (fluxgen at 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 2003/04/14 12:07:03 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 | |||
30 | #include <string> | ||
31 | #include <memory> | ||
32 | |||
33 | namespace FbTk { | ||
34 | |||
35 | class FontImp; | ||
36 | |||
37 | /** | ||
38 | Handles the client to fontimp bridge. | ||
39 | */ | ||
40 | class Font { | ||
41 | public: | ||
42 | |||
43 | Font(const char *name=0, bool antialias = false); | ||
44 | virtual ~Font(); | ||
45 | /** | ||
46 | Load a font | ||
47 | @return true on success, else false and it'll fall back on the last | ||
48 | loaded font | ||
49 | */ | ||
50 | bool load(const char *name); | ||
51 | |||
52 | /// @return true if multibyte is enabled, else false | ||
53 | static bool multibyte() { return m_multibyte; } | ||
54 | /// @return true if utf-8 mode is enabled, else false | ||
55 | static bool utf8() { return m_utf8mode; } | ||
56 | void setAntialias(bool flag); | ||
57 | /** | ||
58 | @param text text to check size | ||
59 | @param size length of text in bytes | ||
60 | @return size of text in pixels | ||
61 | */ | ||
62 | unsigned int textWidth(const char * const text, unsigned int size) const; | ||
63 | unsigned int height() const; | ||
64 | int ascent() const; | ||
65 | int descent() const; | ||
66 | /** | ||
67 | Rotate font in any angle | ||
68 | (currently only 90 degrees supported and just XFont implementation) | ||
69 | */ | ||
70 | void rotate(float angle); | ||
71 | |||
72 | /** | ||
73 | Draws text to drawable | ||
74 | @param w the drawable | ||
75 | @param screen screen number | ||
76 | @param gc Graphic Context | ||
77 | @param text the text buffer | ||
78 | @param len size of text buffer | ||
79 | @param x position | ||
80 | @param y position | ||
81 | @param rotate if the text should be drawn rotated (if it's rotated before) | ||
82 | */ | ||
83 | void drawText(Drawable w, int screen, GC gc, | ||
84 | const char *text, size_t len, | ||
85 | int x, int y, bool rotate=true) const; | ||
86 | bool isAntialias() const { return m_antialias; } | ||
87 | /// @return true if the font is rotated, else false | ||
88 | bool isRotated() const { return m_rotated; } | ||
89 | /// @return rotated angle | ||
90 | float angle() const { return m_angle; } | ||
91 | private: | ||
92 | |||
93 | std::auto_ptr<FontImp> m_fontimp; ///< font implementation | ||
94 | std::string m_fontstr; ///< font name | ||
95 | static bool m_multibyte; ///< if the fontimp should be a multibyte font | ||
96 | static bool m_utf8mode; ///< should the font use utf8 font imp | ||
97 | bool m_antialias; ///< is font antialias | ||
98 | bool m_rotated; ///< wheter we're rotated or not | ||
99 | float m_angle; ///< rotation angle | ||
100 | }; | ||
101 | |||
102 | }; //end namespace FbTk | ||
103 | |||
104 | #endif //FBTK_FONT_HH | ||