summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2011-06-09 10:06:00 +0200
committerQt Continuous Integration System <qt-info@nokia.com>2011-06-10 12:04:16 +0200
commit11bbfb5882856f47fc15be70be288bc8d00b5d0a (patch)
tree26050f4c9284e0ea3b43b90a9e393dbbed9cac23 /tests/auto
parentdb37aa1004f1e2489b94f1d9cc21630b62e03552 (diff)
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 <p><br /></p> 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 <qt_sanity_bot@ovi.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qtextdocument/tst_qtextdocument.cpp26
1 files changed, 25 insertions, 1 deletions
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", "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p>\n");
+ expectedOutput.replace("EMPTYBLOCK", "<p style=\"-qt-paragraph-type:empty; height:1em; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"></p>\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"