diff --git a/ChangeLog.txt b/ChangeLog.txt index 453a4cae12..48a4ae054b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,7 @@ pre-2.x.x - patch Qt6.5.3 to avoid transient child window resize bug on Windows - fix QuickParser bug when parseing attribute names not properly ignoreing all legal whitespace - make OPF parsing robust to alternative whitespace usage as well + - fix creation of thumbnails of svg images in SelectFiles and Image Report for macOS Sigil-2.0.2 diff --git a/src/Dialogs/ReportsWidgets/ImageFilesWidget.cpp b/src/Dialogs/ReportsWidgets/ImageFilesWidget.cpp index e897126de2..a7812eedd3 100644 --- a/src/Dialogs/ReportsWidgets/ImageFilesWidget.cpp +++ b/src/Dialogs/ReportsWidgets/ImageFilesWidget.cpp @@ -27,9 +27,7 @@ #include #include #include -#include #include -#include #include "sigil_exception.h" #include "BookManipulation/FolderKeeper.h" @@ -116,18 +114,7 @@ void ImageFilesWidget::SetupTable(int sort_column, Qt::SortOrder sort_order) QString path = resource->GetFullPath(); QImage image; if (resource->Type() == Resource::SVGResourceType) { - QString svgdata = Utility::ReadUnicodeTextFile(path); - // QtSvg has many issues with desc, title, and flowRoot tags - svgdata = Utility::FixupSvgForRendering(svgdata); - QSvgRenderer renderer(this); - renderer.load(svgdata.toUtf8()); - QSize sz = renderer.defaultSize(); - QImage svgimage(sz, QImage::Format_ARGB32); - // **must** fill it with tranparent pixels BEFORE trying to render anything - svgimage.fill(qRgba(0,0,0,0)); - QPainter painter(&svgimage); - renderer.render(&painter); - image = svgimage; + image = Utility::RenderSvgToImage(path); } else { image.load(path); } diff --git a/src/Dialogs/SelectFiles.cpp b/src/Dialogs/SelectFiles.cpp index 32f17506cf..d55229afc4 100644 --- a/src/Dialogs/SelectFiles.cpp +++ b/src/Dialogs/SelectFiles.cpp @@ -26,9 +26,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -206,19 +204,8 @@ void SelectFiles::SetImages() QImage image; if (type == Resource::ImageResourceType) { image.load(resource->GetFullPath()); - } else { // Svg - QString svgdata = Utility::ReadUnicodeTextFile(resource->GetFullPath()); - // QtSvg has many issues with desc, title, and flowRoot tags - svgdata = Utility::FixupSvgForRendering(svgdata); - QSvgRenderer renderer(this); - renderer.load(svgdata.toUtf8()); - QSize sz = renderer.defaultSize(); - QImage svgimage(sz, QImage::Format_ARGB32); - // **must** fill it with tranparent pixels BEFORE trying to render anything - svgimage.fill(qRgba(0,0,0,0)); - QPainter painter(&svgimage); - renderer.render(&painter); - image = svgimage; + } else { + image = Utility::RenderSvgToImage(resource->GetFullPath()); } QPixmap pixmap = QPixmap::fromImage(image); if (pixmap.height() > m_ThumbnailSize || pixmap.width() > m_ThumbnailSize) { diff --git a/src/Misc/Utility.cpp b/src/Misc/Utility.cpp index 02a77b0df4..cca7c489ed 100644 --- a/src/Misc/Utility.cpp +++ b/src/Misc/Utility.cpp @@ -59,6 +59,9 @@ #include #include #include +#include +#include +#include #include #include "sigil_constants.h" @@ -1528,3 +1531,20 @@ QString Utility::FixupSvgForRendering(const QString& data) } return svgdata.join(""); } + +QImage Utility::RenderSvgToImage(const QString& filepath) +{ + QString svgdata = Utility::ReadUnicodeTextFile(filepath); + // QtSvg has many issues with desc, title, and flowRoot tags + svgdata = Utility::FixupSvgForRendering(svgdata); + QSvgRenderer renderer; + renderer.load(svgdata.toUtf8()); + QSize sz = renderer.defaultSize(); + QImage svgimage(sz, QImage::Format_ARGB32); + // **must** fill it with tranparent pixels BEFORE trying to render anything + svgimage.fill(qRgba(0,0,0,0)); + QPainter painter(&svgimage); + renderer.render(&painter); + return svgimage; + +} diff --git a/src/Misc/Utility.h b/src/Misc/Utility.h index 4288d1cc09..b2f6bd7d43 100644 --- a/src/Misc/Utility.h +++ b/src/Misc/Utility.h @@ -32,11 +32,13 @@ #include #include #include +#include class QStringRef; class QWidget; class QMenu; + struct ExceptionBase; class Utility @@ -270,6 +272,7 @@ class Utility QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); static QString FixupSvgForRendering(const QString& data); + static QImage RenderSvgToImage(const QString& filepath); }; #endif // UTILITY_H