summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathias <mathias>2004-11-19 12:00:20 (GMT)
committermathias <mathias>2004-11-19 12:00:20 (GMT)
commit66a3fc1c4dfa2cb68e650257e0bd10f2906c0d39 (patch)
tree76f6052a4f5e52288107a78d4307fd719c20b5f6 /src
parent993c17cf2efd3caba5241276c268909197dd3681 (diff)
downloadfluxbox_lack-66a3fc1c4dfa2cb68e650257e0bd10f2906c0d39.zip
fluxbox_lack-66a3fc1c4dfa2cb68e650257e0bd10f2906c0d39.tar.bz2
fixes fontsituations when text disappears in non-antialias mode
primary problem was to use utf8 when in fact the FontSet wasnt utf8.
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/Font.cc27
-rw-r--r--src/FbTk/FontImp.hh1
-rw-r--r--src/FbTk/XftFontImp.hh1
-rw-r--r--src/FbTk/XmbFontImp.cc8
-rw-r--r--src/FbTk/XmbFontImp.hh3
5 files changed, 22 insertions, 18 deletions
diff --git a/src/FbTk/Font.cc b/src/FbTk/Font.cc
index 3bacbce..e2e3dec 100644
--- a/src/FbTk/Font.cc
+++ b/src/FbTk/Font.cc
@@ -133,7 +133,7 @@ char* recode(iconv_t cd,
133 // 2) An incomplete multibyte sequence 133 // 2) An incomplete multibyte sequence
134 // 3) The output buffer has no more room for the next converted character. 134 // 3) The output buffer has no more room for the next converted character.
135 // So we the delete new message and return original message 135 // So we the delete new message and return original message
136 delete new_msg_ptr; 136 delete[] new_msg_ptr;
137 free(orig_msg_ptr); 137 free(orig_msg_ptr);
138 return 0; 138 return 0;
139 } 139 }
@@ -142,7 +142,7 @@ char* recode(iconv_t cd,
142 *new_msg = '\0'; 142 *new_msg = '\0';
143 143
144 if(inbytesleft != 0) { 144 if(inbytesleft != 0) {
145 delete new_msg_ptr; 145 delete[] new_msg_ptr;
146 return 0; 146 return 0;
147 } 147 }
148 148
@@ -231,7 +231,7 @@ bool Font::m_utf8mode = false;
231 231
232// some initialisation for using fonts 232// some initialisation for using fonts
233void fontInit() { 233void fontInit() {
234 setlocale(LC_CTYPE, ""); 234 setlocale(LC_CTYPE, "");
235} 235}
236 236
237Font::Font(const char *name, bool antialias): 237Font::Font(const char *name, bool antialias):
@@ -239,13 +239,13 @@ Font::Font(const char *name, bool antialias):
239 m_antialias(false), m_rotated(false), 239 m_antialias(false), m_rotated(false),
240 m_shadow(false), m_shadow_color("#000000"), 240 m_shadow(false), m_shadow_color("#000000"),
241 m_shadow_offx(1), m_shadow_offy(1), 241 m_shadow_offx(1), m_shadow_offy(1),
242 m_halo(false), m_halo_color("#ffffff") { 242 m_halo(false), m_halo_color("#ffffff"),
243
244#ifdef HAVE_ICONV 243#ifdef HAVE_ICONV
245 m_iconv = (iconv_t)(-1); 244 m_iconv((iconv_t)(-1))
246#else 245#else
247 m_iconv = -1; 246 m_iconv(-1)
248#endif // HAVE_ICONV 247#endif // HAVE_ICONV
248{
249 249
250 // MB_CUR_MAX returns the size of a char in the current locale 250 // MB_CUR_MAX returns the size of a char in the current locale
251 if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte 251 if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte
@@ -295,7 +295,6 @@ Font::Font(const char *name, bool antialias):
295#ifdef USE_XFT 295#ifdef USE_XFT
296 if (antialias) { 296 if (antialias) {
297 m_fontimp.reset(new XftFontImp(0, m_utf8mode)); 297 m_fontimp.reset(new XftFontImp(0, m_utf8mode));
298 m_antialias = true;
299 } 298 }
300#endif //USE_XFT 299#endif //USE_XFT
301 // if we didn't create a Xft font then create basic font 300 // if we didn't create a Xft font then create basic font
@@ -341,9 +340,9 @@ void Font::setAntialias(bool flag) {
341 if (!m_fontimp->load("fixed")) {// if that failes too, output warning 340 if (!m_fontimp->load("fixed")) {// if that failes too, output warning
342 _FB_USES_NLS; 341 _FB_USES_NLS;
343 cerr<<_FBTKTEXT(Error, CantFallbackFont, "Warning: can't load fallback font", "Attempt to load the last-resort default font failed")<<" 'fixed'."<<endl; 342 cerr<<_FBTKTEXT(Error, CantFallbackFont, "Warning: can't load fallback font", "Attempt to load the last-resort default font failed")<<" 'fixed'."<<endl;
344 } 343 }
345 } 344 }
346 345
347 m_antialias = flag; 346 m_antialias = flag;
348} 347}
349 348
@@ -400,13 +399,13 @@ bool Font::load(const std::string &name) {
400 399
401unsigned int Font::textWidth(const char * const text, unsigned int size) const { 400unsigned int Font::textWidth(const char * const text, unsigned int size) const {
402#ifdef HAVE_ICONV 401#ifdef HAVE_ICONV
403 if (m_iconv != (iconv_t)(-1)) { 402 if (m_fontimp->utf8() && m_iconv != (iconv_t)(-1)) {
404 char* rtext = recode(m_iconv, text, size); 403 char* rtext = recode(m_iconv, text, size);
405 if (rtext != 0) 404 if (rtext != 0)
406 size = strlen(rtext); 405 size = strlen(rtext);
407 unsigned int r = m_fontimp->textWidth(rtext ? rtext : text, size); 406 unsigned int r = m_fontimp->textWidth(rtext ? rtext : text, size);
408 if (rtext != 0) 407 if (rtext != 0)
409 delete rtext; 408 delete[] rtext;
410 return r; 409 return r;
411 } 410 }
412#endif // HAVE_ICONV 411#endif // HAVE_ICONV
@@ -437,7 +436,7 @@ void Font::drawText(const FbDrawable &w, int screen, GC gc,
437 static bool first_run = true; 436 static bool first_run = true;
438 437
439#ifdef HAVE_ICONV 438#ifdef HAVE_ICONV
440 if (m_iconv != (iconv_t)(-1) && first_run) { 439 if (m_fontimp->utf8() && m_iconv != (iconv_t)(-1) && first_run) {
441 rtext = recode(m_iconv, text, len); 440 rtext = recode(m_iconv, text, len);
442 if (rtext != 0) { 441 if (rtext != 0) {
443 len = strlen(rtext); 442 len = strlen(rtext);
@@ -490,7 +489,7 @@ void Font::drawText(const FbDrawable &w, int screen, GC gc,
490 m_fontimp->drawText(w, screen, gc, real_text, len, x, y); 489 m_fontimp->drawText(w, screen, gc, real_text, len, x, y);
491 490
492 if (rtext != 0) 491 if (rtext != 0)
493 delete rtext; 492 delete[] rtext;
494 493
495} 494}
496 495
diff --git a/src/FbTk/FontImp.hh b/src/FbTk/FontImp.hh
index 8691feb..4cdf839 100644
--- a/src/FbTk/FontImp.hh
+++ b/src/FbTk/FontImp.hh
@@ -50,6 +50,7 @@ public:
50 virtual unsigned int height() const = 0; 50 virtual unsigned int height() const = 0;
51 virtual bool loaded() const = 0; 51 virtual bool loaded() const = 0;
52 virtual void rotate(float angle) { } // by default, no rotate support 52 virtual void rotate(float angle) { } // by default, no rotate support
53 virtual bool utf8() const { return false; };
53protected: 54protected:
54 FontImp() { } 55 FontImp() { }
55}; 56};
diff --git a/src/FbTk/XftFontImp.hh b/src/FbTk/XftFontImp.hh
index c04084d..466f58d 100644
--- a/src/FbTk/XftFontImp.hh
+++ b/src/FbTk/XftFontImp.hh
@@ -42,6 +42,7 @@ public:
42 int ascent() const { return m_xftfont ? m_xftfont->ascent : 0; } 42 int ascent() const { return m_xftfont ? m_xftfont->ascent : 0; }
43 int descent() const { return m_xftfont ? m_xftfont->descent : 0; } 43 int descent() const { return m_xftfont ? m_xftfont->descent : 0; }
44 bool loaded() const { return m_xftfont != 0; } 44 bool loaded() const { return m_xftfont != 0; }
45 bool utf8() const { return m_utf8mode; }
45private: 46private:
46 XftFont *m_xftfont; 47 XftFont *m_xftfont;
47 bool m_utf8mode; 48 bool m_utf8mode;
diff --git a/src/FbTk/XmbFontImp.cc b/src/FbTk/XmbFontImp.cc
index fe222db..79a50fb 100644
--- a/src/FbTk/XmbFontImp.cc
+++ b/src/FbTk/XmbFontImp.cc
@@ -110,7 +110,7 @@ const char *getFontElement(const char *pattern, char *buf, int bufsiz, ...) {
110 return 0; 110 return 0;
111} 111}
112 112
113XFontSet createFontSet(const char *fontname, bool utf8mode) { 113XFontSet createFontSet(const char *fontname, bool& utf8mode) {
114 Display *display = FbTk::App::instance()->display(); 114 Display *display = FbTk::App::instance()->display();
115 XFontSet fs; 115 XFontSet fs;
116 const int FONT_ELEMENT_SIZE=50; 116 const int FONT_ELEMENT_SIZE=50;
@@ -192,13 +192,15 @@ XFontSet createFontSet(const char *fontname, bool utf8mode) {
192 setlocale(LC_CTYPE, orig_locale.c_str()); 192 setlocale(LC_CTYPE, orig_locale.c_str());
193#endif // HAVE_SETLOCALE 193#endif // HAVE_SETLOCALE
194 194
195 utf8mode = false;
196
195 return fs; 197 return fs;
196} 198}
197 199
198}; 200};
199namespace FbTk { 201namespace FbTk {
200 202
201XmbFontImp::XmbFontImp(const char *filename, bool utf8):m_fontset(0), m_setextents(0), m_utf8mode(utf8) { 203XmbFontImp::XmbFontImp(const char *filename, bool utf8) : m_fontset(0), m_setextents(0), m_utf8mode(utf8) {
202 if (filename != 0) 204 if (filename != 0)
203 load(filename); 205 load(filename);
204} 206}
@@ -209,7 +211,7 @@ XmbFontImp::~XmbFontImp() {
209} 211}
210 212
211bool XmbFontImp::load(const std::string &fontname) { 213bool XmbFontImp::load(const std::string &fontname) {
212 if (fontname.size() == 0) 214 if (fontname.empty())
213 return false; 215 return false;
214 216
215 XFontSet set = createFontSet(fontname.c_str(), m_utf8mode); 217 XFontSet set = createFontSet(fontname.c_str(), m_utf8mode);
diff --git a/src/FbTk/XmbFontImp.hh b/src/FbTk/XmbFontImp.hh
index ac9f0ee..cba6001 100644
--- a/src/FbTk/XmbFontImp.hh
+++ b/src/FbTk/XmbFontImp.hh
@@ -42,10 +42,11 @@ public:
42 int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; } 42 int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; }
43 int descent() const { return m_setextents ? m_setextents->max_ink_extent.height + m_setextents->max_ink_extent.y : 0; } 43 int descent() const { return m_setextents ? m_setextents->max_ink_extent.height + m_setextents->max_ink_extent.y : 0; }
44 bool loaded() const { return m_fontset != 0; } 44 bool loaded() const { return m_fontset != 0; }
45 bool utf8() const { return m_utf8mode; }
45private: 46private:
46 XFontSet m_fontset; 47 XFontSet m_fontset;
47 XFontSetExtents *m_setextents; 48 XFontSetExtents *m_setextents;
48 const bool m_utf8mode; 49 bool m_utf8mode;
49}; 50};
50 51
51} // end namespace FbTk 52} // end namespace FbTk