utf-8 fix, a fixed patch from Sergey Kuleshov

This commit is contained in:
fluxgen 2004-08-10 11:57:35 +00:00
parent 52cb375886
commit 41249b77fb
2 changed files with 48 additions and 34 deletions

View file

@ -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) {
// check the string size,
// if the size is zero we use the XftDrawString8 function instead.
XGlyphInfo ginfo;
XftTextExtentsUtf8(App::instance()->display(),
m_xftfont,
(XftChar8 *)text, len,
&ginfo);
if (ginfo.xOff != 0) {
XftDrawStringUtf8(draw,
&xftcolor,
m_xftfont,
x, y,
(XftChar8 *)(text), len);
} else
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);
}
return ginfo.xOff;
}

View file

@ -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 = "<<utf8<<endl;
#else // X_HAVE_UTF8_STRING
cerr<<"Using uft8 = false"<<endl;
#endif //X_HAVE_UTF8_STRING
#endif // DEBUG
if (filename != 0)
load(filename);
}
@ -238,18 +231,19 @@ void XmbFontImp::drawText(Drawable w, int screen, GC gc, const char *text,
unsigned int XmbFontImp::textWidth(const char * const text, unsigned int len) const {
if (m_fontset == 0)
return 0;
XRectangle ink, logical;
#ifdef X_HAVE_UTF8_STRING
if (m_utf8mode) {
Xutf8TextExtents(m_fontset, text, len,
&ink, &logical);
} else
if (logical.width != 0)
return logical.width;
}
#endif // X_HAVE_UTF8_STRING
{
XmbTextExtents(m_fontset, text, len,
&ink, &logical);
}
return logical.width;
}