diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 403a0510fa..2ed0f21d3e 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -663,6 +663,9 @@ glyph_metrics_t QFontEngine::tightBoundingBox(const QGlyphLayout &glyphs) QFixed ymax = 0; QFixed xmax = 0; for (int i = 0; i < glyphs.numGlyphs; i++) { + // If shaping has found this should be ignored, ignore it. + if (!glyphs.advances[i] || glyphs.attributes[i].dontPrint) + continue; glyph_metrics_t bb = boundingBox(glyphs.glyphs[i]); QFixed x = overall.xoff + glyphs.offsets[i].x + bb.x; QFixed y = overall.yoff + glyphs.offsets[i].y + bb.y; diff --git a/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp b/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp index 8c6cc8fbc1..d176f60d10 100644 --- a/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp +++ b/src/platformsupport/fontdatabases/freetype/qfontengine_ft.cpp @@ -1672,6 +1672,9 @@ glyph_metrics_t QFontEngineFT::boundingBox(const QGlyphLayout &glyphs) QFixed ymax = 0; QFixed xmax = 0; for (int i = 0; i < glyphs.numGlyphs; i++) { + // If shaping has found this should be ignored, ignore it. + if (!glyphs.advances[i] || glyphs.attributes[i].dontPrint) + continue; Glyph *g = cacheEnabled ? defaultGlyphSet.getGlyph(glyphs.glyphs[i]) : 0; if (!g) { if (!face) diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index a0e8525268..6fe3e20083 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -59,6 +59,7 @@ private slots: void mnemonicTextWidth(); void leadingBelowLine(); void elidedMetrics(); + void zeroWidthMetrics(); }; void tst_QFontMetrics::same() @@ -358,5 +359,28 @@ void tst_QFontMetrics::elidedMetrics() QFontDatabase::removeApplicationFont(id); } +void tst_QFontMetrics::zeroWidthMetrics() +{ + QString zwnj(QChar(0x200c)); + QString zwsp(QChar(0x200b)); + + QFont font; + QFontMetricsF fm(font); + QCOMPARE(fm.horizontalAdvance(zwnj), 0); + QCOMPARE(fm.horizontalAdvance(zwsp), 0); + QCOMPARE(fm.boundingRect(zwnj).width(), 0); + QCOMPARE(fm.boundingRect(zwsp).width(), 0); + + QString string1 = QStringLiteral("(") + zwnj + QStringLiteral(")"); + QString string2 = QStringLiteral("(") + zwnj + zwnj + QStringLiteral(")"); + QString string3 = QStringLiteral("(") + zwsp + QStringLiteral(")"); + QString string4 = QStringLiteral("(") + zwsp + zwsp + QStringLiteral(")"); + + QCOMPARE(fm.horizontalAdvance(string1), fm.horizontalAdvance(string2)); + QCOMPARE(fm.horizontalAdvance(string3), fm.horizontalAdvance(string4)); + QCOMPARE(fm.boundingRect(string1).width(), fm.boundingRect(string2).width()); + QCOMPARE(fm.boundingRect(string3).width(), fm.boundingRect(string4).width()); +} + QTEST_MAIN(tst_QFontMetrics) #include "tst_qfontmetrics.moc"