diff options
-rw-r--r-- | src/FbTk/Font.cc | 40 | ||||
-rw-r--r-- | src/FbTk/Font.hh | 5 |
2 files changed, 37 insertions, 8 deletions
diff --git a/src/FbTk/Font.cc b/src/FbTk/Font.cc index f1ca707..071fc1e 100644 --- a/src/FbTk/Font.cc +++ b/src/FbTk/Font.cc | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | //$Id: Font.cc,v 1.4 2003/01/05 23:00:19 fluxgen Exp $ | 22 | //$Id: Font.cc,v 1.5 2003/11/28 23:27:29 fluxgen Exp $ |
23 | 23 | ||
24 | 24 | ||
25 | #include "Font.hh" | 25 | #include "Font.hh" |
@@ -42,6 +42,8 @@ | |||
42 | // standard font system | 42 | // standard font system |
43 | #include "XFontImp.hh" | 43 | #include "XFontImp.hh" |
44 | 44 | ||
45 | #include "GContext.hh" | ||
46 | |||
45 | //use gnu extensions | 47 | //use gnu extensions |
46 | #ifndef _GNU_SOURCE | 48 | #ifndef _GNU_SOURCE |
47 | #define _GNU_SOURCE | 49 | #define _GNU_SOURCE |
@@ -68,7 +70,7 @@ bool Font::m_utf8mode = false; | |||
68 | 70 | ||
69 | Font::Font(const char *name, bool antialias): | 71 | Font::Font(const char *name, bool antialias): |
70 | m_fontimp(0), | 72 | m_fontimp(0), |
71 | m_antialias(false), m_rotated(false) { | 73 | m_antialias(false), m_rotated(false), m_shadow(false) { |
72 | 74 | ||
73 | // MB_CUR_MAX returns the size of a char in the current locale | 75 | // MB_CUR_MAX returns the size of a char in the current locale |
74 | if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte | 76 | if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte |
@@ -135,11 +137,20 @@ void Font::setAntialias(bool flag) { | |||
135 | m_antialias = flag; | 137 | m_antialias = flag; |
136 | } | 138 | } |
137 | 139 | ||
138 | bool Font::load(const char *name) { | 140 | bool Font::load(const std::string &name) { |
139 | if (name == 0) | 141 | if (name.size() == 0) |
140 | return false; | 142 | return false; |
143 | |||
144 | // find font option "shadow" | ||
145 | m_shadow = false; | ||
146 | size_t start_pos = name.find_first_of(":"); | ||
147 | if (start_pos != std::string::npos) { | ||
148 | if (name.find_first_of("shadow", start_pos) != std::string::npos) | ||
149 | m_shadow = true; | ||
150 | } | ||
151 | |||
141 | m_fontstr = name; | 152 | m_fontstr = name; |
142 | return m_fontimp->load(name); | 153 | return m_fontimp->load(name.c_str()); |
143 | } | 154 | } |
144 | 155 | ||
145 | unsigned int Font::textWidth(const char * const text, unsigned int size) const { | 156 | unsigned int Font::textWidth(const char * const text, unsigned int size) const { |
@@ -157,10 +168,24 @@ int Font::ascent() const { | |||
157 | int Font::descent() const { | 168 | int Font::descent() const { |
158 | return m_fontimp->descent(); | 169 | return m_fontimp->descent(); |
159 | } | 170 | } |
160 | void Font::drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y, | 171 | void Font::drawText(Drawable w, int screen, GC gc, |
172 | const char *text, size_t len, int x, int y, | ||
161 | bool rotate) const { | 173 | bool rotate) const { |
162 | if (text == 0 || len == 0) | 174 | if (text == 0 || len == 0) |
163 | return; | 175 | return; |
176 | |||
177 | // so we don't end up in a loop with m_shadow | ||
178 | static bool first_run = true; | ||
179 | |||
180 | // draw shadow first | ||
181 | if (first_run && m_shadow) { | ||
182 | FbTk::GContext shadow_gc(w); | ||
183 | shadow_gc.setForeground(FbTk::Color("black", screen)); | ||
184 | first_run = false; // so we don't end up in a loop | ||
185 | drawText(w, screen, shadow_gc.gc(), text, len, x + 1, y + 1); | ||
186 | first_run = true; | ||
187 | } | ||
188 | |||
164 | if (!rotate && isRotated()) { | 189 | if (!rotate && isRotated()) { |
165 | // if this was called with request to not rotated the text | 190 | // if this was called with request to not rotated the text |
166 | // we just forward it to the implementation that handles rotation | 191 | // we just forward it to the implementation that handles rotation |
@@ -170,6 +195,7 @@ void Font::drawText(Drawable w, int screen, GC gc, const char *text, size_t len, | |||
170 | try { | 195 | try { |
171 | XFontImp *font = dynamic_cast<XFontImp *>(m_fontimp.get()); | 196 | XFontImp *font = dynamic_cast<XFontImp *>(m_fontimp.get()); |
172 | font->setRotate(false); // disable rotation temporarly | 197 | font->setRotate(false); // disable rotation temporarly |
198 | |||
173 | font->drawText(w, screen, gc, text, len, x, y); | 199 | font->drawText(w, screen, gc, text, len, x, y); |
174 | font->setRotate(true); // enable rotation | 200 | font->setRotate(true); // enable rotation |
175 | } catch (std::bad_cast &bc) { | 201 | } catch (std::bad_cast &bc) { |
@@ -179,6 +205,8 @@ void Font::drawText(Drawable w, int screen, GC gc, const char *text, size_t len, | |||
179 | 205 | ||
180 | } else | 206 | } else |
181 | m_fontimp->drawText(w, screen, gc, text, len, x, y); | 207 | m_fontimp->drawText(w, screen, gc, text, len, x, y); |
208 | |||
209 | |||
182 | } | 210 | } |
183 | 211 | ||
184 | void Font::rotate(float angle) { | 212 | void Font::rotate(float angle) { |
diff --git a/src/FbTk/Font.hh b/src/FbTk/Font.hh index 8ecb5ce..4a2c4cb 100644 --- a/src/FbTk/Font.hh +++ b/src/FbTk/Font.hh | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | //$Id: Font.hh,v 1.4 2003/04/14 12:07:03 fluxgen Exp $ | 22 | //$Id: Font.hh,v 1.5 2003/11/28 23:27:29 fluxgen Exp $ |
23 | 23 | ||
24 | #ifndef FBTK_FONT_HH | 24 | #ifndef FBTK_FONT_HH |
25 | #define FBTK_FONT_HH | 25 | #define FBTK_FONT_HH |
@@ -47,7 +47,7 @@ public: | |||
47 | @return true on success, else false and it'll fall back on the last | 47 | @return true on success, else false and it'll fall back on the last |
48 | loaded font | 48 | loaded font |
49 | */ | 49 | */ |
50 | bool load(const char *name); | 50 | bool load(const std::string &name); |
51 | 51 | ||
52 | /// @return true if multibyte is enabled, else false | 52 | /// @return true if multibyte is enabled, else false |
53 | static bool multibyte() { return m_multibyte; } | 53 | static bool multibyte() { return m_multibyte; } |
@@ -97,6 +97,7 @@ private: | |||
97 | bool m_antialias; ///< is font antialias | 97 | bool m_antialias; ///< is font antialias |
98 | bool m_rotated; ///< wheter we're rotated or not | 98 | bool m_rotated; ///< wheter we're rotated or not |
99 | float m_angle; ///< rotation angle | 99 | float m_angle; ///< rotation angle |
100 | bool m_shadow; ///< shadow text | ||
100 | }; | 101 | }; |
101 | 102 | ||
102 | }; //end namespace FbTk | 103 | }; //end namespace FbTk |