From ecf440d89dcbf422f78fdf8e88fbcacd0108560c Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Wed, 15 Feb 2017 08:59:23 +0200 Subject: 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 --- src/gui/text/qtexthtmlparser.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/gui/text/qtexthtmlparser.cpp') 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 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 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; -- cgit v1.2.3