summaryrefslogtreecommitdiff
path: root/src/gui/text/qtextdocument.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-12-03 15:12:51 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-01-02 10:30:13 +0100
commita1f4321bbba2f3bff24d753ce766be738dbfa61a (patch)
tree4a9444c604517313d327c45bbab6bf4186db26e4 /src/gui/text/qtextdocument.cpp
parent809a96d6d94a93046dc63dd6f52c51ae90c374f8 (diff)
downloadqtbase-a1f4321bbba2f3bff24d753ce766be738dbfa61a.tar.gz
QTextDocument: Give fontFamily() precedence over fontFamilies()
If the singular fontFamily() is given, then this is obviously the one to be preferred over any plural fontFamilies(). Make sure it always ends up first in the list of emitted font families. Change-Id: I1e3b1ba29721c8298b1a0d4a1e1da49ba5b4e7ac Fixes: QTBUG-80475 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/text/qtextdocument.cpp')
-rw-r--r--src/gui/text/qtextdocument.cpp39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index 4b35509ace..25c153910d 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -2297,6 +2297,17 @@ QTextHtmlExporter::QTextHtmlExporter(const QTextDocument *_doc)
defaultCharFormat.clearProperty(QTextFormat::TextUnderlineStyle);
}
+static QStringList resolvedFontFamilies(const QTextCharFormat &format)
+{
+ QStringList fontFamilies = format.fontFamilies().toStringList();
+ const QString mainFontFamily = format.fontFamily();
+ if (!mainFontFamily.isEmpty() && !fontFamilies.startsWith(mainFontFamily)) {
+ fontFamilies.removeAll(mainFontFamily);
+ fontFamilies.prepend(mainFontFamily);
+ }
+ return fontFamilies;
+}
+
/*!
Returns the document in HTML format. The conversion may not be
perfect, especially for complex documents, due to the limitations
@@ -2325,11 +2336,7 @@ QString QTextHtmlExporter::toHtml(const QByteArray &encoding, ExportMode mode)
if (mode == ExportEntireDocument) {
html += QLatin1String(" style=\"");
- QStringList fontFamilies = defaultCharFormat.fontFamilies().toStringList();
- if (!fontFamilies.isEmpty())
- emitFontFamily(fontFamilies);
- else
- emitFontFamily(defaultCharFormat.fontFamily());
+ emitFontFamily(resolvedFontFamilies(defaultCharFormat));
if (defaultCharFormat.hasProperty(QTextFormat::FontPointSize)) {
html += QLatin1String(" font-size:");
@@ -2391,14 +2398,10 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format)
bool attributesEmitted = false;
{
- const QStringList families = format.fontFamilies().toStringList();
- const QString family = format.fontFamily();
- if (!families.isEmpty() && families != defaultCharFormat.fontFamilies().toStringList()) {
+ const QStringList families = resolvedFontFamilies(format);
+ if (!families.isEmpty() && families != resolvedFontFamilies(defaultCharFormat)) {
emitFontFamily(families);
attributesEmitted = true;
- } else if (!family.isEmpty() && family != defaultCharFormat.fontFamily()) {
- emitFontFamily(family);
- attributesEmitted = true;
}
}
@@ -2661,20 +2664,6 @@ void QTextHtmlExporter::emitPageBreakPolicy(QTextFormat::PageBreakFlags policy)
html += QLatin1String(" page-break-after:always;");
}
-void QTextHtmlExporter::emitFontFamily(const QString &family)
-{
- html += QLatin1String(" font-family:");
-
- QLatin1String quote("\'");
- if (family.contains(QLatin1Char('\'')))
- quote = QLatin1String("&quot;");
-
- html += quote;
- html += family.toHtmlEscaped();
- html += quote;
- html += QLatin1Char(';');
-}
-
void QTextHtmlExporter::emitFontFamily(const QStringList &families)
{
html += QLatin1String(" font-family:");