summaryrefslogtreecommitdiffstats
path: root/share/extensions
diff options
context:
space:
mode:
authorAlexandre Prokoudine <alexandre.prokoudine@gmail.com>2008-11-22 19:25:18 +0000
committerprokoudine <prokoudine@users.sourceforge.net>2008-11-22 19:25:18 +0000
commit17474e4c69bf4c23674b9e5e6fed04329250a452 (patch)
treed95cdf90be9680b8bdd1ff16b5849c153002735c /share/extensions
parentMerge from fe-moved (diff)
downloadinkscape-17474e4c69bf4c23674b9e5e6fed04329250a452.tar.gz
inkscape-17474e4c69bf4c23674b9e5e6fed04329250a452.zip
added Guides Creator extension by Jonas Termeau (LP300877)
(bzr r6892)
Diffstat (limited to 'share/extensions')
-rw-r--r--share/extensions/Makefile.am2
-rw-r--r--share/extensions/guides_creator.inx43
-rwxr-xr-xshare/extensions/guides_creator.py144
3 files changed, 189 insertions, 0 deletions
diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am
index dd92eb24c..eb2a5d3c2 100644
--- a/share/extensions/Makefile.am
+++ b/share/extensions/Makefile.am
@@ -60,6 +60,7 @@ extensions = \
gimp_xcf.py \
grid_cartesian.py \
grid_polar.py \
+ guides_creator.py \
handles.py \
hpgl_output.py \
ill2svg.pl \
@@ -172,6 +173,7 @@ modules = \
gimp_xcf.inx \
grid_cartesian.inx \
grid_polar.inx \
+ guides_creator.inx \
handles.inx \
hpgl_output.inx \
inkscape_help_askaquestion.inx \
diff --git a/share/extensions/guides_creator.inx b/share/extensions/guides_creator.inx
new file mode 100644
index 000000000..24aebab67
--- /dev/null
+++ b/share/extensions/guides_creator.inx
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
+ <_name>Guides creator</_name>
+ <id>org.inkscape.effect.guidescreator</id>
+ <dependency type="executable" location="extensions">guides_creator.py</dependency>
+ <dependency type="executable" location="extensions">inkex.py</dependency>
+ <param name="vertical_guides" type="optiongroup" appearance="minimal" _gui-text="Vertical guides each">
+ <_option value="0">None</_option>
+ <_option value="2">1/2</_option>
+ <_option value="3">1/3</_option>
+ <_option value="4">1/4</_option>
+ <_option value="5">1/5</_option>
+ <_option value="6">1/6</_option>
+ <_option value="7">1/7</_option>
+ <_option value="8">1/8</_option>
+ <_option value="9">1/9</_option>
+ <_option value="10">1/10</_option>
+ </param>
+ <param name="horizontal_guides" type="optiongroup" appearance="minimal" _gui-text="Horizontal guides each">
+ <_option value="0">None</_option>
+ <_option value="2">1/2</_option>
+ <_option value="3">1/3</_option>
+ <_option value="4">1/4</_option>
+ <_option value="5">1/5</_option>
+ <_option value="6">1/6</_option>
+ <_option value="7">1/7</_option>
+ <_option value="8">1/8</_option>
+ <_option value="9">1/9</_option>
+ <_option value="10">1/10</_option>
+ </param>
+ <param name="start_from_edges" type="boolean" _gui-text="Start from edges">false</param>
+ <param name="delete_existing_guides" type="boolean" _gui-text="Delete existing guides">false</param>
+ <effect>
+ <object-type>all</object-type>
+ <effects-menu>
+ <submenu _name="Render"/>
+ </effects-menu>
+ </effect>
+ <script>
+ <command reldir="extensions" interpreter="python">guides_creator.py</command>
+ </script>
+</inkscape-extension>
+
diff --git a/share/extensions/guides_creator.py b/share/extensions/guides_creator.py
new file mode 100755
index 000000000..2807089f3
--- /dev/null
+++ b/share/extensions/guides_creator.py
@@ -0,0 +1,144 @@
+#!/usr/bin/env python
+'''
+Guides Creator v1.0 (21/11/2008)
+
+Copyright (C) 2008 Jonas Termeau jonas.termeau **AT** gmail.com
+
+## This basic extension allows you to automatically draw guides in inkscape.
+
+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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+'''
+
+# inspired by hello_world turorial by Blackhex and Rubikcube
+# (http://wiki.inkscape.org/wiki/index.php/PythonEffectTutorial)
+
+# Making an .INX file : http://wiki.inkscape.org/wiki/index.php/MakingAnINX
+# see also http://codespeak.net/lxml/dev/tutorial.html#namespaces for XML namespaces manipulation
+
+# # # # # # # #
+# TODO: [v2.0]
+# -implement vertical and horizontal golden number proportions (987/610) based guides
+#
+# # # # # # # #
+
+
+# # # extension's begining # # #
+
+# These two lines are only needed if you don't put the script directly into
+# the installation directory
+import sys
+sys.path.append('/usr/share/inkscape/extensions')
+
+# We will use the inkex module with the predefined Effect base class.
+import inkex
+from simplestyle import *
+
+from xml.etree import ElementTree as ET
+
+
+
+class Guides_Creator(inkex.Effect):
+
+ def __init__(self):
+ """
+ Constructor.
+ Defines options of the script.
+ """
+ # Call the base class constructor.
+ inkex.Effect.__init__(self)
+ # Define string option "--vertical_guides" with default value 0.
+ self.OptionParser.add_option('--vertical_guides',
+ action = 'store',type = 'string',
+ dest = 'vertical_guides',default = 0,
+ help = 'Vertical guides each:')
+
+ # Define string option "--horizontal_guides" with default value 0.
+ self.OptionParser.add_option('--horizontal_guides',
+ action = 'store',type = 'string',
+ dest = 'horizontal_guides',default = 0,
+ help = 'Horizontal guides each:')
+
+ # Define string option "--delete_existing_guides" with default value 0.
+ self.OptionParser.add_option('--delete_existing_guides',
+ action = 'store',type = 'inkbool',
+ dest = 'delete_existing_guides',default = False,
+ help = 'Delete existing guides')
+
+ # Define string option "--start_from_edges" with default value 0.
+ self.OptionParser.add_option('--start_from_edges',
+ action = 'store',type = 'inkbool',
+ dest = 'start_from_edges',default = False,
+ help = 'Start from edges')
+
+ def effect(self):
+
+ # Get script's options value.
+ from_edges = self.options.start_from_edges
+ delete_existing = self.options.delete_existing_guides
+ h_division = int(self.options.horizontal_guides)
+ v_division = int(self.options.vertical_guides)
+
+ # Get access to main SVG document element and get its dimensions.
+ svg = self.document.getroot()
+
+ # getting the width and height attributes of the canvas
+ width = inkex.unittouu(svg.get('width'))
+ height = inkex.unittouu(svg.attrib['height'])
+
+ # getting the parent tag of the guide
+ nv = self.document.xpath('/svg:svg/sodipodi:namedview',namespaces=inkex.NSS)[0]
+
+ if (delete_existing):
+ # getting all the guides
+ children = self.document.xpath('/svg:svg/sodipodi:namedview/sodipodi:guide',namespaces=inkex.NSS)
+
+ # removing each guides
+ for element in children:
+ nv.remove(element)
+
+ if (from_edges):
+ var = 1
+ else:
+ var = 0
+
+ # creating vertical guides
+ if (v_division > 0):
+ for v in range(0,v_division-1+2*var):
+ # setting up the guide's attributes (id is generated automatically)
+ position = str(round((width / v_division) + (v - var) * (width / v_division),4)) + ",0"
+ orientation = str(round(height,4)) + ",0"
+
+ # Create a sodipodi:guide node
+ # (look into inkex's namespaces to find 'sodipodi' value in order to make a "sodipodi:guide" tag)
+ # see NSS array in file inkex.py for the other namespaces
+ inkex.etree.SubElement(nv,'{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}guide',{'position':position,'orientation':orientation})
+
+ # creating horizontal guides
+ if (h_division > 0):
+ for h in range(0,h_division-1+2*var):
+ # setting up the guide's attributes (id is generated automatically)
+ position = "0," + str(round((height / h_division) + (h - var) * (height / h_division),4))
+ orientation = "0," + str(round(width,4))
+
+ # Create a sodipodi:guide node
+ # (look into inkex's namespaces to find 'sodipodi' value in order to make a "sodipodi:guide" tag)
+ # see NSS array in file inkex.py for the other namespaces
+ inkex.etree.SubElement(nv,'{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}guide',{'position':position,'orientation':orientation})
+
+# Create effect instance and apply it.
+effect = Guides_Creator()
+effect.affect()
+
+## end of file guide_creator.py ##