Skip to content

Commit

Permalink
fix: SVG rendering issue with filters attribute
Browse files Browse the repository at this point in the history
From: lxqt/libqtxdg#247
Use QImageReader instead of QSvgRender for XdgIconLoader
QSvgRender itself only support SVG 1.2 Tiny for rendering so SVGs
that more complex might not able to rendered properly. Thus, some
DE like KDE and DDE provides their own Qt icon engine and registered
them as for SVG icons, and seems that causes libqtxdg have issues, so
lxqt/libqtxdg/pull/246 was there.

But user or DE might still want to install or provide Qt image formats
plugins for better SVG files/icons rendering, using QSvgRender will
stop the Qt image formats plugin from being used.

Using QImageReader will still allow us avoiding the usage of Qt icon
engines, but kepts the ability to make Qt image formats plugin to
work properly.

This patch originally provided by @zccrs

Issue: linuxdeepin/developer-center#6480
  • Loading branch information
kegechen committed Dec 19, 2023
1 parent 803f929 commit 61a6b79
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
libqtxdg (3.12.0-1deepin1) unstable; urgency=medium

* release 3.12.0-1deepin1
* Add Patch to fix #6480

-- Mike Chen <[email protected]> Tue, 19 Dec 2023 13:49:08 +0800

libqtxdg (3.12.0-1) unstable; urgency=medium

* New upstream release.
Expand Down
48 changes: 48 additions & 0 deletions debian/patches/Fix_6480_svg_with_filters.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/src/xdgiconloader/xdgiconloader.cpp b/src/xdgiconloader/xdgiconloader.cpp
index 217eca1..95aecc8 100644
--- a/src/xdgiconloader/xdgiconloader.cpp
+++ b/src/xdgiconloader/xdgiconloader.cpp
@@ -53,7 +53,7 @@
#include <QImageReader>
#include <QXmlStreamReader>
#include <QFileSystemWatcher>
-#include <QSvgRenderer>
+#include <QBuffer>

#include <private/qhexstring_p.h>

@@ -829,12 +829,12 @@ QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State
pm = QPixmap(icnSize, icnSize);
pm.fill(Qt::transparent);

- QSvgRenderer renderer;
- if (renderer.load(filename))
- {
+ QImageReader imageReader(filename);
+ if (imageReader.canRead()) {
+ imageReader.setScaledSize(QSize(icnSize, icnSize));
QPainter p;
p.begin(&pm);
- renderer.render(&p, QRect(0, 0, icnSize, icnSize));
+ p.drawImage(0, 0, imageReader.read());
p.end();
}

@@ -928,11 +928,14 @@ QPixmap ScalableFollowsColorEntry::pixmap(const QSize &size, QIcon::Mode mode, Q

if (!svgBuffer.isEmpty())
{
- QSvgRenderer renderer;
- renderer.load(svgBuffer);
+ QBuffer buffer;
+ buffer.setData(svgBuffer);
+ buffer.open(QIODevice::ReadOnly);
+ QImageReader imageReader(&buffer);
+ imageReader.setScaledSize(QSize(icnSize, icnSize));
QPainter p;
p.begin(&pm);
- renderer.render(&p, QRect(0, 0, icnSize, icnSize));
+ p.drawImage(0, 0, imageReader.read());
p.end();
}
}
1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix_6480_svg_with_filters.patch

0 comments on commit 61a6b79

Please sign in to comment.