blob: 8777b301961f594922560d696d115bf240da72a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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);
}
|