KDEGames

renderelement.cpp
1/*
2 SPDX-FileCopyrightText: 2023 Friedrich W. H. Kossebau <kossebau@kde.org>
3
4 SPDX-License-Identifier: BSD-3-Clause
5*/
6
7#include <QCommandLineParser>
8#include <QGuiApplication>
9#include <QImage>
10#include <QPainter>
11#include <QString>
12#include <QSvgRenderer>
13
14#include <iostream>
15
16using namespace Qt::Literals;
17
18int main(int argc, char **argv)
19{
20 QGuiApplication app(argc, argv);
21
22 QCommandLineParser parser;
23 parser.addHelpOption();
24 parser.addPositionalArgument(u"svg_file"_s, u"Input SVG file"_s);
25 parser.addPositionalArgument(u"element_id"_s, u"SVG Element Id"_s);
26 parser.addPositionalArgument(u"width"_s, u"Width"_s);
27 parser.addPositionalArgument(u"height"_s, u"Height"_s);
28 parser.addPositionalArgument(u"png_file"_s, u"Output PNG file"_s);
29
30 parser.process(app);
31
32 const QStringList args = parser.positionalArguments();
33
34 if (args.size() < 5) {
35 std::cout << qPrintable(parser.helpText());
36 return -1;
37 }
38
39 const int width = args[2].toInt();
40 const int height = args[3].toInt();
41 const QString inputPath = args[0];
42 const QString elementId = args[1];
43 const QString outputPath = args[4];
44
45 QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
46 image.fill(Qt::transparent);
47
48 QSvgRenderer renderer(inputPath);
49 if (!renderer.isValid()) {
50 return -1;
51 }
52
53 QPainter p(&image);
54 renderer.render(&p, elementId);
55
56 image.save(outputPath, "PNG");
57
58 return 0;
59}
QCommandLineOption addHelpOption()
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
QString helpText() const const
QStringList positionalArguments() const const
void process(const QCoreApplication &app)
Format_ARGB32_Premultiplied
qsizetype size() const const
transparent
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:09:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.