diff options
| author | Peter Lieverdink <me@cafuego.net> | 2011-05-01 01:57:27 +0000 |
|---|---|---|
| committer | Peter Lieverdink <me@cafuego.net> | 2011-05-01 01:57:27 +0000 |
| commit | 68b997a99d3532bd0d5c92eb9ce04094b88c8dca (patch) | |
| tree | ea15dfecc0109e5de87d96786d24c8be208aa86e | |
| parent | emf import. support for clip rectangle (Bug 383180) (diff) | |
| download | inkscape-68b997a99d3532bd0d5c92eb9ce04094b88c8dca.tar.gz inkscape-68b997a99d3532bd0d5c92eb9ce04094b88c8dca.zip | |
Replace guides creator with upstream guides creator version 2.31.
(bzr r10193.1.1)
| -rw-r--r-- | share/extensions/guides_creator.inx | 117 | ||||
| -rwxr-xr-x | share/extensions/guides_creator.py | 387 |
2 files changed, 404 insertions, 100 deletions
diff --git a/share/extensions/guides_creator.inx b/share/extensions/guides_creator.inx index 11aa84e11..34eef4fb3 100644 --- a/share/extensions/guides_creator.inx +++ b/share/extensions/guides_creator.inx @@ -1,44 +1,93 @@ -<?xml version="1.0" encoding="UTF-8"?> -<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> +<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="preset" type="enum" _gui-text="Preset:"> - <_item value="custom">Custom...</_item> - <_item value="golden">Golden ratio</_item> - <_item value="3;3">Rule-of-third</_item> - </param> - <param name="vertical_guides" type="enum" _gui-text="Vertical guide each:"> - <_item value="0">None</_item> - <_item value="2">1/2</_item> - <_item value="3">1/3</_item> - <_item value="4">1/4</_item> - <_item value="5">1/5</_item> - <_item value="6">1/6</_item> - <_item value="7">1/7</_item> - <_item value="8">1/8</_item> - <_item value="9">1/9</_item> - <_item value="10">1/10</_item> - </param> - <param name="horizontal_guides" type="enum" _gui-text="Horizontal guide each:"> - <_item value="0">None</_item> - <_item value="2">1/2</_item> - <_item value="3">1/3</_item> - <_item value="4">1/4</_item> - <_item value="5">1/5</_item> - <_item value="6">1/6</_item> - <_item value="7">1/7</_item> - <_item value="8">1/8</_item> - <_item value="9">1/9</_item> - <_item value="10">1/10</_item> - </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> + <param name="tab" type="notebook"> + <page name="regular_guides" _gui-text="Regular guides"> + <param name="guides_preset" type="enum" appearance="minimal" _gui-text="Guides preset"> + <item value="custom">Custom...</item> + <item value="golden">Golden ratio</item> + <item value="3;3">Rule-of-third</item> + </param> + <param name="vertical_guides" type="int" min="1" max="100" _gui-text="Columns">2</param> + <param name="horizontal_guides" type="int" min="1" max="100" _gui-text="Rows">3</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> + </page> + <page name="diagonal_guides" _gui-text="Diagonal guides"> + <param name="ul" type="boolean" _gui-text="Upper left corner">false</param> + <param name="ur" type="boolean" _gui-text="Upper right corner">false</param> + <param name="ll" type="boolean" _gui-text="Lower left corner">false</param> + <param name="lr" type="boolean" _gui-text="Lower right corner">false</param> + <param name="delete_existing_guides2" type="boolean" _gui-text="Delete existing guides">false</param> + </page> + <page name="margins" _gui-text="Margins"> + <param name="margins_preset" type="enum" appearance="minimal" _gui-text="Margins preset"> + <item value="custom">Custom...</item> + <item value="book_left">Left book page</item> + <item value="book_right">Right book page</item> + </param> + <param name="header_margin" type="enum" appearance="minimal" _gui-text="Header margin"> + <item value="10">1/10</item> + <item value="9">1/9</item> + <item value="8">1/8</item> + <item value="7">1/7</item> + <item value="6">1/6</item> + <item value="5">1/5</item> + <item value="4">1/4</item> + <item value="3">1/3</item> + <item value="2">1/2</item> + <item value="0">None</item> + </param> + <param name="footer_margin" type="enum" appearance="minimal" _gui-text="Footer margin"> + <item value="10">1/10</item> + <item value="9">1/9</item> + <item value="8">1/8</item> + <item value="7">1/7</item> + <item value="6">1/6</item> + <item value="5">1/5</item> + <item value="4">1/4</item> + <item value="3">1/3</item> + <item value="2">1/2</item> + <item value="0">None</item> + </param> + <param name="left_margin" type="enum" appearance="minimal" _gui-text="Left margin"> + <item value="10">1/10</item> + <item value="9">1/9</item> + <item value="8">1/8</item> + <item value="7">1/7</item> + <item value="6">1/6</item> + <item value="5">1/5</item> + <item value="4">1/4</item> + <item value="3">1/3</item> + <item value="2">1/2</item> + <item value="0">None</item> + </param> + <param name="right_margin" type="enum" appearance="minimal" _gui-text="Right margin"> + <item value="10">1/10</item> + <item value="9">1/9</item> + <item value="8">1/8</item> + <item value="7">1/7</item> + <item value="6">1/6</item> + <item value="5">1/5</item> + <item value="4">1/4</item> + <item value="3">1/3</item> + <item value="2">1/2</item> + <item value="0">None</item> + </param> + + <param name="vertical_subdivisions" type="int" min="1" max="100" _gui-text="Columns">2</param> + <param name="horizontal_subdivisions" type="int" min="1" max="100" _gui-text="Rows">3</param> + <param name="start_from_edges2" type="boolean" _gui-text="Start from edges">false</param> + <param name="delete_existing_guides3" type="boolean" _gui-text="Delete existing guides">false</param> + + </page> + </param> <effect> <object-type>all</object-type> <effects-menu> - <submenu _name="Render"/> + <submenu _name="Guides"/> </effects-menu> </effect> <script> diff --git a/share/extensions/guides_creator.py b/share/extensions/guides_creator.py index 96f2557ee..c70c4dc1a 100755 --- a/share/extensions/guides_creator.py +++ b/share/extensions/guides_creator.py @@ -1,18 +1,22 @@ #!/usr/bin/env python ''' -Guides Creator v2.0 (25/11/2008) +Guides Creator v2.31 (05/07/2009) http://code.google.com/p/inkscape-guides-creator/ Copyright (C) 2008 Jonas Termeau - jonas.termeau **AT** gmail.com -Thanks to Bernard Gray - bernard.gray **AT** gmail.com +Thanks to: + +Bernard Gray - bernard.gray **AT** gmail.com (python helping) +Jamie Heames (english translation issues) +~suv (bug report in v2.3) +http://www.gutenberg.eu.org/publications/ (9x9 margins settings) ## 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. +the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -24,7 +28,7 @@ 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 +# 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 @@ -32,7 +36,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # # # # # # # TODO: See http://code.google.com/p/inkscape-guides-creator/wiki/Roadmap -# # # # # # # # # @@ -49,17 +52,19 @@ from simplestyle import * from xml.etree import ElementTree as ET -# for golden number formulae +# for golden number formula and diagonal guides from math import sqrt +from math import cos +from math import sin # for printing debugging output import gettext _ = gettext.gettext def printDebug(string): - inkex.errormsg(_(string)) + inkex.errormsg(_(str(string))) -def drawVerticalGuides(division,w,h,edges,parent): +def drawVerticalGuides(division,w,h,edges,parent,vertical_shift=0): if (division > 0): if (edges): var = 1 @@ -68,12 +73,12 @@ def drawVerticalGuides(division,w,h,edges,parent): for v in range(0,division-1+2*var): # setting up the guide's attributes (id is generated automatically) - position = str(round((w / division) + (v - var) * (w / division),4)) + ",0" + position = str(round((w / division) + (v - var) * (w / division) + vertical_shift,4)) + ",0" orientation = str(round(h,4)) + ",0" createGuide(position,orientation,parent) -def drawHorizontalGuides(division,w,h,edges,parent): +def drawHorizontalGuides(division,w,h,edges,parent,horizontal_shift=0): if (division > 0): if (edges): var = 1 @@ -82,9 +87,9 @@ def drawHorizontalGuides(division,w,h,edges,parent): for x in range(0,division-1+2*var): # setting up the guide's attributes (id is generated automatically) - position = "0," + str(round((h / division) + (x - var) * (h / division),4)) + position = "0," + str(round((h / division) + (x - var) * (h / division) + horizontal_shift,4)) orientation = "0," + str(round(w,4)) - + createGuide(position,orientation,parent) def createGuide(position,orientation,parent): @@ -96,7 +101,6 @@ def createGuide(position,orientation,parent): def getVerticalDivisionsFromPreset(preset): # take a "string1;string2" preset # and return "string1" - str_array = preset.split(';') result = int(str_array[0]) @@ -105,12 +109,22 @@ def getVerticalDivisionsFromPreset(preset): def getHorizontalDivisionsFromPreset(preset): # take a "string1;string2" preset # and return "string2" - str_array = preset.split(';') result = int(str_array[1]) return result +def deleteAllGuides(document): + # getting the parent's tag of the guides + nv = document.xpath('/svg:svg/sodipodi:namedview',namespaces=inkex.NSS)[0] + + # getting all the guides + children = document.xpath('/svg:svg/sodipodi:namedview/sodipodi:guide',namespaces=inkex.NSS) + + # removing each guides + for element in children: + nv.remove(element) + class Guides_Creator(inkex.Effect): def __init__(self): @@ -121,10 +135,16 @@ class Guides_Creator(inkex.Effect): # Call the base class constructor. inkex.Effect.__init__(self) + # Define option for the tab. + self.OptionParser.add_option("--tab", + action="store",type="string", + dest="tab", default="regular_guides", + help="") + # Define string option "--preset" with default value 'custom'. - self.OptionParser.add_option('--preset', + self.OptionParser.add_option('--guides_preset', action = 'store',type = 'string', - dest = 'preset',default = 'custom', + dest = 'guides_preset',default = 'custom', help = 'Preset') # Define string option "--vertical_guides" with default value '0'. @@ -139,95 +159,330 @@ class Guides_Creator(inkex.Effect): dest = 'horizontal_guides',default = 0, help = 'Horizontal guides each:') - # Define string option "--start_from_edges" with default value False. + # Define boolean option "--start_from_edges" with default value False. self.OptionParser.add_option('--start_from_edges', action = 'store',type = 'inkbool', dest = 'start_from_edges',default = False, help = 'Start from edges') - # Define string option "--delete_existing_guides" with default value False. + # Define boolean option "--delete_existing_guides" with default value False. self.OptionParser.add_option('--delete_existing_guides', action = 'store',type = 'inkbool', dest = 'delete_existing_guides',default = False, help = 'Delete existing guides') + + # Define boolean option "--upper_left_corner" with default value False. + self.OptionParser.add_option('--ul', + action = 'store',type = 'inkbool', + dest = 'ul',default = False, + help = 'Upper left corner') + + # Define boolean option "--upper_right_corner" with default value False. + self.OptionParser.add_option('--ur', + action = 'store',type = 'inkbool', + dest = 'ur',default = False, + help = 'Upper right corner') + + # Define boolean option "--lower_left_corner" with default value False. + self.OptionParser.add_option('--ll', + action = 'store',type = 'inkbool', + dest = 'll',default = False, + help = 'Lower left corner') + + # Define boolean option "--upper_left_corner" with default value False. + self.OptionParser.add_option('--lr', + action = 'store',type = 'inkbool', + dest = 'lr',default = False, + help = 'Lower right corner') + + # Define boolean option "--delete_existing_guides2" with default value False. + self.OptionParser.add_option('--delete_existing_guides2', + action = 'store',type = 'inkbool', + dest = 'delete_existing_guides2',default = False, + help = 'Delete existing guides') + + # Define string option "--margins_preset" with default value 'custom'. + self.OptionParser.add_option('--margins_preset', + action = 'store',type = 'string', + dest = 'margins_preset',default = 'custom', + help = 'Margins preset') + + # Define boolean option "--delete_existing_guides3" with default value False. + self.OptionParser.add_option('--delete_existing_guides3', + action = 'store',type = 'inkbool', + dest = 'delete_existing_guides3',default = False, + help = 'Delete existing guides') + + # Define string option "--vertical_subdivisions" with default value '0'. + self.OptionParser.add_option('--vertical_subdivisions', + action = 'store',type = 'string', + dest = 'vertical_subdivisions',default = 0, + help = 'Vertical subdivisions') + + # Define string option "--horizontal_subdivisions" with default value '0'. + self.OptionParser.add_option('--horizontal_subdivisions', + action = 'store',type = 'string', + dest = 'horizontal_subdivisions',default = 0, + help = 'Horizontal subdivisions') + + # Define string option "--header_margin" with default value '6'. + self.OptionParser.add_option('--header_margin', + action = 'store',type = 'string', + dest = 'header_margin',default = 6, + help = 'Header margin') + + # Define string option "--footer_margin" with default value '6'. + self.OptionParser.add_option('--footer_margin', + action = 'store',type = 'string', + dest = 'footer_margin',default = 6, + help = 'Footer margin') + + # Define string option "--left_margin" with default value '6'. + self.OptionParser.add_option('--left_margin', + action = 'store',type = 'string', + dest = 'left_margin',default = 6, + help = 'Left margin') + + # Define string option "--right_margin" with default value '6'. + self.OptionParser.add_option('--right_margin', + action = 'store',type = 'string', + dest = 'right_margin',default = 6, + help = 'Right margin') + + # Define boolean option "--start_from_edges2" with default value False. + self.OptionParser.add_option('--start_from_edges2', + action = 'store',type = 'inkbool', + dest = 'start_from_edges2',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 + + tab = self.options.tab + + # first tab + guides_preset = self.options.guides_preset h_division = int(self.options.horizontal_guides) v_division = int(self.options.vertical_guides) - preset = self.options.preset + from_edges = self.options.start_from_edges + delete_existing = self.options.delete_existing_guides - # Get access to main SVG document element and get its dimensions. + # second tab + upper_left = self.options.ul + upper_right = self.options.ur + lower_left = self.options.ll + lower_right = self.options.lr + delete_existing2 = self.options.delete_existing_guides2 + + # third tab + margins_preset = self.options.margins_preset + header_margin = int(self.options.header_margin) + footer_margin = int(self.options.footer_margin) + left_margin = int(self.options.left_margin) + right_margin = int(self.options.right_margin) + h_subdiv = int(self.options.horizontal_subdivisions) + v_subdiv = int(self.options.vertical_subdivisions) + from_edges2 = self.options.start_from_edges2 + delete_existing3 = self.options.delete_existing_guides3 + + # getting the main SVG document element (canvas) 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 + # getting edges coordinates + h_orientation = '0,' + str(round(width,4)) + v_orientation = str(round(height,4)) + ',0' + + # getting parent tag of the guides 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) + if (tab == "\"regular_guides\""): + + if (delete_existing): + deleteAllGuides(self.document) - # removing each guides - for element in children: - nv.remove(element) + if (guides_preset == 'custom'): - if (preset == 'custom'): + if ((v_division == 0) and (from_edges)): + v_division = 1 - # creating vertical guides - drawVerticalGuides(v_division,width,height,from_edges,nv) + if ((h_division == 0) and (from_edges)): + h_division = 1 + + # creating vertical guides + drawVerticalGuides(v_division,width,height,from_edges,nv) + + # creating horizontal guides + drawHorizontalGuides(h_division,width,height,from_edges,nv) + + elif (guides_preset == 'golden'): + + gold = (1 + sqrt(5)) / 2 - # creating horizontal guides - drawHorizontalGuides(h_division,width,height,from_edges,nv) + # horizontal golden guides + position1 = '0,' + str(height / gold) + position2 = '0,'+ str(height - (height / gold)) - elif (preset == 'golden'): + createGuide(position1,h_orientation,nv) + createGuide(position2,h_orientation,nv) - gold = (1 + sqrt(5)) / 2 - - # horizontal golden guides - position1 = '0,' + str(height / gold) - position2 = '0,'+ str(height - (height / gold)) - h_orientation = '0,' + str(round(width,4)) + # vertical golden guides + position1 = str(width / gold) + ',0' + position2 = str(width - (width / gold)) + ',0' - createGuide(position1,h_orientation,nv) - createGuide(position2,h_orientation,nv) + createGuide(position1,v_orientation,nv) + createGuide(position2,v_orientation,nv) - # vertical golden guides - position1 = str(width / gold) + ',0' - position2 = str(width - (width / gold)) + ',0' - v_orientation = str(round(height,4)) + ',0' + if (from_edges): + # horizontal borders + createGuide('0,' + str(height),h_orientation,nv) + createGuide(str(height) + ',0',h_orientation,nv) - createGuide(position1,v_orientation,nv) - createGuide(position2,v_orientation,nv) + # vertical borders + createGuide('0,' + str(width),v_orientation,nv) + createGuide(str(width) + ',0',v_orientation,nv) - if (from_edges): - # horizontal borders - createGuide('0,' + str(height),h_orientation,nv) - createGuide(str(height) + ',0',h_orientation,nv) - # horizontal borders - createGuide('0,' + str(width),v_orientation,nv) - createGuide(str(width) + ',0',v_orientation,nv) + else: + v_division = getVerticalDivisionsFromPreset(guides_preset) + h_division = getHorizontalDivisionsFromPreset(guides_preset) - else: + drawVerticalGuides(v_division,width,height,from_edges,nv) + drawHorizontalGuides(h_division,width,height,from_edges,nv) + + elif (tab == "\"diagonal_guides\""): + + if (delete_existing2): + deleteAllGuides(self.document) + + # diagonal + angle = 45 + + # X axe + left = 0 + right = width + + # Y axe + down = 0 + up = height + + ul_corner = str(up) + ',' + str(left) + ur_corner = str(right) + ',' + str(up) + ll_corner = str(down) + ',' + str(left) + lr_corner = str(down) + ',' + str(right) + + from_ul_to_lr = str(cos(angle)) + ',' + str(cos(angle)) + from_ur_to_ll = str(-sin(angle)) + ',' + str(sin(angle)) + from_ll_to_ur = str(-cos(angle)) + ',' + str(cos(angle)) + from_lr_to_ul = str(-sin(angle)) + ',' + str(-sin(angle)) + + if (upper_left): + createGuide(ul_corner,from_ul_to_lr,nv) + + if (upper_right): + createGuide(ur_corner,from_ur_to_ll,nv) + + if (lower_left): + createGuide(ll_corner,from_ll_to_ur,nv) + if (lower_right): + createGuide(lr_corner,from_lr_to_ul,nv) + + elif (tab == "\"margins\""): + + if (delete_existing3): + deleteAllGuides(self.document) + + if (from_edges2): + + # horizontal borders + createGuide('0,' + str(height),h_orientation,nv) + createGuide(str(height) + ',0',h_orientation,nv) + + # vertical borders + createGuide('0,' + str(width),v_orientation,nv) + createGuide(str(width) + ',0',v_orientation,nv) + + if (margins_preset == 'custom'): + + y_header = height + y_footer = 0 + x_left = 0 + x_right = width + + if (header_margin != 0): + y_header = (height / header_margin) * (header_margin - 1) + createGuide('0,' + str(y_header),h_orientation,nv) + + if (footer_margin != 0): + y_footer = height / footer_margin + createGuide('0,' + str(y_footer),h_orientation,nv) + + if (left_margin != 0): + x_left = width / left_margin + createGuide(str(x_left) + ',0',v_orientation,nv) + + if (right_margin != 0): + x_right = (width / right_margin) * (right_margin - 1) + createGuide(str(x_right) + ',0',v_orientation,nv) + + elif (margins_preset == 'book_left'): + # 1/9th header + y_header = (height / 9) * 8 + createGuide('0,' + str(y_header),h_orientation,nv) + + # 2/9th footer + y_footer = (height / 9) * 2 + createGuide('0,' + str(y_footer),h_orientation,nv) + + # 2/9th left margin + x_left = (width / 9) * 2 + createGuide(str(x_left) + ',0',v_orientation,nv) + + # 1/9th right margin + x_right = (width / 9) * 8 + createGuide(str(x_right) + ',0',v_orientation,nv) + + elif (margins_preset == 'book_right'): + # 1/9th header + y_header = (height / 9) * 8 + createGuide('0,' + str(y_header),h_orientation,nv) + + # 2/9th footer + y_footer = (height / 9) * 2 + createGuide('0,' + str(y_footer),h_orientation,nv) + + # 2/9th left margin + x_left = (width / 9) + createGuide(str(x_left) + ',0',v_orientation,nv) + + # 1/9th right margin + x_right = (width / 9) * 7 + createGuide(str(x_right) + ',0',v_orientation,nv) + + + # setting up properties of the rectangle created between guides + rectangle_height = y_header - y_footer + rectangle_width = x_right - x_left - v_division = getVerticalDivisionsFromPreset(preset) - h_division = getHorizontalDivisionsFromPreset(preset) + if (h_subdiv != 0): + begin_from = y_footer - drawVerticalGuides(v_division,width,height,from_edges,nv) - drawHorizontalGuides(h_division,width,height,from_edges,nv) + # creating horizontal guides + drawHorizontalGuides(h_subdiv,rectangle_width,rectangle_height,0,nv,begin_from) + if (v_subdiv != 0): + begin_from = x_left -if __name__ == '__main__': #pragma: no cover - # Create effect instance and apply it. - effect = Guides_Creator() - effect.affect() + # creating vertical guides + drawVerticalGuides(v_subdiv,rectangle_width,rectangle_height,0,nv,begin_from) + +# Create effect instance and apply it. +effect = Guides_Creator() +effect.affect() ## end of file guide_creator.py ## |
