Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: svg/dci pixmap not clear when DPR > 1 #203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions imageformatplugins/dci/qdciiohandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "qvariant.h"
#include "qbuffer.h"
#include "qdebug.h"
#include <QGuiApplication>

#include <DDciIcon>

Expand Down Expand Up @@ -95,7 +96,6 @@ QDciIOHandler::QDciIOHandler()

}


QDciIOHandler::~QDciIOHandler()
{
delete d;
Expand All @@ -120,6 +120,17 @@ QByteArray QDciIOHandler::name() const
return "dci";
}

static inline qreal devicePixelRatio()
{
qreal ratio = 1.0;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (qApp->testAttribute(Qt::AA_UseHighDpiPixmaps))
#endif
ratio = qApp->devicePixelRatio();

return ratio;
}

bool QDciIOHandler::read(QImage *image)
{
if (d->readDone || d->load(device())) {
Expand All @@ -128,7 +139,7 @@ bool QDciIOHandler::read(QImage *image)

if (finalSize > 0) {
DDciIconPalette palette(QColor::Invalid, d->backColor);
*image = d->icon.pixmap(1.0, finalSize, d->current, palette).toImage();
*image = d->icon.pixmap(devicePixelRatio(), finalSize, d->current, palette).toImage();
}
d->readDone = true;
return true;
Expand Down
22 changes: 14 additions & 8 deletions imageformatplugins/svg/qsvgiohandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "qvariant.h"
#include "qbuffer.h"
#include "qdebug.h"
#include <QGuiApplication>

#include <DSvgRenderer>

Expand Down Expand Up @@ -71,20 +72,17 @@ bool QSvgIOHandlerPrivate::load(QIODevice *device)
return loaded;
}


QSvgIOHandler::QSvgIOHandler()
: d(new QSvgIOHandlerPrivate(this))
{

}


QSvgIOHandler::~QSvgIOHandler()
{
delete d;
}


bool QSvgIOHandler::canRead() const
{
if (!device())
Expand All @@ -103,12 +101,21 @@ bool QSvgIOHandler::canRead() const
return false;
}


QByteArray QSvgIOHandler::name() const
{
return "svg";
}

static inline qreal devicePixelRatio()
{
qreal ratio = 1.0;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (qApp->testAttribute(Qt::AA_UseHighDpiPixmaps))
#endif
ratio = qApp->devicePixelRatio();

return ratio;
}

bool QSvgIOHandler::read(QImage *image)
{
Expand Down Expand Up @@ -140,6 +147,8 @@ bool QSvgIOHandler::read(QImage *image)
bounds = t.mapRect(bounds);
}
if (!finalSize.isEmpty()) {
qreal ratio = devicePixelRatio();
finalSize *= ratio;
if (bounds.isEmpty() && d->backColor.alpha() == 0) {
*image = d->r.toImage(finalSize);
} else {
Expand All @@ -150,6 +159,7 @@ bool QSvgIOHandler::read(QImage *image)
d->r.render(&p, bounds);
p.end();
}
image->setDevicePixelRatio(ratio);
}
d->readDone = true;
return true;
Expand All @@ -158,7 +168,6 @@ bool QSvgIOHandler::read(QImage *image)
return false;
}


QVariant QSvgIOHandler::option(ImageOption option) const
{
switch(option) {
Expand Down Expand Up @@ -187,7 +196,6 @@ QVariant QSvgIOHandler::option(ImageOption option) const
return QVariant();
}


void QSvgIOHandler::setOption(ImageOption option, const QVariant & value)
{
switch(option) {
Expand All @@ -208,7 +216,6 @@ void QSvgIOHandler::setOption(ImageOption option, const QVariant & value)
}
}


bool QSvgIOHandler::supportsOption(ImageOption option) const
{
switch(option)
Expand All @@ -226,7 +233,6 @@ bool QSvgIOHandler::supportsOption(ImageOption option) const
return false;
}


bool QSvgIOHandler::canRead(QIODevice *device)
{
QByteArray buf = device->peek(8);
Expand Down