mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
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
This commit is contained in:
parent
7bb1fa55ac
commit
29e7776c34
@ -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<wchar_t> 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<XftChar8 *>(const_cast<char *>(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<XftChar8 *>(const_cast<char *>(&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<XftChar8 *>(const_cast<char *>(&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<wchar_t> wcs(new wchar_t[ls + 1]);
|
||||
size_t len;
|
||||
if (fontLoader.isSpecial(f)) {
|
||||
unsigned char const * us =
|
||||
reinterpret_cast<unsigned char const *>(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
|
||||
|
@ -107,27 +107,19 @@ 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
|
||||
GWorkArea & owner_;
|
||||
|
@ -133,7 +133,6 @@ libgtk_la_SOURCES = \
|
||||
LyXKeySymFactory.C \
|
||||
LyXScreenFactory.C \
|
||||
WorkAreaFactory.C \
|
||||
codeConvert.h \
|
||||
ghelpers.C \
|
||||
ghelpers.h \
|
||||
io_callback.C \
|
||||
|
@ -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 <X11/Xft/Xft.h>
|
||||
|
||||
|
||||
inline XftChar32 * wcsToXftChar32StrFast(wchar_t * wcs)
|
||||
{
|
||||
return reinterpret_cast<XftChar32 *>(wcs);
|
||||
}
|
||||
|
||||
|
||||
inline XftChar32 * wcsToXftChar32StrFast(wchar_t const * wcs)
|
||||
{
|
||||
return reinterpret_cast<XftChar32 *>(const_cast<wchar_t *>(wcs));
|
||||
}
|
||||
|
||||
|
||||
inline XftChar32 wcToXftChar32(wchar_t wc)
|
||||
{
|
||||
return static_cast<XftChar32>(wc);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -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<XftChar8 *>(&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<XftChar8 *>(&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<XftChar8 *>(&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<XftChar8 *>(&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<XftChar32 *>(
|
||||
wcsToXftChar32StrFast(s)),
|
||||
n,
|
||||
&glyph);
|
||||
XftTextExtents8(getDisplay(), font,
|
||||
reinterpret_cast<XftChar8 *>(const_cast<char *>(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<XftChar8 *>(&c),
|
||||
1,
|
||||
&glyph);
|
||||
result += XGlyphLogWidth(glyph);
|
||||
} else {
|
||||
XftTextExtents32(getDisplay(), font,
|
||||
wcsToXftChar32StrFast(&wc),
|
||||
XftTextExtents8(getDisplay(), font,
|
||||
reinterpret_cast<XftChar8 *>(&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<wchar_t> wcs(new wchar_t[n]);
|
||||
int len; // Signed to handle error retvals
|
||||
if (fontLoader.isSpecial(f)) {
|
||||
unsigned char const * us =
|
||||
reinterpret_cast<unsigned char const *>(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<size_t>(len), f);
|
||||
}
|
||||
|
||||
|
||||
int signedWidth(string const & s, LyXFont const & f)
|
||||
{
|
||||
if (s.empty())
|
||||
return 0;
|
||||
boost::scoped_array<wchar_t> 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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user