diff options
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:"); |