]> git.lyx.org Git - lyx.git/commitdiff
Unicode support
authorDekel Tsur <dekelts@tau.ac.il>
Tue, 15 Oct 2002 15:13:49 +0000 (15:13 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Tue, 15 Oct 2002 15:13:49 +0000 (15:13 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5414 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/QLPainter.C
src/frontends/qt2/QLPainter.h
src/frontends/qt2/qfont_metrics.C

index 0829e180729695d6309cdec3867631d7dd123006..0732b3c656ca85e2fb7f43a579d124cac2cb4cc8 100644 (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>
index 5056fedd4df0c111d61fc76a2f75f62e0155912e..471e00ed3c381f448d325b48b6960328d7a1d25e 100644 (file)
@@ -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) {
index 2410f4d60ad48eebd63a8c8ae090e8e4b5eaa752..5a3b8375b2382c5cc8d6a95d1222eba4594eb677 100644 (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,
index ff28fd424f0423e6c09102898bf9d0366739fd5c..57b65a2eb13a8bc202bfaa922ccd7f5d52bef9f3 100644 (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;
 }