Unicode support

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5414 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Dekel Tsur 2002-10-15 15:13:49 +00:00
parent 855925c969
commit be90eb4453
4 changed files with 54 additions and 17 deletions

View File

@ -1,5 +1,8 @@
2002-10-15 Dekel Tsur <dekelts@tau.ac.il>
* QLPainter.C (text): Unicode support.
* qfont_metrics.C (width): ditto.
* qfont_loader.C (available): Add code for QT 2.x.
2002-10-14 Dekel Tsur <dekelts@tau.ac.il>

View File

@ -22,6 +22,8 @@
#include "lyxrc.h"
#include "debug.h"
#include "LyXView.h"
#include "encoding.h"
#include "language.h"
#include "QWorkArea.h"
#include "qfont_loader.h"
@ -217,8 +219,7 @@ Painter & QLPainter::text(int x, int y,
void QLPainter::smallCapsText(int x, int y,
char const * s, size_t ls,
LyXFont const & f)
QString const & s, LyXFont const & f)
{
LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
@ -229,16 +230,17 @@ void QLPainter::smallCapsText(int x, int y,
QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
int tmpx = x;
size_t ls = s.length();
for (size_t i = 0; i < ls; ++i) {
char const c = uppercase(s[i]);
QChar const c = s[i].upper();
if (c != s[i]) {
qp_->setFont(qsmallfont);
qp_->drawText(tmpx, y, &c, 1);
tmpx += qsmallfontm.width(&c, 1);
qp_->drawText(tmpx, y, c);
tmpx += qsmallfontm.width(c);
} else {
qp_->setFont(qfont);
qp_->drawText(tmpx, y, &c, 1);
tmpx += qfontm.width(&c, 1);
qp_->drawText(tmpx, y, c);
tmpx += qfontm.width(c);
}
}
}
@ -250,11 +252,32 @@ Painter & QLPainter::text(int x, int y,
{
setPen(f.color());
Encoding const * encoding = f.language()->encoding();
if (f.isSymbolFont())
encoding = encodings.symbol_encoding();
QString str;
str.setLength(ls);
for (size_t i = 0; i < ls; ++i)
str[i] = QChar(encoding->ucs(s[i]));
#if QT_VERSION >= 0x030000
// HACK: QT3 refuses to show single compose characters
if (ls = 1 && str[0].unicode() >= 0x05b0 && str[0].unicode() <= 0x05c2)
str = ' '+str;
#endif
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
qp_->setFont(fontloader.get(f));
qp_->drawText(x, y, s, ls);
#if QT_VERSION >= 0x030000
// We need to draw the text as LTR as we use our own bidi
// code.
qp_->drawText(x, y, str, -1, QPainter::LTR);
#else
qp_->drawText(x, y, str);
#endif
} else {
smallCapsText(x, y, s, ls, f);
smallCapsText(x, y, str, f);
}
if (f.underbar() == LyXFont::ON) {

View File

@ -25,6 +25,7 @@
class LyXFont;
class QWorkArea;
class QPainter;
class QString;
/**
* QLPainter - a painter implementation for Xlib
@ -122,8 +123,7 @@ public:
private:
/// draw small caps text
void smallCapsText(int x, int y,
char const * str, size_t l,
LyXFont const & f);
QString const & str, LyXFont const & f);
/// set pen parameters
QPainter & setPen(LColor::color c,

View File

@ -20,6 +20,8 @@
#include "font_metrics.h"
#include "qfont_loader.h"
#include "debug.h"
#include "encoding.h"
#include "language.h"
#include <qfontmetrics.h>
#include <qfont.h>
@ -78,8 +80,17 @@ int rbearing(char c, LyXFont const & f)
int width(char const * s, size_t ls, LyXFont const & f)
{
Encoding const * encoding = f.language()->encoding();
if (f.isSymbolFont())
encoding = encodings.symbol_encoding();
QString str;
str.setLength(ls);
for (size_t i = 0; i < ls; ++i)
str[i] = QChar(encoding->ucs(s[i]));
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
return metrics(f).width(s, ls);
return metrics(f).width(str);
}
// handle small caps ourselves ...
@ -93,11 +104,11 @@ int width(char const * s, size_t ls, LyXFont const & f)
int w = 0;
for (size_t i = 0; i < ls; ++i) {
char const c = uppercase(s[i]);
if (c != s[i])
w += qsmallm.width(&c, 1);
QChar const c = str[i].upper();
if (c != str[i])
w += qsmallm.width(c);
else
w += qm.width(&c, 1);
w += qm.width(c);
}
return w;
}