From 66a3fc1c4dfa2cb68e650257e0bd10f2906c0d39 Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 19 Nov 2004 12:00:20 +0000 Subject: fixes fontsituations when text disappears in non-antialias mode primary problem was to use utf8 when in fact the FontSet wasnt utf8. --- src/FbTk/Font.cc | 27 +++++++++++++-------------- src/FbTk/FontImp.hh | 1 + src/FbTk/XftFontImp.hh | 1 + src/FbTk/XmbFontImp.cc | 8 +++++--- src/FbTk/XmbFontImp.hh | 3 ++- 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, // 2) An incomplete multibyte sequence // 3) The output buffer has no more room for the next converted character. // So we the delete new message and return original message - delete new_msg_ptr; + delete[] new_msg_ptr; free(orig_msg_ptr); return 0; } @@ -142,7 +142,7 @@ char* recode(iconv_t cd, *new_msg = '\0'; if(inbytesleft != 0) { - delete new_msg_ptr; + delete[] new_msg_ptr; return 0; } @@ -231,7 +231,7 @@ bool Font::m_utf8mode = false; // some initialisation for using fonts void fontInit() { - setlocale(LC_CTYPE, ""); + setlocale(LC_CTYPE, ""); } Font::Font(const char *name, bool antialias): @@ -239,13 +239,13 @@ Font::Font(const char *name, bool antialias): m_antialias(false), m_rotated(false), m_shadow(false), m_shadow_color("#000000"), m_shadow_offx(1), m_shadow_offy(1), - m_halo(false), m_halo_color("#ffffff") { - + m_halo(false), m_halo_color("#ffffff"), #ifdef HAVE_ICONV - m_iconv = (iconv_t)(-1); + m_iconv((iconv_t)(-1)) #else - m_iconv = -1; + m_iconv(-1) #endif // HAVE_ICONV +{ // MB_CUR_MAX returns the size of a char in the current locale if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte @@ -295,7 +295,6 @@ Font::Font(const char *name, bool antialias): #ifdef USE_XFT if (antialias) { m_fontimp.reset(new XftFontImp(0, m_utf8mode)); - m_antialias = true; } #endif //USE_XFT // if we didn't create a Xft font then create basic font @@ -341,9 +340,9 @@ void Font::setAntialias(bool flag) { if (!m_fontimp->load("fixed")) {// if that failes too, output warning _FB_USES_NLS; cerr<<_FBTKTEXT(Error, CantFallbackFont, "Warning: can't load fallback font", "Attempt to load the last-resort default font failed")<<" 'fixed'."<utf8() && m_iconv != (iconv_t)(-1)) { char* rtext = recode(m_iconv, text, size); if (rtext != 0) size = strlen(rtext); unsigned int r = m_fontimp->textWidth(rtext ? rtext : text, size); if (rtext != 0) - delete rtext; + delete[] rtext; return r; } #endif // HAVE_ICONV @@ -437,7 +436,7 @@ void Font::drawText(const FbDrawable &w, int screen, GC gc, static bool first_run = true; #ifdef HAVE_ICONV - if (m_iconv != (iconv_t)(-1) && first_run) { + if (m_fontimp->utf8() && m_iconv != (iconv_t)(-1) && first_run) { rtext = recode(m_iconv, text, len); if (rtext != 0) { len = strlen(rtext); @@ -490,7 +489,7 @@ void Font::drawText(const FbDrawable &w, int screen, GC gc, m_fontimp->drawText(w, screen, gc, real_text, len, x, y); if (rtext != 0) - delete rtext; + delete[] rtext; } 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: virtual unsigned int height() const = 0; virtual bool loaded() const = 0; virtual void rotate(float angle) { } // by default, no rotate support + virtual bool utf8() const { return false; }; protected: FontImp() { } }; 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: int ascent() const { return m_xftfont ? m_xftfont->ascent : 0; } int descent() const { return m_xftfont ? m_xftfont->descent : 0; } bool loaded() const { return m_xftfont != 0; } + bool utf8() const { return m_utf8mode; } private: XftFont *m_xftfont; 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, ...) { return 0; } -XFontSet createFontSet(const char *fontname, bool utf8mode) { +XFontSet createFontSet(const char *fontname, bool& utf8mode) { Display *display = FbTk::App::instance()->display(); XFontSet fs; const int FONT_ELEMENT_SIZE=50; @@ -192,13 +192,15 @@ XFontSet createFontSet(const char *fontname, bool utf8mode) { setlocale(LC_CTYPE, orig_locale.c_str()); #endif // HAVE_SETLOCALE + utf8mode = false; + return fs; } }; namespace FbTk { -XmbFontImp::XmbFontImp(const char *filename, bool utf8):m_fontset(0), m_setextents(0), m_utf8mode(utf8) { +XmbFontImp::XmbFontImp(const char *filename, bool utf8) : m_fontset(0), m_setextents(0), m_utf8mode(utf8) { if (filename != 0) load(filename); } @@ -209,7 +211,7 @@ XmbFontImp::~XmbFontImp() { } bool XmbFontImp::load(const std::string &fontname) { - if (fontname.size() == 0) + if (fontname.empty()) return false; 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: int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; } int descent() const { return m_setextents ? m_setextents->max_ink_extent.height + m_setextents->max_ink_extent.y : 0; } bool loaded() const { return m_fontset != 0; } + bool utf8() const { return m_utf8mode; } private: XFontSet m_fontset; XFontSetExtents *m_setextents; - const bool m_utf8mode; + bool m_utf8mode; }; } // end namespace FbTk -- cgit v0.11.2