From 3fe242781e88224d121ebca730db5ebe4fb98ec6 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 10 Oct 2013 22:57:08 +0200 Subject: [PATCH] Export the block's line-height settings to html Task-number: QTBUG-28404 Change-Id: I87e03ecd981c302a5aefdadf7bcfd9729e37bd13 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Simon Hausmann --- src/gui/text/qtextdocument.cpp | 23 +++++++++++++++++++ .../text/qtextdocument/tst_qtextdocument.cpp | 20 ++++++++++++++++ 2 files changed, 43 insertions(+) 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");