From 73176d2922baae1ccaa702e4900b0473071d0a96 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 3 Jul 2017 11:30:43 +0200 Subject: Add API to disable text shaping on fonts In the past, we had an undocumented text flag that worked with one of the QPainter::drawText() overloads. This was never intended as public API and served a specific cause in Qt WebKit at one point. But there is a general need for such API, as disabling shaping features easily gives 25% performance improvement on text rendering even for fairly short strings. This patch adds a new style strategy flag to disable shaping and will just uses the CMAP and HDMX tables to get glyph indices and advances for the characters. In Qt 6, the TextBypassShaping flag can be removed completely and be replaced by the style strategy. [ChangeLog][QtGui][Text] Added QFont::PreferNoShaping style strategy to support improvements to performance at the expense of some cosmetic font features. Task-number: QTBUG-56728 Change-Id: I48e025dcc06afe02824bf5b5011702a7e0036f6d Reviewed-by: Simon Hausmann --- .../gui/text/qfontmetrics/tst_qfontmetrics.cpp | 6 +++ .../qtextscriptengine/tst_qtextscriptengine.cpp | 60 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index 8667caa1ef..0a422fca17 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -47,7 +47,11 @@ private slots: void elidedText(); void veryNarrowElidedText(); void averageCharWidth(); + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void bypassShaping(); +#endif + void elidedMultiLength(); void elidedMultiLengthF(); void inFontUcs4(); @@ -187,6 +191,7 @@ void tst_QFontMetrics::averageCharWidth() QVERIFY(fmf.averageCharWidth() != 0); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void tst_QFontMetrics::bypassShaping() { QFont f; @@ -201,6 +206,7 @@ void tst_QFontMetrics::bypassShaping() // This assertion is needed in Qt WebKit's WebCore::Font::offsetForPositionForSimpleText QCOMPARE(textWidth, charsWidth); } +#endif template void elidedMultiLength_helper() { diff --git a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp index ee50b98733..0371f51961 100644 --- a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp +++ b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp @@ -78,6 +78,9 @@ private slots: void thaiIsolatedSaraAm(); void thaiWithZWJ(); void thaiMultipleVowels(); + + void shapingDisabledDevanagari(); + void shapingDisabledLatin(); private: bool haveTestFonts; }; @@ -1280,5 +1283,62 @@ void tst_QTextScriptEngine::thaiMultipleVowels() // If we haven't crashed at this point, then the test has passed. } +void tst_QTextScriptEngine::shapingDisabledLatin() +{ + QString s("fi"); + + QFont font("Calibri"); + font.setStyleStrategy(QFont::PreferNoShaping); + + QTextLayout layout(s); + layout.setFont(font); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList runs = layout.glyphRuns(); + + QCOMPARE(runs.size(), 1); + QCOMPARE(runs.first().glyphIndexes().size(), 2); +} + +void tst_QTextScriptEngine::shapingDisabledDevanagari() +{ + QString s; + s += QChar(0x0915); // KA + s += QChar(0x094D); // VIRAMA + s += QChar(0x0915); // KA + + + QList normalRuns; + { + QTextLayout layout(s); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + normalRuns = layout.glyphRuns(); + } + + QFont font; + font.setStyleStrategy(QFont::PreferNoShaping); + + QList noShapingRuns; + { + QTextLayout layout(s); + layout.setFont(font); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + noShapingRuns = layout.glyphRuns(); + } + + // Even though shaping is disabled, Devanagari requires it, so the flag should be ignored. + QCOMPARE(normalRuns.size(), 1); + QCOMPARE(noShapingRuns.size(), 1); + QCOMPARE(noShapingRuns.first().glyphIndexes().size(), normalRuns.first().glyphIndexes().size()); +} + QTEST_MAIN(tst_QTextScriptEngine) #include "tst_qtextscriptengine.moc" -- cgit v1.2.3