OSDN Git Service

pics: reimplement ksvgtopng utility
authorIvailo Monev <xakepa10@gmail.com>
Tue, 1 Feb 2022 03:48:58 +0000 (05:48 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 1 Feb 2022 03:49:33 +0000 (05:49 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
pics/CMakeLists.txt
pics/ksvgtopng.cpp

index 30afe89..bda5701 100644 (file)
@@ -2,5 +2,5 @@ add_subdirectory( emoticons )
 
 set(ksvgtopng_SRCS ksvgtopng.cpp )
 add_executable(ksvgtopng ${ksvgtopng_SRCS})
-target_link_libraries(ksvgtopng ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTSVG_LIBRARY})
+target_link_libraries(ksvgtopng ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
 install(TARGETS ksvgtopng ${INSTALL_TARGETS_DEFAULT_ARGS} )
index d50ba84..3204e1b 100644 (file)
@@ -1,57 +1,52 @@
+/*  This file is part of the KDE Project
+    Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License version 2, as published by the Free Software Foundation.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
 #include <QApplication>
 #include <QImage>
-#include <QtCore/QString>
-
-#include <QtSvg/QSvgRenderer>
-#include <QPainter>
-#include <iostream>
-
-using std::cout;
-using std::endl;
+#include <QDebug>
 
 int main(int argc, char **argv)
 {
-       // Initialize Qt application, otherwise for some svg files it can segfault with:
-       // ASSERT failure in QFontDatabase: "A QApplication object needs to be 
-       // constructed before FontConfig is used."
-       QApplication app(argc, argv);
-
-       if(argc < 5)
-       {
-               cout << "Usage : ksvgtopng width height svgfilename outputfilename" << endl;
-               cout << "Please use full path name for svgfilename" << endl;
-               return -1;
-       }
-
-       int width = atoi(argv[1]);
-       int height = atoi(argv[2]);
-
-       QImage img(width, height, QImage::Format_ARGB32_Premultiplied);
-       img.fill(0);
-
-       QSvgRenderer renderer(QString::fromLocal8Bit(argv[3]));
-       if(renderer.isValid())
-       {
-               QPainter p(&img);
-               renderer.render(&p);
-/*
-               // Apply icon sharpening
-               double factor = 0;
-
-               if(width == 16)
-                       factor = 30;
-               else if(width == 32)
-                       factor = 20;
-               else if(width == 48)
-                       factor = 10;
-               else if(width == 64)
-                       factor = 5;
-
-               *img = KImageEffect::sharpen(*img, factor); // use QImageBlitz::sharpen()
-*/
-       }
-
-       img.save(argv[4], "PNG");
-
-       return 0;
+    // Initialize Qt application, otherwise for some svg files it can segfault with:
+    // ASSERT failure in QFontDatabase: "A QApplication object needs to be 
+    // constructed before FontConfig is used."
+    QApplication app(argc, argv);
+
+    if(argc < 5) {
+        qDebug() << "Usage : ksvgtopng width height svgfilename outputfilename";
+        qDebug() << "Please use full path name for svgfilename";
+        return 1;
+    }
+
+    QImage image(argv[3], "SVG");
+    if (image.isNull()) {
+        qWarning() << "Could not load" << argv[3];
+        return 2;
+    }
+
+    const int width = atoi(argv[1]);
+    const int height = atoi(argv[2]);
+    image = image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+
+    if (image.save(argv[4], "PNG") == false) {
+        qWarning() << "Could not save" << argv[4];
+        return 4;
+    }
+
+    return 0;
 }