~ubuntu-branches/ubuntu/wily/kde-cli-tools/wily-proposed

« back to all changes in this revision

Viewing changes to ksvgtopng/ksvgtopng.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-10-14 13:47:15 UTC
  • Revision ID: package-import@ubuntu.com-20141014134715-l1r8o4voiw7s909q
Tags: upstream-5.1.0.1
ImportĀ upstreamĀ versionĀ 5.1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <QApplication>
 
2
#include <QImage>
 
3
#include <QtCore/QString>
 
4
 
 
5
#include <QtSvg/QSvgRenderer>
 
6
#include <QPainter>
 
7
#include <iostream>
 
8
 
 
9
using std::cout;
 
10
using std::endl;
 
11
 
 
12
int 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
}