From 11bbfb5882856f47fc15be70be288bc8d00b5d0a Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 9 Jun 2011 10:06:00 +0200 Subject: Fix missing empty lines in Qt HTML when displayed in compliant browsers When QTextDocument exports HTML, it makes an effort to be compatible with its own importer, hence it has to be compatible with the dialect of HTML which Qt has developed over the years. One incorrect interpretation in Qt is that an empty paragraph is interpreted as an empty line. So if you use a QTextDocument to produce HTML for text where an empty line has been added, this empty line will not be visible when the document is viewed in a compliant browser. The fix is to set the height of the empty paragraph to 1em, so that it will match the current pixel size of the font, thus look the same as a


but without altering the structure of the document. Reviewed-by: Gunnar (cherry picked from commit f541c78e1bc5b293466b40e6f10496199a4a5d73) Change-Id: Ic0eae2c81609b8872eb2eb9344a3ec416cd09149 Reviewed-on: http://codereview.qt.nokia.com/445 Reviewed-by: Qt Sanity Bot Reviewed-by: Eskil Abrahamsen Blomfeldt --- tests/auto/qtextdocument/tst_qtextdocument.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp index 1129219b1f..68252ef6ae 100644 --- a/tests/auto/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp @@ -182,6 +182,8 @@ private slots: void copiedFontSize(); + void htmlExportImportBlockCount(); + private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); @@ -1582,7 +1584,7 @@ void tst_QTextDocument::toHtml() expectedOutput.replace("OPENDEFAULTBLOCKSTYLE", "style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"); expectedOutput.replace("DEFAULTBLOCKSTYLE", "style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\""); - expectedOutput.replace("EMPTYBLOCK", "

\n"); + expectedOutput.replace("EMPTYBLOCK", "

\n"); if (expectedOutput.endsWith(QLatin1Char('\n'))) expectedOutput.chop(1); expectedOutput.append(htmlTail); @@ -2760,5 +2762,27 @@ void tst_QTextDocument::copiedFontSize() QCOMPARE(cursorOutput.charFormat().font().pixelSize(), 24); } +void tst_QTextDocument::htmlExportImportBlockCount() +{ + QTextDocument document; + { + QTextCursor cursor(&document); + cursor.insertText("Foo"); + cursor.insertBlock(); + cursor.insertBlock(); + cursor.insertBlock(); + cursor.insertBlock(); + cursor.insertText("Bar"); + } + + QCOMPARE(document.blockCount(), 5); + QString html = document.toHtml(); + + document.clear(); + document.setHtml(html); + + QCOMPARE(document.blockCount(), 5); +} + QTEST_MAIN(tst_QTextDocument) #include "tst_qtextdocument.moc" -- cgit v1.2.3