diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-11 17:17:13 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-11 17:17:51 +0200 |
commit | 4dac45c9ee59ff6586d90d423654da91523ab679 (patch) | |
tree | cd4a4adf2cbc9e77bf86d2d11e71ec66afdf3be4 /src/gui/text/qtextdocument.cpp | |
parent | 078cd61751aeaa310d35a3d596a21a36004a1a0f (diff) | |
parent | f44850b5c3464cdda0ee9b1ee858d95f3ffaa3e2 (diff) |
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Change-Id: I715b1d743d5f11560e7b3fbeb8fd64a5e5ddb277
Diffstat (limited to 'src/gui/text/qtextdocument.cpp')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 899801ca39..dc34a96918 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1364,6 +1364,8 @@ QTextCursor QTextDocument::find(const QString &subString, int from, FindFlags op blockOffset = 0; } } else { + if (blockOffset == block.length() - 1) + --blockOffset; // make sure to skip end-of-paragraph character while (block.isValid()) { if (findInBlock(block, subString, blockOffset, options, &cursor)) return cursor; @@ -2304,7 +2306,11 @@ QString QTextHtmlExporter::toHtml(const QByteArray &encoding, ExportMode mode) if (mode == ExportEntireDocument) { html += QLatin1String(" style=\""); - emitFontFamily(defaultCharFormat.fontFamily()); + QStringList fontFamilies = defaultCharFormat.fontFamilies().toStringList(); + if (!fontFamilies.isEmpty()) + emitFontFamily(fontFamilies); + else + emitFontFamily(defaultCharFormat.fontFamily()); if (defaultCharFormat.hasProperty(QTextFormat::FontPointSize)) { html += QLatin1String(" font-size:"); @@ -2366,8 +2372,12 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) bool attributesEmitted = false; { + const QStringList families = format.fontFamilies().toStringList(); const QString family = format.fontFamily(); - if (!family.isEmpty() && family != defaultCharFormat.fontFamily()) { + if (!families.isEmpty() && families != defaultCharFormat.fontFamilies().toStringList()) { + emitFontFamily(families); + attributesEmitted = true; + } else if (!family.isEmpty() && family != defaultCharFormat.fontFamily()) { emitFontFamily(family); attributesEmitted = true; } @@ -2468,9 +2478,19 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) if (format.foreground() != defaultCharFormat.foreground() && format.foreground().style() != Qt::NoBrush) { - html += QLatin1String(" color:"); - html += colorValue(format.foreground().color()); - html += QLatin1Char(';'); + QBrush brush = format.foreground(); + if (brush.style() == Qt::TexturePattern) { + const bool isPixmap = qHasPixmapTexture(brush); + const qint64 cacheKey = isPixmap ? brush.texture().cacheKey() : brush.textureImage().cacheKey(); + + html += QLatin1String(" -qt-fg-texture-cachekey:"); + html += QString::number(cacheKey); + html += QLatin1String(";"); + } else { + html += QLatin1String(" color:"); + html += colorValue(brush.color()); + html += QLatin1Char(';'); + } attributesEmitted = true; } @@ -2644,6 +2664,27 @@ void QTextHtmlExporter::emitFontFamily(const QString &family) html += QLatin1Char(';'); } +void QTextHtmlExporter::emitFontFamily(const QStringList &families) +{ + html += QLatin1String(" font-family:"); + + bool first = true; + for (const QString &family : families) { + QLatin1String quote("\'"); + if (family.contains(QLatin1Char('\''))) + quote = QLatin1String("""); + + if (!first) + html += QLatin1String(","); + else + first = false; + html += quote; + html += family.toHtmlEscaped(); + html += quote; + } + html += QLatin1Char(';'); +} + void QTextHtmlExporter::emitMargins(const QString &top, const QString &bottom, const QString &left, const QString &right) { html += QLatin1String(" margin-top:"); |