summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocument.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-04-07 10:49:17 +0200
committerLars Knoll <lars.knoll@qt.io>2020-04-21 15:46:36 +0200
commit50916edd9d1707774c597abe1b7237e1a798fc53 (patch)
treeba761a0d1f017836fb1957212a63ff9854bce76c /src/gui/text/qtextdocument.cpp
parenta23cb5cd06bcc3268387cb1abaa0dc2c2d3b13f4 (diff)
Always encode HTML as utf-8
When converting a text document to HTML, always convert it to utf-8, as required by the HTML standard. This also means that we remove the optional encoding parameter. Change-Id: I0bd2fc9df2d06734e1c5b8053b964fbfbb6881e1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/gui/text/qtextdocument.cpp')
-rw-r--r--src/gui/text/qtextdocument.cpp21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index be95e2177d..9cc1ba6c1c 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -2202,7 +2202,7 @@ static QStringList resolvedFontFamilies(const QTextCharFormat &format)
perfect, especially for complex documents, due to the limitations
of HTML.
*/
-QString QTextHtmlExporter::toHtml(const QByteArray &encoding, ExportMode mode)
+QString QTextHtmlExporter::toHtml(ExportMode mode)
{
html = QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
"\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
@@ -2211,8 +2211,7 @@ QString QTextHtmlExporter::toHtml(const QByteArray &encoding, ExportMode mode)
fragmentMarkers = (mode == ExportFragment);
- if (!encoding.isEmpty())
- html += QString::fromLatin1("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%1\" />").arg(QString::fromLatin1(encoding));
+ html += QString::fromLatin1("<meta charset=\"utf-8\" />");
QString title = doc->metaInformation(QTextDocument::DocumentTitle);
if (!title.isEmpty())
@@ -3239,23 +3238,17 @@ void QTextHtmlExporter::emitFrameStyle(const QTextFrameFormat &format, FrameType
/*!
Returns a string containing an HTML representation of the document.
- The \a encoding parameter specifies the value for the charset attribute
- in the html header. For example if 'utf-8' is specified then the
- beginning of the generated html will look like this:
- \snippet code/src_gui_text_qtextdocument.cpp 0
-
- If no encoding is specified then no such meta information is generated.
-
+ The content of the document specifies its encoding to be UTF-8.
If you later on convert the returned html string into a byte array for
- transmission over a network or when saving to disk you should specify
- the encoding you're going to use for the conversion to a byte array here.
+ transmission over a network or when saving to disk you should use
+ QString::toUtf8() to convert the string to a QByteArray.
\sa {Supported HTML Subset}
*/
#ifndef QT_NO_TEXTHTMLPARSER
-QString QTextDocument::toHtml(const QByteArray &encoding) const
+QString QTextDocument::toHtml() const
{
- return QTextHtmlExporter(this).toHtml(encoding);
+ return QTextHtmlExporter(this).toHtml();
}
#endif // QT_NO_TEXTHTMLPARSER