aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Font.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-11-28 23:27:29 (GMT)
committerfluxgen <fluxgen>2003-11-28 23:27:29 (GMT)
commit9dc08a463c63d3d5c680d8dadf63a991cf9add7d (patch)
tree89c831d298fdffdd567c378d8057f916fbbb6c35 /src/FbTk/Font.cc
parent53e1f759c189dc8b3a8b3470b734999c9e5cea53 (diff)
downloadfluxbox_pavel-9dc08a463c63d3d5c680d8dadf63a991cf9add7d.zip
fluxbox_pavel-9dc08a463c63d3d5c680d8dadf63a991cf9add7d.tar.bz2
added shadow
Diffstat (limited to 'src/FbTk/Font.cc')
-rw-r--r--src/FbTk/Font.cc40
1 files changed, 34 insertions, 6 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
69Font::Font(const char *name, bool antialias): 71Font::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
138bool Font::load(const char *name) { 140bool 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
145unsigned int Font::textWidth(const char * const text, unsigned int size) const { 156unsigned int Font::textWidth(const char * const text, unsigned int size) const {
@@ -157,10 +168,24 @@ int Font::ascent() const {
157int Font::descent() const { 168int Font::descent() const {
158 return m_fontimp->descent(); 169 return m_fontimp->descent();
159} 170}
160void Font::drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y, 171void 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
184void Font::rotate(float angle) { 212void Font::rotate(float angle) {