summaryrefslogtreecommitdiff
path: root/tools/kde-dolphin-thumbnailer/resvgthumbnailer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/kde-dolphin-thumbnailer/resvgthumbnailer.cpp')
-rw-r--r--tools/kde-dolphin-thumbnailer/resvgthumbnailer.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/kde-dolphin-thumbnailer/resvgthumbnailer.cpp b/tools/kde-dolphin-thumbnailer/resvgthumbnailer.cpp
new file mode 100644
index 0000000..8777b30
--- /dev/null
+++ b/tools/kde-dolphin-thumbnailer/resvgthumbnailer.cpp
@@ -0,0 +1,43 @@
+#include "resvgthumbnailer.h"
+
+#include <ResvgQt.h>
+
+#include <QPainter>
+
+extern "C"
+{
+ Q_DECL_EXPORT ThumbCreator *new_creator()
+ {
+ return new ResvgThumbnailer;
+ }
+}
+
+bool ResvgThumbnailer::create(const QString& path, int width, int heigth, QImage& img)
+{
+ ResvgRenderer renderer(path);
+ if (!renderer.isValid() || renderer.isEmpty()) {
+ return false;
+ }
+
+ const double ratio = static_cast<double>(renderer.defaultSize().height()) /
+ static_cast<double>(renderer.defaultSize().width());
+ if (width < heigth)
+ heigth = qRound(ratio * width);
+ else
+ width = qRound(heigth / ratio);
+
+ QImage previewImage(width, heigth, QImage::Format_ARGB32_Premultiplied);
+ previewImage.fill(Qt::transparent);
+
+ QPainter p(&previewImage);
+ renderer.render(&p);
+ p.end();
+
+ img = previewImage;
+ return true;
+}
+
+ThumbCreator::Flags ResvgThumbnailer::flags() const
+{
+ return (Flags)(None);
+}