From e78edc8f66d94a44d0cb4e4c9db9a14690ef10b9 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 9 Oct 2014 11:21:47 +0200 Subject: Fix 'viewBox' and 'inkscape:document-units', add 'inkscape:cx' and 'inkscape:cy'. (bzr r13584) --- share/extensions/empty_page.py | 77 ++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 30 deletions(-) (limited to 'share') diff --git a/share/extensions/empty_page.py b/share/extensions/empty_page.py index dc16bab97..34dee7fc4 100644 --- a/share/extensions/empty_page.py +++ b/share/extensions/empty_page.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +# Rewritten by Tavmjong Bah to add correct viewBox, inkscape:cx, etc. attributes + import inkex class C(inkex.Effect): @@ -8,37 +10,52 @@ class C(inkex.Effect): self.OptionParser.add_option("-s", "--size", action="store", type="string", dest="page_size", default="a4", help="Page size") self.OptionParser.add_option("-o", "--orientation", action="store", type="string", dest="page_orientation", default="vertical", help="Page orientation") - def effect(self): + def effect(self): + + width = 300 + height = 300 + units = 'px' + + if self.options.page_size == "a5": + width = 148 + height= 210 + units = 'mm' + + if self.options.page_size == "a4": + width = 210 + height= 297 + units = 'mm' + + if self.options.page_size == "a3": + width = 297 + height= 420 + units = 'mm' + + if self.options.page_size == "letter": + width = 8.5 + height = 11 + units = 'in' + + if self.options.page_orientation == "horizontal": + width, height = height, width + + root = self.document.getroot() - root.set("width", "12in") - root.set("height", "12in") - if self.options.page_size == "a4" and self.options.page_orientation == "vertical": - root.set("width", "210mm") - root.set("height", "297mm") - if self.options.page_size == "a4" and self.options.page_orientation == "horizontal": - root.set("height", "210mm") - root.set("width", "297mm") - - if self.options.page_size == "a5" and self.options.page_orientation == "vertical": - root.set("width", "148mm") - root.set("height", "210mm") - if self.options.page_size == "a5" and self.options.page_orientation == "horizontal": - root.set("width", "210mm") - root.set("height", "148mm") - - if self.options.page_size == "a3" and self.options.page_orientation == "vertical": - root.set("width", "297mm") - root.set("height", "420mm") - if self.options.page_size == "a3" and self.options.page_orientation == "horizontal": - root.set("width", "420mm") - root.set("height", "297mm") - - if self.options.page_size == "letter" and self.options.page_orientation == "vertical": - root.set("width", "8.5in") - root.set("height", "11in") - if self.options.page_size == "letter" and self.options.page_orientation == "horizontal": - root.set("width", "11in") - root.set("height", "8.5in") + root.set("id", "SVGRoot") + root.set("width", str(width) + units) + root.set("height", str(height) + units) + root.set("viewBox", "0 0 " + str(width) + " " + str(height) ) + + namedview = root.find(inkex.addNS('namedview', 'sodipodi')) + if namedview is None: + namedview = inkex.etree.SubElement( root, inkex.addNS('namedview', 'sodipodi') ); + + namedview.set(inkex.addNS('document-units', 'inkscape'), units) + + # Until units are supported in 'cx', etc. + namedview.set(inkex.addNS('cx', 'inkscape'), str(self.uutounit( width, 'px' )/2.0 ) ) + namedview.set(inkex.addNS('cy', 'inkscape'), str(self.uutounit( height, 'px' )/2.0 ) ) + c = C() c.affect() -- cgit v1.2.3 From 19bb109f2149cc856f8d87b49b230f161a8880b3 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 9 Oct 2014 11:25:39 +0200 Subject: Add proper 'viewBox', set 'inkscape:document-units', set maximum em-size to 2048 as is typical in TrueType. (bzr r13585) --- share/extensions/setup_typography_canvas.inx | 10 +++++----- share/extensions/setup_typography_canvas.py | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'share') diff --git a/share/extensions/setup_typography_canvas.inx b/share/extensions/setup_typography_canvas.inx index 332a14ade..8e7739b5c 100644 --- a/share/extensions/setup_typography_canvas.inx +++ b/share/extensions/setup_typography_canvas.inx @@ -4,11 +4,11 @@ org.inkscape.typography.setuptypographycanvas inkex.py setup_typography_canvas.py - 1000 - 750 - 700 - 500 - 250 + 1000 + 750 + 700 + 500 + 250 all diff --git a/share/extensions/setup_typography_canvas.py b/share/extensions/setup_typography_canvas.py index 197aeb77e..a1000f2d1 100755 --- a/share/extensions/setup_typography_canvas.py +++ b/share/extensions/setup_typography_canvas.py @@ -69,6 +69,7 @@ class SetupTypographyCanvas(inkex.Effect): self.svg = self.document.getroot() self.svg.set("width", str(emsize)) self.svg.set("height", str(emsize)) + self.svg.set("viewBox", "0 0 " + str(emsize) + " " + str(emsize) ) baseline = descender # Create guidelines @@ -78,6 +79,12 @@ class SetupTypographyCanvas(inkex.Effect): self.create_horizontal_guideline("xheight", baseline+xheight) self.create_horizontal_guideline("descender", baseline-descender) + namedview = self.svg.find(inkex.addNS('namedview', 'sodipodi')) + namedview.set(inkex.addNS('document-units', 'inkscape'), 'px') + namedview.set(inkex.addNS('cx', 'inkscape'), str(emsize/2.0 )) + namedview.set(inkex.addNS('cy', 'inkscape'), str(emsize/2.0 )) + + if __name__ == '__main__': e = SetupTypographyCanvas() e.affect() -- cgit v1.2.3