diff options
author | Joni Poikelin <joni.poikelin@qt.io> | 2017-02-15 08:59:23 +0200 |
---|---|---|
committer | Joni Poikelin <joni.poikelin@qt.io> | 2017-04-21 07:10:51 +0000 |
commit | ecf440d89dcbf422f78fdf8e88fbcacd0108560c (patch) | |
tree | caa96e5172a0bbde83b8662a978ee9be0d185ad0 /tests/auto/gui/text/qtextdocument | |
parent | 6ac4f2ccefd71c01e3a7f48d4f73c389de53a6dc (diff) |
Fix CSS line-height property multiplier value handling
CSS style such as "line-height: 1.5;" should be used as a multiplier,
but Qt uses it as percentage which makes line spacing way too small. To
workaround this, convert it to percent and use as
QTextBlockFormat::ProportionalHeight instead.
[ChangeLog][QtGui][Important Behvior Changes] Changed CSS line-height
property with multiplier to follow CSS spec
Task-number: QTBUG-56848
Task-number: QTCREATORBUG-17683
Change-Id: Icc98f7c0d4d07542a220702c287f23fa450ef875
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests/auto/gui/text/qtextdocument')
-rw-r--r-- | tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 764b99646b..2f3da2c196 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -187,6 +187,7 @@ private slots: void cssInheritance(); void lineHeightType(); + void cssLineHeightMultiplier(); private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); void buildRegExpData(); @@ -3398,6 +3399,33 @@ void tst_QTextDocument::lineHeightType() { QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { -qt-line-height-type: fixed; line-height: 10; -qt-line-height-type: fixed; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::FixedHeight)); + QCOMPARE(format.lineHeight(), 10.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { -qt-line-height-type: proportional; line-height: 3; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::ProportionalHeight)); + QCOMPARE(format.lineHeight(), 3.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { line-height: 2.5; -qt-line-height-type: proportional; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::ProportionalHeight)); + QCOMPARE(format.lineHeight(), 2.5); + } + + { + QTextDocument td; td.setHtml("<html><head><style type=\"text/css\">body { line-height: 33; -qt-line-height-type: minimum; }</style></head><body>Foobar</body></html>"); QTextBlock block = td.begin(); QTextBlockFormat format = block.blockFormat(); @@ -3424,5 +3452,26 @@ void tst_QTextDocument::lineHeightType() } } +void tst_QTextDocument::cssLineHeightMultiplier() +{ + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { line-height: 10; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::ProportionalHeight)); + QCOMPARE(format.lineHeight(), 1000.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body {line-height: 1.38; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::ProportionalHeight)); + QCOMPARE(format.lineHeight(), 138.0); + } +} + QTEST_MAIN(tst_QTextDocument) #include "tst_qtextdocument.moc" |