summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextimagehandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text/qtextimagehandler.cpp')
-rw-r--r--src/gui/text/qtextimagehandler.cpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/gui/text/qtextimagehandler.cpp b/src/gui/text/qtextimagehandler.cpp
index e85890baf2..16d81a7d6d 100644
--- a/src/gui/text/qtextimagehandler.cpp
+++ b/src/gui/text/qtextimagehandler.cpp
@@ -44,7 +44,10 @@
QT_BEGIN_NAMESPACE
-static QString resolveFileName(QString fileName, QUrl *url, qreal targetDevicePixelRatio)
+extern QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
+ qreal *sourceDevicePixelRatio);
+static QString resolveFileName(QString fileName, QUrl *url, qreal targetDevicePixelRatio,
+ qreal *sourceDevicePixelRatio)
{
// We might use the fileName for loading if url loading fails
// try to make sure it is a valid file path.
@@ -62,19 +65,8 @@ static QString resolveFileName(QString fileName, QUrl *url, qreal targetDevicePi
if (targetDevicePixelRatio <= 1.0)
return fileName;
- // try to find a 2x version
-
- const int dotIndex = fileName.lastIndexOf(QLatin1Char('.'));
- if (dotIndex != -1) {
- QString at2xfileName = fileName;
- at2xfileName.insert(dotIndex, QStringLiteral("@2x"));
- if (QFile::exists(at2xfileName)) {
- fileName = at2xfileName;
- *url = QUrl(fileName);
- }
- }
-
- return fileName;
+ // try to find a Nx version
+ return qt_findAtNxFile(fileName, targetDevicePixelRatio, sourceDevicePixelRatio);
}
@@ -86,7 +78,8 @@ static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, con
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources and convert them to url
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl(name);
- name = resolveFileName(name, &url, devicePixelRatio);
+ qreal sourcePixelRatio = 1.0;
+ name = resolveFileName(name, &url, devicePixelRatio, &sourcePixelRatio);
const QVariant data = doc->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Pixmap || data.type() == QVariant::Image) {
pm = qvariant_cast<QPixmap>(data);
@@ -112,7 +105,7 @@ static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, con
}
if (name.contains(QStringLiteral("@2x")))
- pm.setDevicePixelRatio(2.0);
+ pm.setDevicePixelRatio(sourcePixelRatio);
return pm;
}
@@ -167,7 +160,8 @@ static QImage getImage(QTextDocument *doc, const QTextImageFormat &format, const
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl(name);
- name = resolveFileName(name, &url, devicePixelRatio);
+ qreal sourcePixelRatio = 1.0;
+ name = resolveFileName(name, &url, devicePixelRatio, &sourcePixelRatio);
const QVariant data = doc->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Image) {
image = qvariant_cast<QImage>(data);
@@ -191,8 +185,8 @@ static QImage getImage(QTextDocument *doc, const QTextImageFormat &format, const
doc->addResource(QTextDocument::ImageResource, url, image);
}
- if (name.contains(QStringLiteral("@2x")))
- image.setDevicePixelRatio(2.0);
+ if (sourcePixelRatio != 1.0)
+ image.setDevicePixelRatio(sourcePixelRatio);
return image;
}
@@ -256,10 +250,10 @@ void QTextImageHandler::drawObject(QPainter *p, const QRectF &rect, QTextDocumen
const QTextImageFormat imageFormat = format.toImageFormat();
if (QCoreApplication::instance()->thread() != QThread::currentThread()) {
- const QImage image = getImage(doc, imageFormat, p->device()->devicePixelRatio());
+ const QImage image = getImage(doc, imageFormat, p->device()->devicePixelRatioF());
p->drawImage(rect, image, image.rect());
} else {
- const QPixmap pixmap = getPixmap(doc, imageFormat, p->device()->devicePixelRatio());
+ const QPixmap pixmap = getPixmap(doc, imageFormat, p->device()->devicePixelRatioF());
p->drawPixmap(rect, pixmap, pixmap.rect());
}
}