From 41249b77fb4db6041d53447ffdb49bfb4dd34ce8 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Tue, 10 Aug 2004 11:57:35 +0000 Subject: utf-8 fix, a fixed patch from Sergey Kuleshov --- src/FbTk/XftFontImp.cc | 62 +++++++++++++++++++++++++++++++++----------------- src/FbTk/XmbFontImp.cc | 20 ++++++---------- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/FbTk/XftFontImp.cc b/src/FbTk/XftFontImp.cc index 59f8440..c698238 100644 --- a/src/FbTk/XftFontImp.cc +++ b/src/FbTk/XftFontImp.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//$Id: XftFontImp.cc,v 1.2 2002/12/01 13:42:15 rathnor Exp $ +//$Id: XftFontImp.cc,v 1.3 2004/08/10 11:57:35 fluxgen Exp $ #include "XftFontImp.hh" #include "App.hh" @@ -27,6 +27,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif //HAVE_CONFIG_H + namespace FbTk { XftFontImp::XftFontImp(const char *name, bool utf8):m_xftfont(0), @@ -93,20 +94,33 @@ void XftFontImp::drawText(Drawable w, int screen, GC gc, const char *text, size_ // draw string #ifdef HAVE_XFT_UTF8_STRING if (m_utf8mode) { - XftDrawStringUtf8(draw, - &xftcolor, - m_xftfont, - x, y, - (XftChar8 *)(text), len); - } else -#endif // HAVE_XFT_UTF8_STRING - { - XftDrawString8(draw, - &xftcolor, + // check the string size, + // if the size is zero we use the XftDrawString8 function instead. + XGlyphInfo ginfo; + XftTextExtentsUtf8(App::instance()->display(), m_xftfont, - x, y, - (XftChar8 *)(text), len); - } + (XftChar8 *)text, len, + &ginfo); + if (ginfo.xOff != 0) { + XftDrawStringUtf8(draw, + &xftcolor, + m_xftfont, + x, y, + (XftChar8 *)(text), len); + XftColorFree(disp, DefaultVisual(disp, screen), + DefaultColormap(disp, screen), &xftcolor); + XftDrawDestroy(draw); + return; + } + } +#endif // HAVE_XFT_UTF8_STRING + + XftDrawString8(draw, + &xftcolor, + m_xftfont, + x, y, + (XftChar8 *)(text), len); + XftColorFree(disp, DefaultVisual(disp, screen), DefaultColormap(disp, screen), &xftcolor); @@ -116,21 +130,27 @@ void XftFontImp::drawText(Drawable w, int screen, GC gc, const char *text, size_ unsigned int XftFontImp::textWidth(const char * const text, unsigned int len) const { if (m_xftfont == 0) return 0; + XGlyphInfo ginfo; + #ifdef HAVE_XFT_UTF8_STRING if (m_utf8mode) { XftTextExtentsUtf8(App::instance()->display(), m_xftfont, (XftChar8 *)text, len, &ginfo); - } else + if (ginfo.xOff != 0) + return ginfo.xOff; + + // the utf8 failed, try normal extents + } #endif //HAVE_XFT_UTF8_STRING - { - XftTextExtents8(App::instance()->display(), - m_xftfont, - (XftChar8 *)text, len, - &ginfo); - } + + XftTextExtents8(App::instance()->display(), + m_xftfont, + (XftChar8 *)text, len, + &ginfo); + return ginfo.xOff; } diff --git a/src/FbTk/XmbFontImp.cc b/src/FbTk/XmbFontImp.cc index 9f47d6e..d06f05d 100644 --- a/src/FbTk/XmbFontImp.cc +++ b/src/FbTk/XmbFontImp.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: XmbFontImp.cc,v 1.7 2004/02/10 19:03:42 fluxgen Exp $ +// $Id: XmbFontImp.cc,v 1.8 2004/08/10 11:57:35 fluxgen Exp $ #include "XmbFontImp.hh" @@ -186,13 +186,6 @@ XFontSet createFontSet(const char *fontname) { namespace FbTk { XmbFontImp::XmbFontImp(const char *filename, bool utf8):m_fontset(0), m_utf8mode(utf8) { -#ifdef DEBUG -#ifdef X_HAVE_UTF8_STRING - cerr<<"Using utf8 = "<