]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/QLPainter.C
Rename .C ==> .cpp for files in src/frontends/qt4, part one
[lyx.git] / src / frontends / qt4 / QLPainter.C
index 34f856731dfa7ae782f76dba745ea78bc321629d..8bec6aecec3254be5f2e025fbe9e56453fb7f4d4 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file QLPainter.C
+ * \file QLPainter.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
@@ -11,6 +11,8 @@
 
 #include <config.h>
 
+#include <QTextLayout>
+
 #include "QLPainter.h"
 
 #include "GuiApplication.h"
@@ -96,7 +98,9 @@ void QLPainter::line(int x1, int y1, int x2, int y2,
                return;
 
        setQPainterPen(col, ls, lw);
+       setRenderHint(Antialiasing, x1 != x2 && y1 != y2);
        drawLine(x1, y1, x2, y2);
+       setRenderHint(Antialiasing, false);
 }
 
 
@@ -110,16 +114,21 @@ void QLPainter::lines(int const * xp, int const * yp, int np,
        // Must use new as np is not known at compile time.
        boost::scoped_array<QPoint> points(new QPoint[np]);
 
+       bool antialias = false;
        for (int i = 0; i < np; ++i) {
                points[i].setX(xp[i]);
                points[i].setY(yp[i]);
+               if (i != 0) 
+                       antialias |= xp[i-1] != xp[i] && yp[i-1] != yp[i];
        }
 
        if (!isDrawingEnabled())
                return;
 
        setQPainterPen(col, ls, lw);
+       setRenderHint(Antialiasing, antialias);
        drawPolyline(points.get(), np);
+       setRenderHint(Antialiasing, false);
 }
 
 
@@ -150,7 +159,9 @@ void QLPainter::arc(int x, int y, unsigned int w, unsigned int h,
 
        // LyX usings 1/64ths degree, Qt usings 1/16th
        setQPainterPen(col);
+       setRenderHint(Antialiasing, true);
        drawArc(x, y, w, h, a1 / 4, a2 / 4);
+       setRenderHint(Antialiasing, false);
 }
 
 
@@ -168,16 +179,10 @@ void QLPainter::image(int x, int y, int w, int h, graphics::Image const & i)
 }
 
 
-int QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
-{
-        return text(x, y, reinterpret_cast<char_type const *>(s.data()), s.length(), f);
-}
-
-
 int QLPainter::text(int x, int y, char_type c, LyXFont const & f)
 {
-       char_type s[2] = { c, char_type('\0') };
-       return text(x, y, s, 1, f);
+       docstring s(1, c);
+       return text(x, y, s, f);
 }
 
 
@@ -208,17 +213,21 @@ int QLPainter::smallCapsText(int x, int y,
 }
 
 
-int QLPainter::text(int x, int y, char_type const * s, size_t ls,
-       LyXFont const & f)
+int QLPainter::text(int x, int y, docstring const & s,
+               LyXFont const & f)
 {
-#if 0
-       Encoding const * encoding = f.language()->encoding();
-       if (f.isSymbolFont())
-               encoding = encodings.symbol_encoding();
-#endif
-
-       QString str;
-       ucs4_to_qstring(s, ls, str);
+       /* Caution: The following ucs4 to QString conversions work for symbol fonts
+       only because they are no real conversions but simple casts in reality.
+       When we want to draw a symbol or calculate the metrics we pass the position
+       of the symbol in the font (as given in lib/symbols) as a char_type to the
+       frontend. This is just wrong, because the symbol is no UCS4 character at
+       all. You can think of this number as the code point of the symbol in a
+       custom symbol encoding. It works because this char_type is lateron again
+       interpreted as a position in the font again.
+       The correct solution would be to have extra functions for symbols, but that
+       would require to duplicate a lot of frontend and mathed support code.
+       */
+       QString str = toqstr(s);
 
 #if 0
        // HACK: QT3 refuses to show single compose characters
@@ -238,8 +247,23 @@ int QLPainter::text(int x, int y, char_type const * s, size_t ls,
                // We need to draw the text as LTR as we use our own bidi code.
                setLayoutDirection(Qt::LeftToRight);
                if (isDrawingEnabled()) {
-                       lyxerr << "draw " << std::string(str.toUtf8()) << " at " << x << "," << y << std::endl;
-                       drawText(x, y, str);
+                       LYXERR(Debug::PAINTING) << "draw " << std::string(str.toUtf8())
+                               << " at " << x << "," << y << std::endl;
+                       // Qt4 does not display a glyph whose codepoint is the
+                       // same as that of a soft-hyphen (0x00ad), unless it
+                       // occurs at a line-break. As a kludge, we force Qt to
+                       // render this glyph using a one-column line.
+                       if (s.size() == 1 && str[0].unicode() == 0x00ad) {
+                               QTextLayout adsymbol(str);
+                               adsymbol.setFont(fi.font);
+                               adsymbol.beginLayout();
+                               QTextLine line = adsymbol.createLine();
+                               line.setNumColumns(1);
+                               line.setPosition(QPointF(0, -line.ascent()));
+                               adsymbol.endLayout();
+                               line.draw(this, QPointF(x, y));
+                       } else
+                               drawText(x, y, str);
                }
                // Here we use the font width cache instead of
                //   textwidth = fontMetrics().width(str);
@@ -259,3 +283,4 @@ int QLPainter::text(int x, int y, char_type const * s, size_t ls,
 
 } // namespace frontend
 } // namespace lyx
+