summaryrefslogtreecommitdiff
path: root/src/utils/avg_showsvg.py
blob: 915ae40ff00b2fb43a835789d19bd64a0bb18ef3 (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
60
61
62
63
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# libavg - Media Playback Engine.
# Copyright (C) 2003-2014 Ulrich von Zadow
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Current versions can be found at www.libavg.de
#

import sys

from libavg import avg, app


class ShowSVG(app.MainDiv):
    def onArgvParserCreated(self, parser):
        parser.set_usage("%prog [options] <svgFileName> <elementID>")

        parser.add_option("-s", "--size", dest="size",
                type="float", default=1.0,
                help="specify a factor for the size of the element [Default: 1.0]")
        parser.add_option("--save-image", dest="saveImage",
                action="store_true", default=False,
                help="save the image rendered to a png file")

    def onArgvParsed(self, options, args, parser):
        if len(args) != 2:
            parser.print_help()
            sys.exit(1)
        self._svgFName = args[0]
        self._svgID = args[1]
        self._size = options.size
        self._saveImage = options.saveImage

    def onInit(self):
        self.svg = avg.SVG(self._svgFName, True)
        img = self.svg.createImageNode(self._svgID, {"pos":(1,1), "parent":self},
                self._size)
        rect = avg.RectNode(fillcolor="808080", color="FFFFFF", fillopacity=1,
                pos=(0.5, 0.5), size=img.size+(1,1))
        self.insertChild(rect, 0)
        if self._saveImage:
            bmp = self.svg.renderElement(self._svgID, self._size)
            bmp.save(self._svgID+".png")


if __name__ == "__main__":
    app.App().run(ShowSVG(), app_resolution="1024x768")