From 720defd2caee5225527fa0b154fa68b738fb967b Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 3 May 2021 15:27:08 +0200 Subject: [PATCH] Export text-decoration It used to be ignored because we couldn't disable it, but that works fine now. So re-enable it. Fixes: QTBUG-91171 Change-Id: I4cf966211bb200b73326e90fc7e4c4d3d4090511 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qtextdocument.cpp | 29 ++++++++++++++----- .../tst_qtextdocumentfragment.cpp | 4 +-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index e302a1e170..bf8c10f0d9 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2331,11 +2331,6 @@ QTextHtmlExporter::QTextHtmlExporter(const QTextDocument *_doc) { const QFont defaultFont = doc->defaultFont(); defaultCharFormat.setFont(defaultFont); - // don't export those for the default font since we cannot turn them off with CSS - defaultCharFormat.clearProperty(QTextFormat::FontUnderline); - defaultCharFormat.clearProperty(QTextFormat::FontOverline); - defaultCharFormat.clearProperty(QTextFormat::FontStrikeOut); - defaultCharFormat.clearProperty(QTextFormat::TextUnderlineStyle); } static QStringList resolvedFontFamilies(const QTextCharFormat &format) @@ -2408,8 +2403,28 @@ QString QTextHtmlExporter::toHtml(ExportMode mode) html += QLatin1String("px;"); } - // do not set text-decoration on the default font since those values are /always/ propagated - // and cannot be turned off with CSS + QString decorationTag(QLatin1String(" text-decoration:")); + bool atLeastOneDecorationSet = false; + if (defaultCharFormat.hasProperty(QTextFormat::FontUnderline) || defaultCharFormat.hasProperty(QTextFormat::TextUnderlineStyle)) { + if (defaultCharFormat.fontUnderline()) { + decorationTag += QLatin1String(" underline"); + atLeastOneDecorationSet = true; + } + } + if (defaultCharFormat.hasProperty(QTextFormat::FontOverline)) { + if (defaultCharFormat.fontOverline()) { + decorationTag += QLatin1String(" overline"); + atLeastOneDecorationSet = true; + } + } + if (defaultCharFormat.hasProperty(QTextFormat::FontStrikeOut)) { + if (defaultCharFormat.fontStrikeOut()) { + decorationTag += QLatin1String(" line-through"); + atLeastOneDecorationSet = true; + } + } + if (atLeastOneDecorationSet) + html += decorationTag + QLatin1Char(';'); html += QLatin1Char('\"'); diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp index a7408fcc8e..49d0f42be6 100644 --- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp +++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp @@ -2426,12 +2426,12 @@ void tst_QTextDocumentFragment::defaultFont() f.setFamily("Courier New"); f.setBold(true); f.setItalic(true); - f.setStrikeOut(true); // set here but deliberately ignored for the html export + f.setStrikeOut(true); f.setPointSize(100); doc->setDefaultFont(f); doc->setPlainText("Hello World"); const QString html = doc->toHtml(); - QLatin1String str(""); + QLatin1String str(""); QVERIFY(html.contains(str)); }