summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qtextbrowser.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-04-29 17:58:14 +0200
committerLars Knoll <lars.knoll@qt.io>2020-05-14 07:50:43 +0200
commit103ef2bf584480979da34d150f5467fdfb85a68b (patch)
treec35ce45013a42fe19f5c16883074fde6e726cb44 /src/widgets/widgets/qtextbrowser.cpp
parent7e65f6a45d7ad4e67b8c27f983edd9c4b2281641 (diff)
Remove QTextCodec dependency from QTextBrowser
Use QStringConverter instead to convert HTML to a QString. This limits the amount of supported encodings to UTF based encodings and Latin1. This is ok, as anything but utf8 is strongly discouraged by the HTML spec anyway, and the support we have with this change does cover ~98% of all real world HTML. Change-Id: Ia610d327624b083c23d3c604aee70517a4a5eb6a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/widgets/widgets/qtextbrowser.cpp')
-rw-r--r--src/widgets/widgets/qtextbrowser.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp
index af61dda1de..c9c5c3f190 100644
--- a/src/widgets/widgets/qtextbrowser.cpp
+++ b/src/widgets/widgets/qtextbrowser.cpp
@@ -48,9 +48,6 @@
#include <qdebug.h>
#include <qabstracttextdocumentlayout.h>
#include "private/qtextdocumentlayout_p.h"
-#if QT_CONFIG(textcodec)
-#include <qtextcodec.h>
-#endif
#include <qpainter.h>
#include <qdir.h>
#if QT_CONFIG(whatsthis)
@@ -314,16 +311,16 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType
if (data.userType() == QMetaType::QString) {
txt = data.toString();
} else if (data.userType() == QMetaType::QByteArray) {
+ QByteArray ba = data.toByteArray();
if (type == QTextDocument::HtmlResource) {
-#if QT_CONFIG(textcodec)
- QByteArray ba = data.toByteArray();
- QTextCodec *codec = Qt::codecForHtml(ba);
- txt = codec->toUnicode(ba);
-#else
- txt = data.toString();
-#endif
+ auto encoding = QStringConverter::encodingForHtml(ba.constData(), ba.size());
+ if (!encoding)
+ // fall back to utf8
+ encoding = QStringDecoder::Utf8;
+ QStringDecoder toUtf16(*encoding);
+ txt = toUtf16(ba);
} else {
- txt = QString::fromUtf8(data.toByteArray());
+ txt = QString::fromUtf8(ba);
}
}
if (Q_UNLIKELY(txt.isEmpty()))