1#include <QApplication>
2#include <QImage>
3#include <QtCore/QString>
4
5#include <QtSvg/QSvgRenderer>
6#include <QPainter>
7#include <iostream>
8
9using std::cout;
10using std::endl;
11
12int main(int argc, char **argv)
13{
14 // Initialize Qt application, otherwise for some svg files it can segfault with:
15 // ASSERT failure in QFontDatabase: "A QApplication object needs to be
16 // constructed before FontConfig is used."
17 QApplication app(argc, argv);
18
19 if(argc < 5)
20 {
21 cout << "Usage : ksvgtopng width height svgfilename outputfilename" << endl;
22 cout << "Please use full path name for svgfilename" << endl;
23 return -1;
24 }
25
26 int width = atoi(argv[1]);
27 int height = atoi(argv[2]);
28
29 QImage img(width, height, QImage::Format_ARGB32_Premultiplied);
30 img.fill(0);
31
32 QSvgRenderer renderer(QString::fromLocal8Bit(argv[3]));
33 if(renderer.isValid())
34 {
35 QPainter p(&img);
36 renderer.render(&p);
37/*
38 // Apply icon sharpening
39 double factor = 0;
40
41 if(width == 16)
42 factor = 30;
43 else if(width == 32)
44 factor = 20;
45 else if(width == 48)
46 factor = 10;
47 else if(width == 64)
48 factor = 5;
49
50 *img = KImageEffect::sharpen(*img, factor); // use QImageBlitz::sharpen()
51*/
52 }
53
54 img.save(argv[4], "PNG");
55
56 return 0;
57}
58