summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtexthtmlparser.cpp
diff options
context:
space:
mode:
authorJoni Poikelin <joni.poikelin@qt.io>2017-02-15 08:59:23 +0200
committerJoni Poikelin <joni.poikelin@qt.io>2017-04-21 07:10:51 +0000
commitecf440d89dcbf422f78fdf8e88fbcacd0108560c (patch)
treecaa96e5172a0bbde83b8662a978ee9be0d185ad0 /src/gui/text/qtexthtmlparser.cpp
parent6ac4f2ccefd71c01e3a7f48d4f73c389de53a6dc (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 'src/gui/text/qtexthtmlparser.cpp')
-rw-r--r--src/gui/text/qtexthtmlparser.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp
index da4e21728f..be10efad8d 100644
--- a/src/gui/text/qtexthtmlparser.cpp
+++ b/src/gui/text/qtexthtmlparser.cpp
@@ -493,7 +493,7 @@ static QString quoteNewline(const QString &s)
QTextHtmlParserNode::QTextHtmlParserNode()
: parent(0), id(Html_unknown),
- cssFloat(QTextFrameFormat::InFlow), hasOwnListStyle(false), hasOwnLineHeightType(false),
+ cssFloat(QTextFrameFormat::InFlow), hasOwnListStyle(false), hasOwnLineHeightType(false), hasLineHeightMultiplier(false),
hasCssListIndent(false), isEmptyParagraph(false), isTextFrame(false), isRootFrame(false),
displayMode(QTextHtmlElement::DisplayInline), hasHref(false),
listStyle(QTextListFormat::ListStyleUndefined), imageWidth(-1), imageHeight(-1), tableBorder(0),
@@ -1216,6 +1216,11 @@ void QTextHtmlParserNode::applyCssDeclarations(const QVector<QCss::Declaration>
else
lineHeightType = QTextBlockFormat::SingleHeight;
+ if (hasLineHeightMultiplier) {
+ qreal lineHeight = blockFormat.lineHeight() / 100.0;
+ blockFormat.setProperty(QTextBlockFormat::LineHeight, lineHeight);
+ }
+
blockFormat.setProperty(QTextBlockFormat::LineHeightType, lineHeightType);
hasOwnLineHeightType = true;
}
@@ -1227,9 +1232,14 @@ void QTextHtmlParserNode::applyCssDeclarations(const QVector<QCss::Declaration>
lineHeightType = QTextBlockFormat::MinimumHeight;
} else {
bool ok;
- QString value = decl.d->values.first().toString();
+ QCss::Value cssValue = decl.d->values.first();
+ QString value = cssValue.toString();
lineHeight = value.toDouble(&ok);
if (ok) {
+ if (!hasOwnLineHeightType && cssValue.type == QCss::Value::Number) {
+ lineHeight *= 100.0;
+ hasLineHeightMultiplier = true;
+ }
lineHeightType = QTextBlockFormat::ProportionalHeight;
} else {
lineHeight = 0.0;