8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free#!/usr/bin/env python
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free# Written by Tavmjong Bah
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-freeimport inkex
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-freeimport re
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-freeclass C(inkex.Effect):
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free def __init__(self):
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free inkex.Effect.__init__(self)
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free self.OptionParser.add_option("-s", "--size", action="store", type="string", dest="desktop_size", default="16", help="Desktop size")
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free self.OptionParser.add_option("-w", "--width", action="store", type="int", dest="desktop_width", default="1920", help="Custom width")
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free self.OptionParser.add_option("-z", "--height", action="store", type="int", dest="desktop_height", default="1080", help="Custom height")
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free def effect(self):
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free size = self.options.desktop_size
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free width = self.options.desktop_width
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free height = self.options.desktop_height
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free if size != "Custom":
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free p = re.compile('([0-9]*)x([0-9]*)')
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free m = p.match( size )
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free width = int(m.group(1))
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free height = int(m.group(2))
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free root = self.document.getroot()
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free root.set("id", "SVGRoot")
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free root.set("width", str(width) + 'px')
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free root.set("height", str(height) + 'px')
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free root.set("viewBox", "0 0 " + str(width) + " " + str(height) )
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free namedview = root.find(inkex.addNS('namedview', 'sodipodi'))
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free if namedview is None:
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free namedview = inkex.etree.SubElement( root, inkex.addNS('namedview', 'sodipodi') );
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free namedview.set(inkex.addNS('document-units', 'inkscape'), 'px')
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free namedview.set(inkex.addNS('cx', 'inkscape'), str(width/2.0) )
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free namedview.set(inkex.addNS('cy', 'inkscape'), str(height/2.0) )
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-free
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-freec = C()
8ac705ee842a9087042c9ed7d126f39cadac9cectavmjong-freec.affect()