summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/text/qtextdocument.cpp8
-rw-r--r--tests/auto/qtextdocument/tst_qtextdocument.cpp26
2 files changed, 34 insertions, 0 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index 36f3c6cb4f..9169955617 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -2099,6 +2099,10 @@ QString QTextHtmlExporter::toHtml(const QByteArray &encoding, ExportMode mode)
html += QLatin1String(" font-size:");
html += QString::number(defaultCharFormat.fontPointSize());
html += QLatin1String("pt;");
+ } else if (defaultCharFormat.hasProperty(QTextFormat::FontPixelSize)) {
+ html += QLatin1String(" font-size:");
+ html += QString::number(defaultCharFormat.intProperty(QTextFormat::FontPixelSize));
+ html += QLatin1String("px;");
}
html += QLatin1String(" font-weight:");
@@ -2179,6 +2183,10 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format)
html += QLatin1Char(';');
attributesEmitted = true;
}
+ } else if (format.hasProperty(QTextFormat::FontPixelSize)) {
+ html += QLatin1String(" font-size:");
+ html += QString::number(format.intProperty(QTextFormat::FontPixelSize));
+ html += QLatin1String("px;");
}
if (format.hasProperty(QTextFormat::FontWeight)
diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp
index 6675c99d23..26fa43d137 100644
--- a/tests/auto/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp
@@ -180,6 +180,8 @@ private slots:
void escape_data();
void escape();
+ void copiedFontSize();
+
private:
void backgroundImage_checkExpectedHtml(const QTextDocument &doc);
@@ -2734,5 +2736,29 @@ void tst_QTextDocument::escape()
QCOMPARE(Qt::escape(original), expected);
}
+void tst_QTextDocument::copiedFontSize()
+{
+ QTextDocument documentInput;
+ QTextDocument documentOutput;
+
+ QFont fontInput;
+ fontInput.setPixelSize(24); // With pixels font size is not transfered in html
+
+ QTextCursor cursorInput(&documentInput);
+ QTextCharFormat formatInput = cursorInput.charFormat();
+ formatInput.setFont(fontInput);
+ cursorInput.insertText("Should be the same font", formatInput);
+ cursorInput.select(QTextCursor::Document);
+
+ QTextDocumentFragment fragmentInput(cursorInput);
+ QString html = fragmentInput.toHtml();
+
+ QTextCursor cursorOutput(&documentOutput);
+ QTextDocumentFragment fragmentOutput = QTextDocumentFragment::fromHtml(html);
+ cursorOutput.insertFragment(fragmentOutput);
+
+ QCOMPARE(cursorOutput.charFormat().font().pixelSize(), 24);
+}
+
QTEST_MAIN(tst_QTextDocument)
#include "tst_qtextdocument.moc"