Unit test for checking text-decoration in html export

This unit test is related to the parent commit.
Html export used to omit the text-decoration for the default font,
this unit test ensures that this property is added to the exported
html.

Fixes: QTBUG-91171
Change-Id: Ib68bec27f9963cdcac5c553b2c07557717b1c22e
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
bb10
Oliver Eftevaag 2021-05-03 20:25:25 +02:00
parent 720defd2ca
commit 38f4e1f3e7
1 changed files with 57 additions and 0 deletions

View File

@ -103,6 +103,7 @@ private slots:
void toHtmlRootFrameProperties();
void toHtmlLineHeightProperties();
void toHtmlDefaultFontSpacingProperties();
void toHtmlTextDecorationUnderline();
void capitalizationHtmlInExport();
void wordspacingHtmlExport();
@ -1993,6 +1994,62 @@ void tst_QTextDocument::toHtmlDefaultFontSpacingProperties()
QCOMPARE(doc.toHtml(), expectedOutput);
}
void tst_QTextDocument::toHtmlTextDecorationUnderline()
{
CREATE_DOC_AND_CURSOR();
cursor.insertText("Some text");
QFont fnt = doc.defaultFont();
fnt.setUnderline(true);
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; text-decoration: underline;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
"margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Some text</p>"
"</body></html>");
expectedOutput = expectedOutput.arg(doc.defaultFont().family())
.arg(cssFontSizeString(doc.defaultFont()))
.arg(doc.defaultFont().weight())
.arg((doc.defaultFont().italic() ? "italic" : "normal"));
QCOMPARE(doc.toHtml(), expectedOutput);
QTextCharFormat format;
format.setFontUnderline(false);
cursor.select(QTextCursor::Document);
cursor.mergeCharFormat(format);
QString expectedOutput2 =
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; text-decoration: underline;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
"margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
"<span style=\" text-decoration:none;\">Some text</span></p>"
"</body></html>");
expectedOutput2 = expectedOutput2.arg(doc.defaultFont().family())
.arg(cssFontSizeString(doc.defaultFont()))
.arg(doc.defaultFont().weight())
.arg((doc.defaultFont().italic() ? "italic" : "normal"));
QCOMPARE(doc.toHtml(), expectedOutput2);
}
void tst_QTextDocument::capitalizationHtmlInExport()
{
doc->setPlainText("Test");