From be90eb44530ffe41e1551e6c17ce8363eb1951d7 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Tue, 15 Oct 2002 15:13:49 +0000 Subject: [PATCH] Unicode support git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5414 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 3 +++ src/frontends/qt2/QLPainter.C | 43 ++++++++++++++++++++++++------- src/frontends/qt2/QLPainter.h | 4 +-- src/frontends/qt2/qfont_metrics.C | 21 +++++++++++---- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0829e18072..0732b3c656 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,5 +1,8 @@ 2002-10-15 Dekel Tsur + * 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 diff --git a/src/frontends/qt2/QLPainter.C b/src/frontends/qt2/QLPainter.C index 5056fedd4d..471e00ed3c 100644 --- a/src/frontends/qt2/QLPainter.C +++ b/src/frontends/qt2/QLPainter.C @@ -22,7 +22,9 @@ #include "lyxrc.h" #include "debug.h" #include "LyXView.h" - +#include "encoding.h" +#include "language.h" + #include "QWorkArea.h" #include "qfont_loader.h" #include "QLPainter.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) { diff --git a/src/frontends/qt2/QLPainter.h b/src/frontends/qt2/QLPainter.h index 2410f4d60a..5a3b8375b2 100644 --- a/src/frontends/qt2/QLPainter.h +++ b/src/frontends/qt2/QLPainter.h @@ -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, diff --git a/src/frontends/qt2/qfont_metrics.C b/src/frontends/qt2/qfont_metrics.C index ff28fd424f..57b65a2eb1 100644 --- a/src/frontends/qt2/qfont_metrics.C +++ b/src/frontends/qt2/qfont_metrics.C @@ -20,6 +20,8 @@ #include "font_metrics.h" #include "qfont_loader.h" #include "debug.h" +#include "encoding.h" +#include "language.h" #include #include @@ -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; }