summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-05-11 14:34:27 +0200
committerAndy Shaw <andy.shaw@qt.io>2020-07-06 14:35:57 +0200
commit96cea3b1681dd24a0ec3a53078b78f902e3211a6 (patch)
tree61f912d2560c256fb286b523412aa4be82f98bba /tests
parent60c6f4a51ae6d3de7f9b765f89be41e193f5c19a (diff)
Export the letter and word spacing settings set on the default format
When the default format has letter and word spacing set then these should be exported in the HTML's body tag. This also adds support for the reading of letter-spacing and word-spacing set too, so that the same html outputted can be read back in. Fixes: QTBUG-83718 Change-Id: Ic4afca21eb05efb779dbf99c6b3c13373e851f15 Pick-to: 5.15 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp31
-rw-r--r--tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp43
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 17ce507cdf..5d7f41efda 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -102,6 +102,7 @@ private slots:
void toHtmlBodyBgColorTransparent();
void toHtmlRootFrameProperties();
void toHtmlLineHeightProperties();
+ void toHtmlDefaultFontSpacingProperties();
void capitalizationHtmlInExport();
void wordspacingHtmlExport();
@@ -1964,6 +1965,36 @@ void tst_QTextDocument::toHtmlLineHeightProperties()
QCOMPARE(doc.toHtml(), expectedOutput);
}
+void tst_QTextDocument::toHtmlDefaultFontSpacingProperties()
+{
+ CREATE_DOC_AND_CURSOR();
+
+ cursor.insertText("Blah");
+
+ QFont fnt = doc.defaultFont();
+ fnt.setLetterSpacing(QFont::AbsoluteSpacing, 13);
+ fnt.setWordSpacing(15);
+ doc.setDefaultFont(fnt);
+
+ QString expectedOutput = QString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
+ "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
+ "<html><head><meta name=\"qrichtext\" content=\"1\" />"
+ "<meta charset=\"utf-8\" /><style type=\"text/css\">\n"
+ "p, li { white-space: pre-wrap; }\n"
+ "</style></head>"
+ "<body style=\" font-family:'%1'; font-size:%2; "
+ "font-weight:%3; font-style:%4; letter-spacing:13px; "
+ "word-spacing:15px;\">\n"
+ "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
+ "</body></html>");
+ expectedOutput = expectedOutput.arg(defaultFont.family())
+ .arg(cssFontSizeString(defaultFont))
+ .arg(defaultFont.weight() * 8)
+ .arg((defaultFont.italic() ? "italic" : "normal"));
+
+ QCOMPARE(doc.toHtml(), expectedOutput);
+}
+
void tst_QTextDocument::capitalizationHtmlInExport()
{
doc->setPlainText("Test");
diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
index 67bb628215..3b4c55d406 100644
--- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
+++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
@@ -266,6 +266,7 @@ private slots:
void html_importImageWithoutAspectRatio();
void html_fromFirefox();
void html_emptyInlineInsideBlock();
+ void css_fontAndWordSpacing();
private:
inline void setHtml(const QString &html)
@@ -4239,5 +4240,47 @@ void tst_QTextDocumentFragment::html_emptyInlineInsideBlock()
QVERIFY(doc->firstBlock().blockFormat().leftMargin() > 0);
}
+void tst_QTextDocumentFragment::css_fontAndWordSpacing()
+{
+ {
+ const char html[] = "<body style=\"letter-spacing:13px; word-spacing:15px;\">Foo</span>";
+ doc->setHtml(html);
+ cursor.movePosition(QTextCursor::Start);
+ cursor.movePosition(QTextCursor::NextCharacter);
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontLetterSpacing).toInt(), 13);
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontLetterSpacingType).toUInt(),
+ (uint)(QFont::AbsoluteSpacing));
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontWordSpacing).toInt(), 15);
+ }
+ {
+ const char html[] = "<body style=\"letter-spacing:1em; word-spacing:0px;\">Foo</span>";
+ doc->setHtml(html);
+ cursor.movePosition(QTextCursor::Start);
+ cursor.movePosition(QTextCursor::NextCharacter);
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontLetterSpacing).toInt(), 200);
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontLetterSpacingType).toUInt(),
+ (uint)(QFont::PercentageSpacing));
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontWordSpacing).toInt(), 0);
+ }
+ {
+ const char html[] = "<body style=\"letter-spacing:0em;\">Foo</span>";
+ doc->setHtml(html);
+ cursor.movePosition(QTextCursor::Start);
+ cursor.movePosition(QTextCursor::NextCharacter);
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontLetterSpacing).toInt(), 100);
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontLetterSpacingType).toUInt(),
+ (uint)(QFont::PercentageSpacing));
+ }
+ {
+ const char html[] = "<body style=\"letter-spacing:-0.5em;\">Foo</span>";
+ doc->setHtml(html);
+ cursor.movePosition(QTextCursor::Start);
+ cursor.movePosition(QTextCursor::NextCharacter);
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontLetterSpacing).toInt(), 50);
+ QCOMPARE(cursor.charFormat().property(QTextFormat::FontLetterSpacingType).toUInt(),
+ (uint)(QFont::PercentageSpacing));
+ }
+}
+
QTEST_MAIN(tst_QTextDocumentFragment)
#include "tst_qtextdocumentfragment.moc"