fixes fontsituations when text disappears in non-antialias mode

primary problem was to use utf8 when in fact the FontSet wasnt
utf8.
This commit is contained in:
mathias 2004-11-19 12:00:20 +00:00
parent 993c17cf2e
commit 66a3fc1c4d
5 changed files with 22 additions and 18 deletions

View file

@ -133,7 +133,7 @@ char* recode(iconv_t cd,
// 2) An incomplete multibyte sequence // 2) An incomplete multibyte sequence
// 3) The output buffer has no more room for the next converted character. // 3) The output buffer has no more room for the next converted character.
// So we the delete new message and return original message // So we the delete new message and return original message
delete new_msg_ptr; delete[] new_msg_ptr;
free(orig_msg_ptr); free(orig_msg_ptr);
return 0; return 0;
} }
@ -142,7 +142,7 @@ char* recode(iconv_t cd,
*new_msg = '\0'; *new_msg = '\0';
if(inbytesleft != 0) { if(inbytesleft != 0) {
delete new_msg_ptr; delete[] new_msg_ptr;
return 0; return 0;
} }
@ -239,13 +239,13 @@ Font::Font(const char *name, bool antialias):
m_antialias(false), m_rotated(false), m_antialias(false), m_rotated(false),
m_shadow(false), m_shadow_color("#000000"), m_shadow(false), m_shadow_color("#000000"),
m_shadow_offx(1), m_shadow_offy(1), 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 #ifdef HAVE_ICONV
m_iconv = (iconv_t)(-1); m_iconv((iconv_t)(-1))
#else #else
m_iconv = -1; m_iconv(-1)
#endif // HAVE_ICONV #endif // HAVE_ICONV
{
// MB_CUR_MAX returns the size of a char in the current locale // 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 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 #ifdef USE_XFT
if (antialias) { if (antialias) {
m_fontimp.reset(new XftFontImp(0, m_utf8mode)); m_fontimp.reset(new XftFontImp(0, m_utf8mode));
m_antialias = true;
} }
#endif //USE_XFT #endif //USE_XFT
// if we didn't create a Xft font then create basic font // if we didn't create a Xft font then create basic font
@ -400,13 +399,13 @@ bool Font::load(const std::string &name) {
unsigned int Font::textWidth(const char * const text, unsigned int size) const { unsigned int Font::textWidth(const char * const text, unsigned int size) const {
#ifdef HAVE_ICONV #ifdef HAVE_ICONV
if (m_iconv != (iconv_t)(-1)) { if (m_fontimp->utf8() && m_iconv != (iconv_t)(-1)) {
char* rtext = recode(m_iconv, text, size); char* rtext = recode(m_iconv, text, size);
if (rtext != 0) if (rtext != 0)
size = strlen(rtext); size = strlen(rtext);
unsigned int r = m_fontimp->textWidth(rtext ? rtext : text, size); unsigned int r = m_fontimp->textWidth(rtext ? rtext : text, size);
if (rtext != 0) if (rtext != 0)
delete rtext; delete[] rtext;
return r; return r;
} }
#endif // HAVE_ICONV #endif // HAVE_ICONV
@ -437,7 +436,7 @@ void Font::drawText(const FbDrawable &w, int screen, GC gc,
static bool first_run = true; static bool first_run = true;
#ifdef HAVE_ICONV #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); rtext = recode(m_iconv, text, len);
if (rtext != 0) { if (rtext != 0) {
len = strlen(rtext); 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); m_fontimp->drawText(w, screen, gc, real_text, len, x, y);
if (rtext != 0) if (rtext != 0)
delete rtext; delete[] rtext;
} }

View file

@ -50,6 +50,7 @@ public:
virtual unsigned int height() const = 0; virtual unsigned int height() const = 0;
virtual bool loaded() const = 0; virtual bool loaded() const = 0;
virtual void rotate(float angle) { } // by default, no rotate support virtual void rotate(float angle) { } // by default, no rotate support
virtual bool utf8() const { return false; };
protected: protected:
FontImp() { } FontImp() { }
}; };

View file

@ -42,6 +42,7 @@ public:
int ascent() const { return m_xftfont ? m_xftfont->ascent : 0; } int ascent() const { return m_xftfont ? m_xftfont->ascent : 0; }
int descent() const { return m_xftfont ? m_xftfont->descent : 0; } int descent() const { return m_xftfont ? m_xftfont->descent : 0; }
bool loaded() const { return m_xftfont != 0; } bool loaded() const { return m_xftfont != 0; }
bool utf8() const { return m_utf8mode; }
private: private:
XftFont *m_xftfont; XftFont *m_xftfont;
bool m_utf8mode; bool m_utf8mode;

View file

@ -110,7 +110,7 @@ const char *getFontElement(const char *pattern, char *buf, int bufsiz, ...) {
return 0; return 0;
} }
XFontSet createFontSet(const char *fontname, bool utf8mode) { XFontSet createFontSet(const char *fontname, bool& utf8mode) {
Display *display = FbTk::App::instance()->display(); Display *display = FbTk::App::instance()->display();
XFontSet fs; XFontSet fs;
const int FONT_ELEMENT_SIZE=50; const int FONT_ELEMENT_SIZE=50;
@ -192,13 +192,15 @@ XFontSet createFontSet(const char *fontname, bool utf8mode) {
setlocale(LC_CTYPE, orig_locale.c_str()); setlocale(LC_CTYPE, orig_locale.c_str());
#endif // HAVE_SETLOCALE #endif // HAVE_SETLOCALE
utf8mode = false;
return fs; return fs;
} }
}; };
namespace FbTk { 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) if (filename != 0)
load(filename); load(filename);
} }
@ -209,7 +211,7 @@ XmbFontImp::~XmbFontImp() {
} }
bool XmbFontImp::load(const std::string &fontname) { bool XmbFontImp::load(const std::string &fontname) {
if (fontname.size() == 0) if (fontname.empty())
return false; return false;
XFontSet set = createFontSet(fontname.c_str(), m_utf8mode); XFontSet set = createFontSet(fontname.c_str(), m_utf8mode);

View file

@ -42,10 +42,11 @@ public:
int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; } 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; } 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 loaded() const { return m_fontset != 0; }
bool utf8() const { return m_utf8mode; }
private: private:
XFontSet m_fontset; XFontSet m_fontset;
XFontSetExtents *m_setextents; XFontSetExtents *m_setextents;
const bool m_utf8mode; bool m_utf8mode;
}; };
} // end namespace FbTk } // end namespace FbTk