File indexing completed on 2024-04-28 05:27:05

0001 #include <QGuiApplication>
0002 #include <QImage>
0003 #include <QString>
0004 
0005 #include <QPainter>
0006 #include <QSvgRenderer>
0007 #include <iostream>
0008 
0009 using std::cout;
0010 using std::endl;
0011 
0012 int main(int argc, char **argv)
0013 {
0014     // Initialize Qt application, otherwise for some svg files it can segfault with:
0015     // ASSERT failure in QFontDatabase: "A QApplication object needs to be
0016     // constructed before FontConfig is used."
0017     QGuiApplication app(argc, argv);
0018 
0019     if (argc < 5) {
0020         cout << "Usage : ksvgtopng width height svgfilename outputfilename" << endl;
0021         cout << "Please use full path name for svgfilename" << endl;
0022         return -1;
0023     }
0024 
0025     int width = atoi(argv[1]);
0026     int height = atoi(argv[2]);
0027 
0028     QImage img(width, height, QImage::Format_ARGB32_Premultiplied);
0029     img.fill(0);
0030 
0031     QSvgRenderer renderer(QString::fromLocal8Bit(argv[3]));
0032     if (renderer.isValid()) {
0033         QPainter p(&img);
0034         renderer.render(&p);
0035         /*
0036                 // Apply icon sharpening
0037                 double factor = 0;
0038 
0039                 if(width == 16)
0040                     factor = 30;
0041                 else if(width == 32)
0042                     factor = 20;
0043                 else if(width == 48)
0044                     factor = 10;
0045                 else if(width == 64)
0046                     factor = 5;
0047 
0048                 *img = KImageEffect::sharpen(*img, factor); // use QImageBlitz::sharpen()
0049         */
0050     }
0051 
0052     img.save(QString::fromLatin1(argv[4]), "PNG");
0053 
0054     return 0;
0055 }