empty_page.py revision 09745d1696468b1f7b1fe01727aa49f448c6e199
460N/A#!/usr/bin/env python
460N/A
460N/A# Rewritten by Tavmjong Bah to add correct viewBox, inkscape:cx, etc. attributes
460N/A
460N/Aimport inkex
460N/A
460N/Aclass C(inkex.Effect):
460N/A def __init__(self):
460N/A inkex.Effect.__init__(self)
460N/A self.OptionParser.add_option("-s", "--size", action="store", type="string", dest="page_size", default="a4", help="Page size")
460N/A self.OptionParser.add_option("-o", "--orientation", action="store", type="string", dest="page_orientation", default="vertical", help="Page orientation")
460N/A
460N/A def effect(self):
460N/A
460N/A width = 300
460N/A height = 300
460N/A units = 'px'
460N/A
460N/A if self.options.page_size == "a5":
460N/A width = 148
460N/A height= 210
460N/A units = 'mm'
3477N/A
460N/A if self.options.page_size == "a4":
460N/A width = 210
460N/A height= 297
460N/A units = 'mm'
783N/A
783N/A if self.options.page_size == "a3":
1244N/A width = 297
1472N/A height= 420
618N/A units = 'mm'
1244N/A
1244N/A if self.options.page_size == "letter":
460N/A width = 8.5
844N/A height = 11
1472N/A units = 'in'
460N/A
1258N/A if self.options.page_orientation == "horizontal":
460N/A width, height = height, width
460N/A
460N/A
460N/A root = self.document.getroot()
460N/A root.set("id", "SVGRoot")
460N/A root.set("width", str(width) + units)
460N/A root.set("height", str(height) + units)
460N/A root.set("viewBox", "0 0 " + str(width) + " " + str(height) )
1472N/A
1472N/A namedview = root.find(inkex.addNS('namedview', 'sodipodi'))
1472N/A if namedview is None:
1472N/A namedview = inkex.etree.SubElement( root, inkex.addNS('namedview', 'sodipodi') );
1472N/A
1472N/A namedview.set(inkex.addNS('document-units', 'inkscape'), units)
1472N/A
1472N/A # Until units are supported in 'cx', etc.
460N/A namedview.set(inkex.addNS('cx', 'inkscape'), str(self.uutounit( width, 'px' )/2.0 ) )
460N/A namedview.set(inkex.addNS('cy', 'inkscape'), str(self.uutounit( height, 'px' )/2.0 ) )
460N/A
460N/A
460N/Ac = C()
1472N/Ac.affect()
1472N/A