From 96cea3b1681dd24a0ec3a53078b78f902e3211a6 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 11 May 2020 14:34:27 +0200 Subject: 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 --- src/gui/text/qtextdocument.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/gui/text/qtextdocument.cpp') diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 04edf89430..0890614be9 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2228,6 +2228,24 @@ QString QTextHtmlExporter::toHtml(ExportMode mode) html += (defaultCharFormat.fontItalic() ? QLatin1String("italic") : QLatin1String("normal")); html += QLatin1Char(';'); + const bool percentSpacing = (defaultCharFormat.fontLetterSpacingType() == QFont::PercentageSpacing); + if (defaultCharFormat.hasProperty(QTextFormat::FontLetterSpacing) && + (!percentSpacing || defaultCharFormat.fontLetterSpacing() != 0.0)) { + html += QLatin1String(" letter-spacing:"); + qreal value = defaultCharFormat.fontLetterSpacing(); + if (percentSpacing) // Map to em (100% == 0em) + value = (value / 100) - 1; + html += QString::number(value); + html += percentSpacing ? QLatin1String("em;") : QLatin1String("px;"); + } + + if (defaultCharFormat.hasProperty(QTextFormat::FontWordSpacing) && + defaultCharFormat.fontWordSpacing() != 0.0) { + html += QLatin1String(" word-spacing:"); + html += QString::number(defaultCharFormat.fontWordSpacing()); + 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 -- cgit v1.2.3