/**
- * \file QLPainter.C
+ * \file QLPainter.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
#include <config.h>
+#include <QTextLayout>
+
#include "QLPainter.h"
#include "GuiApplication.h"
return;
setQPainterPen(col, ls, lw);
+ setRenderHint(Antialiasing, x1 != x2 && y1 != y2);
drawLine(x1, y1, x2, y2);
+ setRenderHint(Antialiasing, false);
}
// 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);
}
// 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);
}
}
-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);
}
}
-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
// 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);
} // namespace frontend
} // namespace lyx
+