From 29e7776c34f7f389857a23c30cbbd122a0b54c8d Mon Sep 17 00:00:00 2001 From: John Spray Date: Tue, 14 Feb 2006 14:46:22 +0000 Subject: [PATCH] Remove broken multibyte stuff from GTK frontend, make single-byte stuff work properly. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13236 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/GPainter.C | 58 ++++++--------- src/frontends/gtk/GPainter.h | 14 +--- src/frontends/gtk/Makefile.am | 1 - src/frontends/gtk/codeConvert.h | 36 --------- src/frontends/gtk/xftFontMetrics.C | 115 ++++++----------------------- 5 files changed, 48 insertions(+), 176 deletions(-) delete mode 100644 src/frontends/gtk/codeConvert.h diff --git a/src/frontends/gtk/GPainter.C b/src/frontends/gtk/GPainter.C index 766742d5dd..6b0c19d714 100644 --- a/src/frontends/gtk/GPainter.C +++ b/src/frontends/gtk/GPainter.C @@ -29,7 +29,6 @@ #include "LColor.h" #include "xftFontLoader.h" #include "frontends/font_metrics.h" -#include "codeConvert.h" #include "support/lstrings.h" @@ -208,53 +207,40 @@ void GPainter::image(int x, int y, int w, int h, } -void GPainter::text(int x, int y, std::string const & s, LyXFont const & f) -{ - size_t size = s.length() + 1; - boost::scoped_array wcs(new wchar_t[size]); - size = mbstowcs(wcs.get(), s.c_str(), size); - return text(x, y, wcs.get(), size, f); -} - - -void GPainter::text(int x, int y, char c, LyXFont const & f) -{ - char s[2] = { c, '\0' }; - text(x, y, s, 1, f); -} - - inline XftFont * getXftFont(LyXFont const & f) { return fontLoader.load(f.family(), f.series(), - f.realShape(), f.size()); + f.realShape(), f.size()); } -void GPainter::text(int x, int y, wchar_t const * s, int ls, LyXFont const & f) +// ENCODING: we assume we've got 8-bit string in whatever format Xft +// wants. We should be finding out what the backend's giving us and +// then converting it before feeding it to Xft using XftDrawStringUtf8 +void GPainter::text(int x, int y, char const * s, size_t ls, LyXFont const & f) { XftFont * font = getXftFont(f); XftColor * xftClr = owner_.getColorHandler(). getXftColor(f.realColor()); XftDraw * draw = owner_.getXftDraw(); if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { - XftDrawString32(draw, xftClr, font, x, y, - wcsToXftChar32StrFast(s), ls); + XftDrawString8(draw, xftClr, font, x, y, + reinterpret_cast(const_cast(s)), ls); } else { LyXFont smallfont(f); smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); XftFont * fontS = getXftFont(smallfont); - wchar_t c; + char c; int tmpx = x; for (int i = 0; i < ls; ++i) { c = lyx::support::uppercase(s[i]); if (c != s[i]) { - XftDrawString32(draw, xftClr, fontS, tmpx, y, - wcsToXftChar32StrFast(&c), 1); + XftDrawString8(draw, xftClr, fontS, tmpx, y, + reinterpret_cast(const_cast(&c)), 1); tmpx += font_metrics::width(c, smallfont); } else { - XftDrawString32(draw, xftClr, font, tmpx, y, - wcsToXftChar32StrFast(&c), 1); + XftDrawString8(draw, xftClr, font, tmpx, y, + reinterpret_cast(const_cast(&c)), 1); tmpx += font_metrics::width(c, f); } } @@ -264,19 +250,17 @@ void GPainter::text(int x, int y, wchar_t const * s, int ls, LyXFont const & f) } -void GPainter::text(int x, int y, char const * s, size_t ls, LyXFont const & f) +void GPainter::text(int x, int y, std::string const & s, LyXFont const & f) { - boost::scoped_array wcs(new wchar_t[ls + 1]); - size_t len; - if (fontLoader.isSpecial(f)) { - unsigned char const * us = - reinterpret_cast(s); - len = ls; - std::copy(us, us + ls, wcs.get()); - } else - len = mbstowcs(wcs.get(), s, ls + 1); - text(x, y, wcs.get(), len, f); + text (x, y, s.c_str(), s.size(), f); } + +void GPainter::text(int x, int y, char c, LyXFont const & f) +{ + text (x, y, &c, 1, f); +} + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/gtk/GPainter.h b/src/frontends/gtk/GPainter.h index 7526994b36..87af62724b 100644 --- a/src/frontends/gtk/GPainter.h +++ b/src/frontends/gtk/GPainter.h @@ -107,26 +107,18 @@ public: virtual void text(int x, int y, std::string const & str, LyXFont const & f); - /** Draw a string at position x, y (y is the baseline) - * This is just for fast drawing - */ + /// draw a string at position x, y (y is the baseline) virtual void text(int x, int y, char const * str, size_t l, LyXFont const & f); - virtual void text(int x, int y, wchar_t const * str, int l, - LyXFont const & f); - /// draw a char at position x, y (y is the baseline) virtual void text(int x, int y, char c, LyXFont const & f); - /// draw a wide string at position x, y - void text(int x, int y, - XChar2b const * str, size_t l, - LyXFont const & f); - void start(); + + private: /// our owner who we paint upon diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index df95f5c7df..cb258093f9 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -133,7 +133,6 @@ libgtk_la_SOURCES = \ LyXKeySymFactory.C \ LyXScreenFactory.C \ WorkAreaFactory.C \ - codeConvert.h \ ghelpers.C \ ghelpers.h \ io_callback.C \ diff --git a/src/frontends/gtk/codeConvert.h b/src/frontends/gtk/codeConvert.h deleted file mode 100644 index bba08aae8f..0000000000 --- a/src/frontends/gtk/codeConvert.h +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -/** - * \file codeConvert.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Huang Ying - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef CODE_CONVERT_H -#define CODE_CONVERT_H - -#include - - -inline XftChar32 * wcsToXftChar32StrFast(wchar_t * wcs) -{ - return reinterpret_cast(wcs); -} - - -inline XftChar32 * wcsToXftChar32StrFast(wchar_t const * wcs) -{ - return reinterpret_cast(const_cast(wcs)); -} - - -inline XftChar32 wcToXftChar32(wchar_t wc) -{ - return static_cast(wc); -} - - -#endif diff --git a/src/frontends/gtk/xftFontMetrics.C b/src/frontends/gtk/xftFontMetrics.C index 694906c10b..d2a4a6a3e5 100644 --- a/src/frontends/gtk/xftFontMetrics.C +++ b/src/frontends/gtk/xftFontMetrics.C @@ -24,7 +24,6 @@ #include "lyxrc.h" #include "encoding.h" #include "language.h" -#include "codeConvert.h" #include "support/lstrings.h" #include "debug.h" @@ -77,17 +76,6 @@ inline int XGlyphLogWidth(XGlyphInfo const & info) return info.xOff; } - -wchar_t C2WC(char ch) -{ - wchar_t wcs[2] = {0, 0}; - char mbs[2] = {0, 0}; - mbs[0] = ch; - mbstowcs(wcs, mbs, 2); - return wcs[0]; -} - - } // namespace anon @@ -108,88 +96,61 @@ int maxDescent(LyXFont const & f) } -int ascent(wchar_t c,LyXFont const & f) +int ascent(char c,LyXFont const & f) { XftFont * font = getXftFont(f); XGlyphInfo glyph; - XftTextExtents32(getDisplay(), font, - wcsToXftChar32StrFast(&c), + XftTextExtents8(getDisplay(), font, + reinterpret_cast(&c), 1, &glyph); return XGlyphAscent(glyph); } -int ascent(char c, LyXFont const & f) -{ - return ascent(C2WC(c), f); -} - - -int descent(wchar_t c,LyXFont const & f) +int descent(char c,LyXFont const & f) { XftFont * font = getXftFont(f); XGlyphInfo glyph; - XftTextExtents32(getDisplay(), font, - wcsToXftChar32StrFast(&c), + XftTextExtents8(getDisplay(), font, + reinterpret_cast(&c), 1, &glyph); return XGlyphDescent(glyph); } -int descent(char c, LyXFont const & f) -{ - return descent(C2WC(c), f); -} - - -int lbearing(wchar_t c,LyXFont const & f) +int lbearing(char c,LyXFont const & f) { XftFont * font = getXftFont(f); XGlyphInfo glyph; - XftTextExtents32(getDisplay(), font, - wcsToXftChar32StrFast(&c), + XftTextExtents8(getDisplay(), font, + reinterpret_cast(&c), 1, &glyph); return XGlyphLbearing(glyph); } -int rbearing(wchar_t c,LyXFont const & f) +int rbearing(char c,LyXFont const & f) { XftFont * font = getXftFont(f); XGlyphInfo glyph; - XftTextExtents32(getDisplay(), font, - wcsToXftChar32StrFast(&c), + XftTextExtents8(getDisplay(), font, + reinterpret_cast(&c), 1, &glyph); return XGlyphRbearing(glyph); } -int lbearing(char c, LyXFont const & f) -{ - return lbearing(C2WC(c), f); -} - - -int rbearing(char c, LyXFont const & f) -{ - return rbearing(C2WC(c), f); -} - - -int width(wchar_t const * s, size_t n, LyXFont const & f) +int width(char const * s, size_t n, LyXFont const & f) { XftFont * font = getXftFont(f); XGlyphInfo glyph; if (f.realShape() != LyXFont::SMALLCAPS_SHAPE){ - XftTextExtents32(getDisplay(), font, - const_cast( - wcsToXftChar32StrFast(s)), - n, - &glyph); + XftTextExtents8(getDisplay(), font, + reinterpret_cast(const_cast(s)), n, &glyph); return XGlyphLogWidth(glyph); } else { int result = 0; @@ -197,16 +158,16 @@ int width(wchar_t const * s, size_t n, LyXFont const & f) smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); XftFont * fontS = getXftFont(smallfont); for (size_t i = 0; i < n; ++i) { - wchar_t wc = lyx::support::uppercase(s[i]); - if (wc != s[i]) { - XftTextExtents32(getDisplay(), fontS, - wcsToXftChar32StrFast(&wc), + char c = lyx::support::uppercase(s[i]); + if (c != s[i]) { + XftTextExtents8(getDisplay(), fontS, + reinterpret_cast(&c), 1, &glyph); result += XGlyphLogWidth(glyph); } else { - XftTextExtents32(getDisplay(), font, - wcsToXftChar32StrFast(&wc), + XftTextExtents8(getDisplay(), font, + reinterpret_cast(&c), 1, &glyph); result += XGlyphLogWidth(glyph); @@ -217,42 +178,14 @@ int width(wchar_t const * s, size_t n, LyXFont const & f) } -int width(wchar_t c,LyXFont const & f) -{ - return width(&c, 1, f); -} - - -int width(char const * s, size_t n, LyXFont const & f) -{ - boost::scoped_array wcs(new wchar_t[n]); - int len; // Signed to handle error retvals - if (fontLoader.isSpecial(f)) { - unsigned char const * us = - reinterpret_cast(s); - len = n; - std::copy(us, us + n, wcs.get()); - } else { - len = mbstowcs(wcs.get(), s, n); - if (len < 0) { - lyxerr[Debug::FONT] << "Invalid multibyte encoding! '" << s << "'\n"; - return n * width("0", 1, f); - } - } - return width(wcs.get(), static_cast(len), f); -} - - int signedWidth(string const & s, LyXFont const & f) { if (s.empty()) return 0; - boost::scoped_array wcs(new wchar_t[s.length() + 1]); - int len = mbstowcs(wcs.get(), s.c_str(), s.length()); - if (wcs[0] == '-') - return width(wcs.get() + 1, len - 1, f); + if (s[0] == '-') + return width(s.c_str() + 1, s.size() - 1, f); else - return width(wcs.get(), len, f); + return width(s.c_str(), s.size(), f); }