From 81856e8b008099e39465543c3e85049380256cbb Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 13 Jul 2010 16:47:26 +0200 Subject: Support RTL text in QGlyphs RTL text would be positioned wrong with QGlyphs, as we would not correctly detect the direction of the text and pass it into getGlyphPositions(). The bidi analysis is the same as in the QTextLine::draw() method. Reviewed-by: Kim --- src/gui/text/qtextlayout.cpp | 5 +++- tests/auto/qglyphs/tst_qglyphs.cpp | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 4dda114..43900c0 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2228,6 +2228,8 @@ QList QTextLine::glyphs() const flags |= QTextItem::Underline; if (font.strikeOut()) flags |= QTextItem::StrikeOut; + if (si.analysis.bidiLevel % 2) + flags |= QTextItem::RightToLeft; QGlyphLayout glyphLayout = eng->shapedGlyphs(&si).mid(iterator.glyphsStart, iterator.glyphsEnd - iterator.glyphsStart); @@ -2285,7 +2287,8 @@ QList QTextLine::glyphs() const QVarLengthArray glyphsArray; QVarLengthArray positionsArray; - fontEngine->getGlyphPositions(glyphLayout, QTransform(), 0, glyphsArray, positionsArray); + fontEngine->getGlyphPositions(glyphLayout, QTransform(), flags, glyphsArray, + positionsArray); Q_ASSERT(glyphsArray.size() == positionsArray.size()); QVector glyphs; diff --git a/tests/auto/qglyphs/tst_qglyphs.cpp b/tests/auto/qglyphs/tst_qglyphs.cpp index 6827b23..b75e801 100644 --- a/tests/auto/qglyphs/tst_qglyphs.cpp +++ b/tests/auto/qglyphs/tst_qglyphs.cpp @@ -69,6 +69,7 @@ private slots: void drawStruckOutText(); void drawOverlinedText(); void drawUnderlinedText(); + void drawRightToLeft(); void detach(); private: @@ -527,6 +528,54 @@ void tst_QGlyphs::drawUnderlinedText() QCOMPARE(textLayoutDraw, drawGlyphs); } +void tst_QGlyphs::drawRightToLeft() +{ +#if defined(Q_WS_MAC) + QSKIP("Unstable because of QTBUG-11145", SkipAll); +#endif + + QString s; + s.append(QChar(1575)); + s.append(QChar(1578)); + + QPixmap textLayoutDraw(1000, 1000); + QPixmap drawGlyphs(1000, 1000); + + textLayoutDraw.fill(Qt::white); + drawGlyphs.fill(Qt::white); + + QFont font; + font.setUnderline(true); + + QTextLayout layout(s); + layout.setFont(font); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QPainter p(&textLayoutDraw); + layout.draw(&p, QPointF(50, 50)); + } + + QGlyphs glyphs = layout.glyphs().size() > 0 + ? layout.glyphs().at(0) + : QGlyphs(); + + { + QPainter p(&drawGlyphs); + p.drawGlyphs(QPointF(50, 50), glyphs); + } + +#if defined(DEBUG_SAVE_IMAGE) + textLayoutDraw.save("drawRightToLeft_textLayoutDraw.png"); + drawGlyphs.save("drawRightToLeft_drawGlyphIndexes.png"); +#endif + + QCOMPARE(textLayoutDraw, drawGlyphs); + +} + QTEST_MAIN(tst_QGlyphs) #include "tst_qglyphs.moc" -- cgit v0.12