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:
parent
993c17cf2e
commit
66a3fc1c4d
5 changed files with 22 additions and 18 deletions
|
@ -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'."<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_antialias = flag;
|
||||
}
|
||||
|
||||
|
@ -400,13 +399,13 @@ bool Font::load(const std::string &name) {
|
|||
|
||||
unsigned int Font::textWidth(const char * const text, unsigned int size) const {
|
||||
#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);
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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() { }
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue