summaryrefslogtreecommitdiff
path: root/qsvg.cc
blob: 2eb737e42acd3f52b8c5abd8e262cfee655bd25b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <QtCore/QCoreApplication>
#include <QImage>
#include <QSvgRenderer>
#include <QPainter>

/*
    hicg -- Harmattan Icon/Color Generator
    Copyright (C) 2011 Javier S. Pedro <maemo@javispedro.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program 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 Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using std::cerr;
using std::endl;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
	QStringList args = a.arguments();
	if (args.size() != 5) {
		cerr << "usage: qsvg <file.svg> <width> <height> <file.png>" << endl;
		return 1;
	}

	QSvgRenderer r(args[1]);

	if (!r.isValid()) {
		cerr << "Could not open source file." << endl;
		return 1;
	}

	int w, h;
	w = args[2].toInt();
	h = args[3].toInt();

	QImage i(w, h, QImage::Format_ARGB32);
	i.fill(QColor(Qt::transparent).rgba());

	QPainter p(&i);
	r.render(&p);

	if (!i.save(args[4], "png")) {
		cerr << "Could not save to destination file." << endl;
	}

	return 0;
}