summaryrefslogtreecommitdiffstats
path: root/share/extensions/setup_typography_canvas.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:29:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:29:01 +0000
commit35a96bde514a8897f6f0fcc41c5833bf63df2e2a (patch)
tree657d15a03cc46bd099fc2c6546a7a4ad43815d9f /share/extensions/setup_typography_canvas.py
parentInitial commit. (diff)
downloadinkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.tar.xz
inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.zip
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'share/extensions/setup_typography_canvas.py')
-rwxr-xr-xshare/extensions/setup_typography_canvas.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/share/extensions/setup_typography_canvas.py b/share/extensions/setup_typography_canvas.py
new file mode 100755
index 0000000..61d4539
--- /dev/null
+++ b/share/extensions/setup_typography_canvas.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# coding=utf-8
+#
+# Copyright (C) 2011 Felipe Correa da Silva Sanches
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+import inkex
+from inkex import Guide
+
+
+class SetupTypographyCanvas(inkex.EffectExtension):
+ def add_arguments(self, pars):
+ pars.add_argument("-e", "--emsize", type=int, default=1000)
+ pars.add_argument("-c", "--caps", type=int, default=700, help="Caps Height")
+ pars.add_argument("-x", "--xheight", type=int, default=500)
+ pars.add_argument("-a", "--ascender", type=int, default=750)
+ pars.add_argument("-d", "--descender", type=int, default=250)
+
+ def create_horizontal_guideline(self, name, position):
+ return self.svg.add(Guide().move_to(0, position, (0, 1)).update(inkscape__label=name))
+
+ def create_vertical_guideline(self, name, position):
+ return self.svg.add(Guide().move_to(position, 0, (1, 0)).update(inkscape__label=name))
+
+ def effect(self):
+ # Get all the options
+ emsize = self.options.emsize
+ ascender = self.options.ascender
+ caps = self.options.caps
+ xheight = self.options.xheight
+ descender = self.options.descender
+
+ # Get access to main SVG document element
+ 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
+ self.create_horizontal_guideline("baseline", baseline)
+ self.create_horizontal_guideline("ascender", baseline + ascender)
+ self.create_horizontal_guideline("caps", baseline + caps)
+ self.create_horizontal_guideline("xheight", baseline + xheight)
+ self.create_horizontal_guideline("descender", baseline - descender)
+
+ namedview = self.svg.namedview
+ namedview.set('inkscape:document-units', 'px')
+ namedview.set('inkscape:cx', str(emsize / 2.0))
+ namedview.set('inkscape:cy', str(emsize / 2.0))
+
+if __name__ == '__main__':
+ SetupTypographyCanvas().run()