diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 03602712cc..30e0f32547 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2531,6 +2531,29 @@ void QTextHtmlExporter::emitBlockAttributes(const QTextBlock &block) html += QLatin1Char(';'); } + if (format.lineHeightType() != QTextBlockFormat::SingleHeight) { + switch (format.lineHeightType()) { + case QTextBlockFormat::ProportionalHeight: + case QTextBlockFormat::FixedHeight: + html += QLatin1String(" line-height:"); + break; + case QTextBlockFormat::MinimumHeight: + html += QLatin1String(" min-height:"); + break; + case QTextBlockFormat::LineDistanceHeight: + html += QLatin1String(" line-spacing:"); + break; + case QTextBlockFormat::SingleHeight: + default: + break; // Should never reach here + } + html += QString::number(format.lineHeight()); + if (format.lineHeightType() == QTextBlockFormat::ProportionalHeight) + html += QLatin1String("%;"); + else + html += QLatin1String("px;"); + } + emitPageBreakPolicy(format.pageBreakPolicy()); QTextCharFormat diff; diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 10e79065ee..307e5a6210 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -113,6 +113,7 @@ private slots: void toHtmlBodyBgColorRgba(); void toHtmlBodyBgColorTransparent(); void toHtmlRootFrameProperties(); + void toHtmlLineHeightProperties(); void capitalizationHtmlInExport(); void wordspacingHtmlExport(); @@ -1856,6 +1857,25 @@ void tst_QTextDocument::toHtmlRootFrameProperties() QCOMPARE(doc.toHtml(), expectedOutput); } +void tst_QTextDocument::toHtmlLineHeightProperties() +{ + CREATE_DOC_AND_CURSOR(); + + QTextBlock block = doc.firstBlock(); + QTextBlockFormat blockFormat = block.blockFormat(); + blockFormat.setLineHeight(200, QTextBlockFormat::ProportionalHeight); + cursor.setBlockFormat(blockFormat); + + cursor.insertText("Blah"); + QString expectedOutput("
Blah
"); + + expectedOutput.prepend(htmlHead); + expectedOutput.replace("DEFAULTBLOCKSTYLE", "style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"); + expectedOutput.append(htmlTail); + + QCOMPARE(doc.toHtml(), expectedOutput); +} + void tst_QTextDocument::capitalizationHtmlInExport() { doc->setPlainText("Test");