diff --git a/src/widget/paintable.cpp b/src/widget/paintable.cpp index d235aad6b64a..b7e78135f1a2 100644 --- a/src/widget/paintable.cpp +++ b/src/widget/paintable.cpp @@ -69,29 +69,7 @@ Paintable::Paintable(const PixmapSource& source, DrawMode mode, double scaleFact } else { return; } -#ifdef __APPLE__ - // Apple does Retina scaling behind the scenes, so we also pass a - // Paintable::FIXED image. On the other targets, it is better to - // cache the pixmap. We do not do this for TILE and color schemas. - // which can result in a correct but possibly blurry picture at a - // Retina display. This can be fixed when switching to QT5 - if (mode == TILE || WPixmapStore::willCorrectColors()) { -#else - if (mode == TILE || mode == Paintable::FIXED || WPixmapStore::willCorrectColors()) { -#endif - // The SVG renderer doesn't directly support tiling, so we render - // it to a pixmap which will then get tiled. - QImage copy_buffer(pSvg->defaultSize() * scaleFactor, QImage::Format_ARGB32); - copy_buffer.fill(0x00000000); // Transparent black. - QPainter painter(©_buffer); - pSvg->render(&painter); - WPixmapStore::correctImageColors(©_buffer); - - m_pPixmap.reset(new QPixmap(copy_buffer.size())); - m_pPixmap->convertFromImage(copy_buffer); - } else { - m_pSvg = std::move(pSvg); - } + m_pSvg = std::move(pSvg); } } @@ -253,7 +231,19 @@ void Paintable::drawInternal(const QRectF& targetRect, QPainter* pPainter, // << targetRect << sourceRect; if (m_pSvg) { if (m_drawMode == TILE) { - qWarning() << "Tiled SVG should have been rendered to pixmap!"; + if (!m_pPixmap) { + // qDebug() << "Paintable cache miss"; + qreal devicePixelRatio = pPainter->device()->devicePixelRatio(); + m_pPixmap = std::make_unique(m_pSvg->defaultSize()); + m_pPixmap->setDevicePixelRatio(devicePixelRatio); + m_pPixmap->fill(Qt::transparent); + auto pixmapPainter = QPainter(m_pPixmap.get()); + m_pSvg->render(&pixmapPainter); + mayCorrectColors(); + } + // The SVG renderer doesn't directly support tiling, so we render + // it to a pixmap which will then get tiled. + pPainter->drawTiledPixmap(targetRect, *m_pPixmap); } else { if (!m_pPixmap || m_pPixmap->size() != targetRect.size().toSize() || @@ -266,6 +256,7 @@ void Paintable::drawInternal(const QRectF& targetRect, QPainter* pPainter, auto pixmapPainter = QPainter(m_pPixmap.get()); m_pSvg->setViewBox(sourceRect); m_pSvg->render(&pixmapPainter); + mayCorrectColors(); m_lastSourceRect = sourceRect; } pPainter->drawPixmap(targetRect.topLeft(), *m_pPixmap); @@ -309,3 +300,11 @@ QString Paintable::getAltFileName(const QString& fileName) { return fileName; } } + +void Paintable::mayCorrectColors() { + if (WPixmapStore::willCorrectColors()) { + QImage image = m_pPixmap->toImage(); + WPixmapStore::correctImageColors(&image); + m_pPixmap->convertFromImage(image); + } +} diff --git a/src/widget/paintable.h b/src/widget/paintable.h index 3097361784eb..c2779a0a7f44 100644 --- a/src/widget/paintable.h +++ b/src/widget/paintable.h @@ -53,6 +53,7 @@ class Paintable { private: void drawInternal(const QRectF& targetRect, QPainter* pPainter, const QRectF& sourceRect); + void mayCorrectColors(); std::unique_ptr m_pPixmap; std::unique_ptr m_pSvg;