mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 05:01:49 +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 "LColor.h"
|
||||||
#include "xftFontLoader.h"
|
#include "xftFontLoader.h"
|
||||||
#include "frontends/font_metrics.h"
|
#include "frontends/font_metrics.h"
|
||||||
#include "codeConvert.h"
|
|
||||||
|
|
||||||
#include "support/lstrings.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)
|
inline XftFont * getXftFont(LyXFont const & f)
|
||||||
{
|
{
|
||||||
return fontLoader.load(f.family(), f.series(),
|
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);
|
XftFont * font = getXftFont(f);
|
||||||
XftColor * xftClr = owner_.getColorHandler().
|
XftColor * xftClr = owner_.getColorHandler().
|
||||||
getXftColor(f.realColor());
|
getXftColor(f.realColor());
|
||||||
XftDraw * draw = owner_.getXftDraw();
|
XftDraw * draw = owner_.getXftDraw();
|
||||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
||||||
XftDrawString32(draw, xftClr, font, x, y,
|
XftDrawString8(draw, xftClr, font, x, y,
|
||||||
wcsToXftChar32StrFast(s), ls);
|
reinterpret_cast<XftChar8 *>(const_cast<char *>(s)), ls);
|
||||||
} else {
|
} else {
|
||||||
LyXFont smallfont(f);
|
LyXFont smallfont(f);
|
||||||
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
||||||
XftFont * fontS = getXftFont(smallfont);
|
XftFont * fontS = getXftFont(smallfont);
|
||||||
wchar_t c;
|
char c;
|
||||||
int tmpx = x;
|
int tmpx = x;
|
||||||
for (int i = 0; i < ls; ++i) {
|
for (int i = 0; i < ls; ++i) {
|
||||||
c = lyx::support::uppercase(s[i]);
|
c = lyx::support::uppercase(s[i]);
|
||||||
if (c != s[i]) {
|
if (c != s[i]) {
|
||||||
XftDrawString32(draw, xftClr, fontS, tmpx, y,
|
XftDrawString8(draw, xftClr, fontS, tmpx, y,
|
||||||
wcsToXftChar32StrFast(&c), 1);
|
reinterpret_cast<XftChar8 *>(const_cast<char *>(&c)), 1);
|
||||||
tmpx += font_metrics::width(c, smallfont);
|
tmpx += font_metrics::width(c, smallfont);
|
||||||
} else {
|
} else {
|
||||||
XftDrawString32(draw, xftClr, font, tmpx, y,
|
XftDrawString8(draw, xftClr, font, tmpx, y,
|
||||||
wcsToXftChar32StrFast(&c), 1);
|
reinterpret_cast<XftChar8 *>(const_cast<char *>(&c)), 1);
|
||||||
tmpx += font_metrics::width(c, f);
|
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]);
|
text (x, y, s.c_str(), s.size(), f);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GPainter::text(int x, int y, char c, LyXFont const & f)
|
||||||
|
{
|
||||||
|
text (x, y, &c, 1, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -107,26 +107,18 @@ public:
|
|||||||
virtual void text(int x, int y,
|
virtual void text(int x, int y,
|
||||||
std::string const & str, LyXFont const & f);
|
std::string const & str, LyXFont const & f);
|
||||||
|
|
||||||
/** Draw a string at position x, y (y is the baseline)
|
/// draw a string at position x, y (y is the baseline)
|
||||||
* This is just for fast drawing
|
|
||||||
*/
|
|
||||||
virtual void text(int x, int y,
|
virtual void text(int x, int y,
|
||||||
char const * str, size_t l,
|
char const * str, size_t l,
|
||||||
LyXFont const & f);
|
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)
|
/// draw a char at position x, y (y is the baseline)
|
||||||
virtual void text(int x, int y,
|
virtual void text(int x, int y,
|
||||||
char c, LyXFont const & f);
|
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();
|
void start();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// our owner who we paint upon
|
/// our owner who we paint upon
|
||||||
|
@ -133,7 +133,6 @@ libgtk_la_SOURCES = \
|
|||||||
LyXKeySymFactory.C \
|
LyXKeySymFactory.C \
|
||||||
LyXScreenFactory.C \
|
LyXScreenFactory.C \
|
||||||
WorkAreaFactory.C \
|
WorkAreaFactory.C \
|
||||||
codeConvert.h \
|
|
||||||
ghelpers.C \
|
ghelpers.C \
|
||||||
ghelpers.h \
|
ghelpers.h \
|
||||||
io_callback.C \
|
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 "lyxrc.h"
|
||||||
#include "encoding.h"
|
#include "encoding.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
#include "codeConvert.h"
|
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
@ -77,17 +76,6 @@ inline int XGlyphLogWidth(XGlyphInfo const & info)
|
|||||||
return info.xOff;
|
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
|
} // 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);
|
XftFont * font = getXftFont(f);
|
||||||
XGlyphInfo glyph;
|
XGlyphInfo glyph;
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents8(getDisplay(), font,
|
||||||
wcsToXftChar32StrFast(&c),
|
reinterpret_cast<XftChar8 *>(&c),
|
||||||
1,
|
1,
|
||||||
&glyph);
|
&glyph);
|
||||||
return XGlyphAscent(glyph);
|
return XGlyphAscent(glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ascent(char c, LyXFont const & f)
|
int descent(char c,LyXFont const & f)
|
||||||
{
|
|
||||||
return ascent(C2WC(c), f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int descent(wchar_t c,LyXFont const & f)
|
|
||||||
{
|
{
|
||||||
XftFont * font = getXftFont(f);
|
XftFont * font = getXftFont(f);
|
||||||
XGlyphInfo glyph;
|
XGlyphInfo glyph;
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents8(getDisplay(), font,
|
||||||
wcsToXftChar32StrFast(&c),
|
reinterpret_cast<XftChar8 *>(&c),
|
||||||
1,
|
1,
|
||||||
&glyph);
|
&glyph);
|
||||||
return XGlyphDescent(glyph);
|
return XGlyphDescent(glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int descent(char c, LyXFont const & f)
|
int lbearing(char c,LyXFont const & f)
|
||||||
{
|
|
||||||
return descent(C2WC(c), f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int lbearing(wchar_t c,LyXFont const & f)
|
|
||||||
{
|
{
|
||||||
XftFont * font = getXftFont(f);
|
XftFont * font = getXftFont(f);
|
||||||
XGlyphInfo glyph;
|
XGlyphInfo glyph;
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents8(getDisplay(), font,
|
||||||
wcsToXftChar32StrFast(&c),
|
reinterpret_cast<XftChar8 *>(&c),
|
||||||
1,
|
1,
|
||||||
&glyph);
|
&glyph);
|
||||||
return XGlyphLbearing(glyph);
|
return XGlyphLbearing(glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int rbearing(wchar_t c,LyXFont const & f)
|
int rbearing(char c,LyXFont const & f)
|
||||||
{
|
{
|
||||||
XftFont * font = getXftFont(f);
|
XftFont * font = getXftFont(f);
|
||||||
XGlyphInfo glyph;
|
XGlyphInfo glyph;
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents8(getDisplay(), font,
|
||||||
wcsToXftChar32StrFast(&c),
|
reinterpret_cast<XftChar8 *>(&c),
|
||||||
1,
|
1,
|
||||||
&glyph);
|
&glyph);
|
||||||
return XGlyphRbearing(glyph);
|
return XGlyphRbearing(glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lbearing(char c, LyXFont const & f)
|
int width(char const * s, size_t n, 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)
|
|
||||||
{
|
{
|
||||||
XftFont * font = getXftFont(f);
|
XftFont * font = getXftFont(f);
|
||||||
XGlyphInfo glyph;
|
XGlyphInfo glyph;
|
||||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE){
|
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE){
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents8(getDisplay(), font,
|
||||||
const_cast<XftChar32 *>(
|
reinterpret_cast<XftChar8 *>(const_cast<char *>(s)), n, &glyph);
|
||||||
wcsToXftChar32StrFast(s)),
|
|
||||||
n,
|
|
||||||
&glyph);
|
|
||||||
return XGlyphLogWidth(glyph);
|
return XGlyphLogWidth(glyph);
|
||||||
} else {
|
} else {
|
||||||
int result = 0;
|
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);
|
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
||||||
XftFont * fontS = getXftFont(smallfont);
|
XftFont * fontS = getXftFont(smallfont);
|
||||||
for (size_t i = 0; i < n; ++i) {
|
for (size_t i = 0; i < n; ++i) {
|
||||||
wchar_t wc = lyx::support::uppercase(s[i]);
|
char c = lyx::support::uppercase(s[i]);
|
||||||
if (wc != s[i]) {
|
if (c != s[i]) {
|
||||||
XftTextExtents32(getDisplay(), fontS,
|
XftTextExtents8(getDisplay(), fontS,
|
||||||
wcsToXftChar32StrFast(&wc),
|
reinterpret_cast<XftChar8 *>(&c),
|
||||||
1,
|
1,
|
||||||
&glyph);
|
&glyph);
|
||||||
result += XGlyphLogWidth(glyph);
|
result += XGlyphLogWidth(glyph);
|
||||||
} else {
|
} else {
|
||||||
XftTextExtents32(getDisplay(), font,
|
XftTextExtents8(getDisplay(), font,
|
||||||
wcsToXftChar32StrFast(&wc),
|
reinterpret_cast<XftChar8 *>(&c),
|
||||||
1,
|
1,
|
||||||
&glyph);
|
&glyph);
|
||||||
result += XGlyphLogWidth(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)
|
int signedWidth(string const & s, LyXFont const & f)
|
||||||
{
|
{
|
||||||
if (s.empty())
|
if (s.empty())
|
||||||
return 0;
|
return 0;
|
||||||
boost::scoped_array<wchar_t> wcs(new wchar_t[s.length() + 1]);
|
if (s[0] == '-')
|
||||||
int len = mbstowcs(wcs.get(), s.c_str(), s.length());
|
return width(s.c_str() + 1, s.size() - 1, f);
|
||||||
if (wcs[0] == '-')
|
|
||||||
return width(wcs.get() + 1, len - 1, f);
|
|
||||||
else
|
else
|
||||||
return width(wcs.get(), len, f);
|
return width(s.c_str(), s.size(), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user