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>
This commit is contained in:
Lars Knoll 2020-04-29 17:58:14 +02:00
parent 7e65f6a45d
commit 103ef2bf58

View File

@ -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) {
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
if (type == QTextDocument::HtmlResource) {
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()))