-
Notifications
You must be signed in to change notification settings - Fork 0
/
svgimageprovider.cpp
44 lines (33 loc) · 978 Bytes
/
svgimageprovider.cpp
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
44
#include <QFile>
#include <QPainter>
#include "nanosvg/src/nanosvg.h"
#include "qtnanosvg.hpp"
#include "svgimageprovider.hpp"
//////////////////////////////////////////////////////////////////////////////
SVGImageProvider::SVGImageProvider():
QQuickImageProvider(QQmlImageProviderBase::Pixmap)
{
}
//////////////////////////////////////////////////////////////////////////////
QPixmap SVGImageProvider::requestPixmap(QString const& id, QSize* const sz,
QSize const& rs)
{
QPixmap pm(*sz = rs);
do if (!pm.isNull())
{
QByteArray dat;
if (QFile f(id); f.open(QIODevice::ReadOnly))
{ if ((dat = f.readAll()).isEmpty()) break; } else break;
if (auto const nsi = nsvgParse(dat.data(), "px", 96))
{
pm.fill(Qt::transparent);
{
QPainter p(&pm);
p.setRenderHint(QPainter::Antialiasing);
drawSVGImage(&p, nsi, rs.width(), rs.height());
}
nsvgDelete(nsi);
}
} while (false);
return pm;
}