diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2016-03-30 13:15:02 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2016-04-19 09:32:10 +0000 |
commit | 7094466f7d0c2176eb3080021a4ea5d220555df9 (patch) | |
tree | c1f633f1f3ce805a9af78c8e31e5f70ef6d29694 /tests/auto | |
parent | b3fcaea5f2b97d3f562add97aee48cbb469c875a (diff) |
Interpret fixed CSS line-height as minimum rather than absolute
The QTextBlockFormat::FixedHeight overrides the line height
regardless of its calculated height. If the line contains
objects or text which is higher than the specified line height,
using FixedHeight will cause them to overlap with the previous
line. This is not what happens in normal web browsers. The
expected behavior is that the line height given in CSS is the
minimum height, but that we still reserve space needed to display
everything without overlaps.
To make it possible for people to retain the old behavior, we
introduce the -qt-line-height-type property, which allows them
to override the default.
This also fixes output from toHtml() to use the new property
rather than set the minimum height of the paragraph or the
"line-spacing" property, which does not exist in either CSS nor
in Qt.
[ChangeLog][QtGui][Important Behavior Changes] When line height
is specified in pixels, this is now interpreted as the minimum
line height rather than an absolute line height to avoid overlaps.
To get the old behavior, use the -qt-line-height-type property in
CSS and set it to "fixed".
Task-number: QTBUG-51962
Change-Id: Ic2dde649b69209672170dad4c2de1e1c432a1078
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp | 88 |
1 files changed, 87 insertions, 1 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 04e6bba91e..1869139a98 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -183,6 +183,8 @@ private slots: void textCursorUsageWithinContentsChange(); void cssInheritance(); + + void lineHeightType(); private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); void buildRegExpData(); @@ -3191,7 +3193,7 @@ void tst_QTextDocument::cssInheritance() "<p style=\"line-height: 40px\">Foo</p><p>Bar</p><p>Baz</p></body></html>"); QTextBlock block = td.begin(); QTextBlockFormat fmt = block.blockFormat(); - QCOMPARE(fmt.lineHeightType(), int(QTextBlockFormat::FixedHeight)); + QCOMPARE(fmt.lineHeightType(), int(QTextBlockFormat::MinimumHeight)); QCOMPARE(fmt.lineHeight(), qreal(40)); block = block.next(); fmt = block.blockFormat(); @@ -3276,5 +3278,89 @@ void tst_QTextDocument::cssInheritance() } } +void tst_QTextDocument::lineHeightType() +{ + { + QTextDocument td; + td.setHtml("<html><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::SingleHeight)); + QCOMPARE(format.lineHeight(), 0.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { line-height: 40px; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::MinimumHeight)); + QCOMPARE(format.lineHeight(), 40.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { line-height: 200%; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::ProportionalHeight)); + QCOMPARE(format.lineHeight(), 200.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { line-height: 200%; -qt-line-height-type: single; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::SingleHeight)); + QCOMPARE(format.lineHeight(), 200.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { line-height: 40px; -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(), 40.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { 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 { line-height: 33; -qt-line-height-type: minimum; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::MinimumHeight)); + QCOMPARE(format.lineHeight(), 33.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { -qt-line-height-type: fixed; line-height: 200%; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::FixedHeight)); + QCOMPARE(format.lineHeight(), 200.0); + } + + { + QTextDocument td; + td.setHtml("<html><head><style type=\"text/css\">body { -qt-line-height-type: fixed; line-height: 200px; }</style></head><body>Foobar</body></html>"); + QTextBlock block = td.begin(); + QTextBlockFormat format = block.blockFormat(); + QCOMPARE(int(format.lineHeightType()), int(QTextBlockFormat::FixedHeight)); + QCOMPARE(format.lineHeight(), 200.0); + } +} + QTEST_MAIN(tst_QTextDocument) #include "tst_qtextdocument.moc" |