summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2015-05-22 07:02:44 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2015-05-22 07:02:44 +0000
commit35d94a8e1c01cd60e4fcf4c15f46fee38c765fca (patch)
treed8366acd729a6a9d4bdc1001f050a43f30d8b7ad /share
parentUndo changes to CMakeLists.txt in 2geom directory after syncs (diff)
parentminor tweaks to libUEMF and related code (diff)
downloadinkscape-35d94a8e1c01cd60e4fcf4c15f46fee38c765fca.tar.gz
inkscape-35d94a8e1c01cd60e4fcf4c15f46fee38c765fca.zip
Merge from trunk
(bzr r14059.2.15)
Diffstat (limited to 'share')
-rw-r--r--share/extensions/image_attributes.inx82
-rwxr-xr-xshare/extensions/image_attributes.py169
-rw-r--r--share/extensions/layout_nup.inx1
-rwxr-xr-xshare/extensions/layout_nup.py216
-rwxr-xr-xshare/extensions/layout_nup_pageframe.py230
5 files changed, 463 insertions, 235 deletions
diff --git a/share/extensions/image_attributes.inx b/share/extensions/image_attributes.inx
new file mode 100644
index 000000000..a353d17e5
--- /dev/null
+++ b/share/extensions/image_attributes.inx
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
+
+ <_name>Set Image Attributes</_name>
+ <id>org.inkscape.effect.image_attributes</id>
+
+ <dependency type="executable" location="extensions">image_attributes.py</dependency>
+ <dependency type="executable" location="extensions">inkex.py</dependency>
+
+ <param name="tab_main" type="notebook">
+
+ <!-- render images like in 0.48 -->
+ <page name="tab_basic" _gui-text="Basic">
+ <_param name="basic_desc1" type="description">Render all bitmap images like in older Inskcape versions.
+
+Available options:</_param>
+ <param name="fix_scaling" type="boolean" _gui-text="Support non-unifom scaling">true</param>
+ <param name="fix_rendering" type="boolean" _gui-text="Render images blocky">false</param>
+ </page>
+
+ <!-- image aspect ratio -->
+ <page name="tab_aspectRatio" _gui-text="Image Aspect Ratio">
+ <param name="aspect_ratio" type="enum" _gui-text="preserveAspectRatio attribute:">
+ <item value="none">none</item>
+ <_item value="unset">Unset</_item>
+ <item value="xMinYMin">xMinYMin</item>
+ <item value="xMidYMin">xMidYMin</item>
+ <item value="xMaxYMin">xMaxYMin</item>
+ <item value="xMinYMid">xMinYMid</item>
+ <item value="xMidYMid">xMidYMid</item>
+ <item value="xMaxYMid">xMaxYMid</item>
+ <item value="xMinYMax">xMinYMax</item>
+ <item value="xMidYMax">xMidYMax</item>
+ <item value="xMaxYMax">xMaxYMax</item>
+ </param>
+ <param name="aspect_clip" type="enum" _gui-text="meetOrSlice:">
+ <item value="unset">-</item>
+ <item value="meet">meet</item>
+ <item value="slice">slice</item>
+ </param>
+ <param name="aspect_ratio_scope" type="enum" _gui-text="Scope:">
+ <_item value="selected_only">Change only selected image(s)</_item>
+ <_item value="in_selection">Change all images in selection</_item>
+ <_item value="in_document">Change all images in document</_item>
+ </param>
+ </page>
+
+ <!-- image-rendering -->
+ <page name="tab_image_rendering" _gui-text="Image Rendering Quality">
+ <param name="image_rendering" type="enum" _gui-text="Image rendering attribute:">
+ <_item value="unset">Unset</_item>
+ <item value="auto">auto</item>
+ <item value="optimizeQuality">optimizeQuality</item>
+ <item value="optimizeSpeed">optimizeSpeed</item>
+ <item value="inherit">inherit</item>
+ </param>
+ <param name="image_rendering_scope" type="enum" _gui-text="Scope:">
+ <_item value="selected_only">Change only selected image(s)</_item>
+ <_item value="in_selection">Change all images in selection</_item>
+ <_item value="in_document">Change all images in document</_item>
+ <_item value="on_parent_group">Apply attribute to parent group of selection</_item>
+ <_item value="on_root_only" >Apply attribute to SVG root</_item>
+ </param>
+ </page>
+
+ </param>
+
+ <effect needs-document="true" needs-live-preview="true">
+ <object-type>all</object-type>
+ <effects-menu>
+ <submenu _name="Images"/>
+ </effects-menu>
+ </effect>
+
+ <script>
+ <command reldir="extensions" interpreter="python">image_attributes.py</command>
+ </script>
+
+ <options silent="false"></options>
+
+</inkscape-extension>
+
diff --git a/share/extensions/image_attributes.py b/share/extensions/image_attributes.py
new file mode 100755
index 000000000..ddd5a8b87
--- /dev/null
+++ b/share/extensions/image_attributes.py
@@ -0,0 +1,169 @@
+#!/usr/bin/env python
+'''
+image_attributes.py - adjust image attributes which don't have global
+GUI options yet
+
+Tool for Inkscape 0.91 to adjust rendering of drawings with linked
+or embedded bitmap images created with older versions of Inkscape
+or third-party applications.
+
+Copyright (C) 2015, ~suv <suv-sf@users.sf.net>
+
+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
+'''
+
+# local library
+import inkex
+import simplestyle
+
+try:
+ inkex.localize()
+except:
+ import gettext
+ _ = gettext.gettext
+
+
+class SetAttrImage(inkex.Effect):
+ def __init__(self):
+ inkex.Effect.__init__(self)
+ # main options
+ self.OptionParser.add_option("--fix_scaling",
+ action="store", type="inkbool",
+ dest="fix_scaling", default=True,
+ help="")
+ self.OptionParser.add_option("--fix_rendering",
+ action="store", type="inkbool",
+ dest="fix_rendering", default=False,
+ help="")
+ self.OptionParser.add_option("--aspect_ratio",
+ action="store", type="string",
+ dest="aspect_ratio", default="none",
+ help="Value for attribute 'preserveAspectRatio'")
+ self.OptionParser.add_option("--aspect_clip",
+ action="store", type="string",
+ dest="aspect_clip", default="unset",
+ help="optional 'meetOrSlice' value")
+ self.OptionParser.add_option("--aspect_ratio_scope",
+ action="store", type="string",
+ dest="aspect_ratio_scope", default="selected_only",
+ help="scope within which to edit 'preserveAspectRatio' attribute")
+ self.OptionParser.add_option("--image_rendering",
+ action="store", type="string",
+ dest="image_rendering", default="unset",
+ help="Value for attribute 'image-rendering'")
+ self.OptionParser.add_option("--image_rendering_scope",
+ action="store", type="string",
+ dest="image_rendering_scope", default="selected_only",
+ help="scope within which to edit 'image-rendering' attribute")
+ # tabs
+ self.OptionParser.add_option("--tab_main",
+ action="store", type="string",
+ dest="tab_main")
+
+ # core method
+
+ def change_attribute(self, node, attribute):
+ for key, value in attribute.items():
+ if key == 'preserveAspectRatio':
+ # set presentation attribute
+ if value != "unset":
+ node.set(key, str(value))
+ else:
+ if node.get(key):
+ del node.attrib[key]
+ elif key == 'image-rendering':
+ node_style = simplestyle.parseStyle(node.get('style'))
+ if key not in node_style:
+ # set presentation attribute
+ if value != "unset":
+ node.set(key, str(value))
+ else:
+ if node.get(key):
+ del node.attrib[key]
+ else:
+ # set style property
+ if value != "unset":
+ node_style[key] = str(value)
+ else:
+ del node_style[key]
+ node.set('style', simplestyle.formatStyle(node_style))
+ else:
+ pass
+
+ def change_all_images(self, node, attribute):
+ path = 'descendant-or-self::svg:image'
+ for img in node.xpath(path, namespaces=inkex.NSS):
+ self.change_attribute(img, attribute)
+
+ # methods called via dispatcher
+
+ def change_selected_only(self, selected, attribute):
+ if selected:
+ for node_id, node in selected.iteritems():
+ if node.tag == inkex.addNS('image', 'svg'):
+ self.change_attribute(node, attribute)
+
+ def change_in_selection(self, selected, attribute):
+ if selected:
+ for node_id, node in selected.iteritems():
+ self.change_all_images(node, attribute)
+
+ def change_in_document(self, selected, attribute):
+ self.change_all_images(self.document.getroot(), attribute)
+
+ def change_on_parent_group(self, selected, attribute):
+ if selected:
+ for node_id, node in selected.iteritems():
+ self.change_attribute(node.getparent(), attribute)
+
+ def change_on_root_only(self, selected, attribute):
+ self.change_attribute(self.document.getroot(), attribute)
+
+ # main
+
+ def effect(self):
+ attr_val = []
+ attr_dict = {}
+ cmd_scope = None
+ if self.options.tab_main == '"tab_basic"':
+ cmd_scope = "in_document"
+ attr_dict['preserveAspectRatio'] = ("none" if self.options.fix_scaling else "unset")
+ attr_dict['image-rendering'] = ("optimizeSpeed" if self.options.fix_rendering else "unset")
+ elif self.options.tab_main == '"tab_aspectRatio"':
+ attr_val = [self.options.aspect_ratio]
+ if self.options.aspect_clip != "unset":
+ attr_val.append(self.options.aspect_clip)
+ attr_dict['preserveAspectRatio'] = ' '.join(attr_val)
+ cmd_scope = self.options.aspect_ratio_scope
+ elif self.options.tab_main == '"tab_image_rendering"':
+ attr_dict['image-rendering'] = self.options.image_rendering
+ cmd_scope = self.options.image_rendering_scope
+ else: # help tab
+ pass
+ # dispatcher
+ if cmd_scope is not None:
+ try:
+ change_cmd = getattr(self, 'change_{0}'.format(cmd_scope))
+ change_cmd(self.selected, attr_dict)
+ except AttributeError:
+ inkex.errormsg('Scope "{0}" not supported'.format(cmd_scope))
+
+
+if __name__ == '__main__':
+ e = SetAttrImage()
+ e.affect()
+
+
+# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99
diff --git a/share/extensions/layout_nup.inx b/share/extensions/layout_nup.inx
index 2b7734fc3..1d4d1ef0f 100644
--- a/share/extensions/layout_nup.inx
+++ b/share/extensions/layout_nup.inx
@@ -3,7 +3,6 @@
<_name>N-up layout</_name>
<id>org.greygreen.inkscape.effects.nup</id>
<dependency type="executable" location="extensions">layout_nup.py</dependency>
- <dependency type="executable" location="extensions">layout_nup_pageframe.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<param name="tab" type="notebook">
diff --git a/share/extensions/layout_nup.py b/share/extensions/layout_nup.py
index 5f8451c45..266a3950d 100755
--- a/share/extensions/layout_nup.py
+++ b/share/extensions/layout_nup.py
@@ -19,7 +19,19 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import inkex
import sys
-import layout_nup_pageframe
+try:
+ import xml.etree.ElementTree as ElementTree
+except:
+ try:
+ from lxml import etree as ElementTree
+ except:
+ try:
+ from elementtree.ElementTree import ElementTree
+ except:
+ sys.stderr.write("""Requires ElementTree module, included
+in Python 2.5 or supplied by lxml or elementtree modules.
+
+""")
class Nup(inkex.Effect):
def __init__(self):
@@ -64,7 +76,7 @@ class Nup(inkex.Effect):
if getattr(self.options, i):
showList.append(i.lower().replace('show', ''))
o = self.options
- self.pf = layout_nup_pageframe.GenerateNup(
+ self.pf = self.GenerateNup(
unit=o.unit,
pgSize=(o.pgSizeX,o.pgSizeY),
pgMargin=(o.pgMarginTop,o.pgMarginRight,o.pgMarginBottom,o.pgMarginLeft),
@@ -84,7 +96,203 @@ class Nup(inkex.Effect):
def output(self):
sys.stdout.write(self.pf)
+ def expandTuple(self, unit, x, length = 4):
+ try:
+ iter(x)
+ except:
+ return None
+
+ if len(x) != length: x = x*2
+ if len(x) != length:
+ raise Exception("expandTuple: requires 2 or 4 item tuple")
+ try:
+ return tuple(map(lambda ev: (self.unittouu(str(eval(str(ev)))+unit)/self.unittouu('1px')), x))
+ except:
+ return None
+
+ def GenerateNup(self,
+ unit="px",
+ pgSize=("8.5*96","11*96"),
+ pgMargin=(0,0),
+ pgPadding=(0,0),
+ num=(2,2),
+ calculateSize=True,
+ size=None,
+ margin=(0,0),
+ padding=(20,20),
+ show=['default'],
+ container='svg',
+ returnTree = False,
+ ):
+ """Generate the SVG. Inputs are run through 'eval(str(x))' so you can use
+ '8.5*72' instead of 612. Margin / padding dimension tuples can be
+ (top & bottom, left & right) or (top, right, bottom, left).
+
+ Keyword arguments:
+ pgSize -- page size, width x height
+ pgMargin -- extra space around each page
+ pgPadding -- added to pgMargin
+ n -- rows x cols
+ size -- override calculated size, width x height
+ margin -- white space around each piece
+ padding -- inner padding for each piece
+ show -- list of keywords indicating what to show
+ - 'crosses' - cutting guides
+ - 'inner' - inner boundary
+ - 'outer' - outer boundary
+ container -- 'svg' or 'g'
+ returnTree -- whether to return the ElementTree or the string
+ """
+
+ if 'default' in show:
+ show = set(show).union(['inner', 'innerbox', 'holder', 'crosses'])
+
+ pgMargin = self.expandTuple(unit, pgMargin)
+ pgPadding = self.expandTuple(unit, pgPadding)
+ margin = self.expandTuple(unit, margin)
+ padding = self.expandTuple(unit, padding)
+
+ pgSize = self.expandTuple(unit, pgSize, length = 2)
+ # num = tuple(map(lambda ev: eval(str(ev)), num))
+
+ pgEdge = map(sum,zip(pgMargin, pgPadding))
+
+ top, right, bottom, left = 0,1,2,3
+ width, height = 0,1
+ rows, cols = 0,1
+ size = self.expandTuple(unit, size, length = 2)
+ if size == None or calculateSize == True or len(size) < 2 or size[0] == 0 or size[1] == 0:
+ size = ((pgSize[width]
+ - pgEdge[left] - pgEdge[right]
+ - num[cols]*(margin[left] + margin[right])) / num[cols],
+ (pgSize[height]
+ - pgEdge[top] - pgEdge[bottom]
+ - num[rows]*(margin[top] + margin[bottom])) / num[rows]
+ )
+ else:
+ size = self.expandTuple(unit, size, length = 2)
+
+ # sep is separation between same points on pieces
+ sep = (size[width]+margin[right]+margin[left],
+ size[height]+margin[top]+margin[bottom])
+
+ style = 'stroke:#000000;stroke-opacity:1;fill:none;fill-opacity:1;'
+
+ padbox = 'rect', {
+ 'x': str(pgEdge[left] + margin[left] + padding[left]),
+ 'y': str(pgEdge[top] + margin[top] + padding[top]),
+ 'width': str(size[width] - padding[left] - padding[right]),
+ 'height': str(size[height] - padding[top] - padding[bottom]),
+ 'style': style,
+ }
+ margbox = 'rect', {
+ 'x': str(pgEdge[left] + margin[left]),
+ 'y': str(pgEdge[top] + margin[top]),
+ 'width': str(size[width]),
+ 'height': str(size[height]),
+ 'style': style,
+ }
+
+ doc = ElementTree.ElementTree(ElementTree.Element(container,
+ {'xmlns:inkscape':"http://www.inkscape.org/namespaces/inkscape",
+ 'xmlns:xlink':"http://www.w3.org/1999/xlink",
+ 'width':str(pgSize[width]),
+ 'height':str(pgSize[height]),
+ }))
+
+ sub = ElementTree.SubElement
+
+ root = doc.getroot()
+
+ def makeClones(under, to):
+ for r in range(0,num[rows]):
+ for c in range(0,num[cols]):
+ if r == 0 and c == 0: continue
+ sub(under, 'use', {
+ 'xlink:href': '#' + to,
+ 'transform': 'translate(%f,%f)' %
+ (c*sep[width], r*sep[height])})
+
+ # guidelayer #####################################################
+ if set(['inner', 'outer']).intersection(show):
+ layer = sub(root, 'g', {'id':'guidelayer',
+ 'inkscape:groupmode':'layer'})
+ if 'inner' in show:
+ padbox[1]['id'] = 'innerguide'
+ padbox[1]['style'] = padbox[1]['style'].replace('stroke:#000000',
+ 'stroke:#8080ff')
+ sub(layer, *padbox)
+ del padbox[1]['id']
+ padbox[1]['style'] = padbox[1]['style'].replace('stroke:#8080ff',
+ 'stroke:#000000')
+ makeClones(layer, 'innerguide')
+ if 'outer' in show:
+ margbox[1]['id'] = 'outerguide'
+ margbox[1]['style'] = padbox[1]['style'].replace('stroke:#000000',
+ 'stroke:#8080ff')
+ sub(layer, *margbox)
+ del margbox[1]['id']
+ margbox[1]['style'] = padbox[1]['style'].replace('stroke:#8080ff',
+ 'stroke:#000000')
+ makeClones(layer, 'outerguide')
+
+ # crosslayer #####################################################
+ if set(['crosses']).intersection(show):
+ layer = sub(root, 'g', {'id':'cutlayer',
+ 'inkscape:groupmode':'layer'})
+
+ if 'crosses' in show:
+ crosslen = 12
+ group = sub(layer, 'g', id='cross')
+ x,y = 0,0
+ path = 'M%f %f' % (x+pgEdge[left] + margin[left],
+ y+pgEdge[top] + margin[top]-crosslen)
+ path += ' L%f %f' % (x+pgEdge[left] + margin[left],
+ y+pgEdge[top] + margin[top]+crosslen)
+ path += ' M%f %f' % (x+pgEdge[left] + margin[left]-crosslen,
+ y+pgEdge[top] + margin[top])
+ path += ' L%f %f' % (x+pgEdge[left] + margin[left]+crosslen,
+ y+pgEdge[top] + margin[top])
+ sub(group, 'path', style=style+'stroke-width:0.05',
+ d = path, id = 'crossmarker')
+ for r in 0, 1:
+ for c in 0, 1:
+ if r or c:
+ x,y = c*size[width], r*size[height]
+ sub(group, 'use', {
+ 'xlink:href': '#crossmarker',
+ 'transform': 'translate(%f,%f)' %
+ (x,y)})
+ makeClones(layer, 'cross')
+
+ # clonelayer #####################################################
+ layer = sub(root, 'g', {'id':'clonelayer', 'inkscape:groupmode':'layer'})
+ makeClones(layer, 'main')
+
+ # mainlayer ######################################################
+ layer = sub(root, 'g', {'id':'mainlayer', 'inkscape:groupmode':'layer'})
+ group = sub(layer, 'g', {'id':'main'})
+
+ if 'innerbox' in show:
+ sub(group, *padbox)
+ if 'outerbox' in show:
+ sub(group, *margbox)
+ if 'holder' in show:
+ x, y = (pgEdge[left] + margin[left] + padding[left],
+ pgEdge[top] + margin[top] + padding[top])
+ w, h = (size[width] - padding[left] - padding[right],
+ size[height] - padding[top] - padding[bottom])
+ path = 'M%f %f' % (x + w/2., y)
+ path += ' L%f %f' % (x + w, y + h/2.)
+ path += ' L%f %f' % (x + w/2., y + h)
+ path += ' L%f %f' % (x, y + h/2.)
+ path += ' Z'
+ sub(group, 'path', style=style, d = path)
+
+ if returnTree:
+ return doc
+ else:
+ return ElementTree.tostring(root)
+
e = Nup()
e.affect()
-
-
diff --git a/share/extensions/layout_nup_pageframe.py b/share/extensions/layout_nup_pageframe.py
deleted file mode 100755
index 471a75dd3..000000000
--- a/share/extensions/layout_nup_pageframe.py
+++ /dev/null
@@ -1,230 +0,0 @@
-#!/usr/bin/env python
-#@+leo-ver=4-thin
-#@+node:tbrown.20070622094435.1:@thin pageframe.py
-"""Create n-up SVG layouts"""
-
-#@+others
-#@+node:tbrown.20070622103716:imports
-import sys, inkex
-
-try:
- import xml.etree.ElementTree as ElementTree
-except:
- try:
- from lxml import etree as ElementTree
- except:
- try:
- from elementtree.ElementTree import ElementTree
- except:
- sys.stderr.write("""Requires ElementTree module, included
-in Python 2.5 or supplied by lxml or elementtree modules.
-
-""")
-#@-node:tbrown.20070622103716:imports
-#@+node:tbrown.20070622103716.1:expandTuple
-def expandTuple(unit, x, length = 4):
- try:
- iter(x)
- except:
- return None
-
- if len(x) != length: x = x*2
- if len(x) != length:
- raise Exception("expandTuple: requires 2 or 4 item tuple")
- try:
- return tuple(map(lambda ev: (self.unittouu(str(eval(str(ev)))+unit)), x))
- except:
- return None
-#@-node:tbrown.20070622103716.1:expandTuple
-#@+node:tbrown.20070622103716.2:GenerateNup
-def GenerateNup(unit="px",
- pgSize=("8.5*96","11*96"),
- pgMargin=(0,0),
- pgPadding=(0,0),
- num=(2,2),
- calculateSize=True,
- size=None,
- margin=(0,0),
- padding=(20,20),
- show=['default'],
- container='svg',
- returnTree = False,
- ):
- """Generate the SVG. Inputs are run through 'eval(str(x))' so you can use
-'8.5*72' instead of 612. Margin / padding dimension tuples can be
-(top & bottom, left & right) or (top, right, bottom, left).
-
-Keyword arguments:
-pgSize -- page size, width x height
-pgMargin -- extra space around each page
-pgPadding -- added to pgMargin
-n -- rows x cols
-size -- override calculated size, width x height
-margin -- white space around each piece
-padding -- inner padding for each piece
-show -- list of keywords indicating what to show
- - 'crosses' - cutting guides
- - 'inner' - inner boundary
- - 'outer' - outer boundary
-container -- 'svg' or 'g'
-returnTree -- whether to return the ElementTree or the string
-"""
-
- if 'default' in show:
- show = set(show).union(['inner', 'innerbox', 'holder', 'crosses'])
-
- pgMargin = expandTuple(unit, pgMargin)
- pgPadding = expandTuple(unit, pgPadding)
- margin = expandTuple(unit, margin)
- padding = expandTuple(unit, padding)
-
- pgSize = expandTuple(unit, pgSize, length = 2)
-# num = tuple(map(lambda ev: eval(str(ev)), num))
-
- pgEdge = map(sum,zip(pgMargin, pgPadding))
-
- top, right, bottom, left = 0,1,2,3
- width, height = 0,1
- rows, cols = 0,1
- size = expandTuple(unit, size, length = 2)
- if size == None or calculateSize == True or len(size) < 2 or size[0] == 0 or size[1] == 0:
- size = ((pgSize[width]
- - pgEdge[left] - pgEdge[right]
- - num[cols]*(margin[left] + margin[right])) / num[cols],
- (pgSize[height]
- - pgEdge[top] - pgEdge[bottom]
- - num[rows]*(margin[top] + margin[bottom])) / num[rows]
- )
- else:
- size = expandTuple(unit, size, length = 2)
-
- # sep is separation between same points on pieces
- sep = (size[width]+margin[right]+margin[left],
- size[height]+margin[top]+margin[bottom])
-
- style = 'stroke:#000000;stroke-opacity:1;fill:none;fill-opacity:1;'
-
- padbox = 'rect', {
- 'x': str(pgEdge[left] + margin[left] + padding[left]),
- 'y': str(pgEdge[top] + margin[top] + padding[top]),
- 'width': str(size[width] - padding[left] - padding[right]),
- 'height': str(size[height] - padding[top] - padding[bottom]),
- 'style': style,
- }
- margbox = 'rect', {
- 'x': str(pgEdge[left] + margin[left]),
- 'y': str(pgEdge[top] + margin[top]),
- 'width': str(size[width]),
- 'height': str(size[height]),
- 'style': style,
- }
-
- doc = ElementTree.ElementTree(ElementTree.Element(container,
- {'xmlns:inkscape':"http://www.inkscape.org/namespaces/inkscape",
- 'xmlns:xlink':"http://www.w3.org/1999/xlink",
- 'width':str(pgSize[width]),
- 'height':str(pgSize[height]),
- }))
-
- sub = ElementTree.SubElement
-
- root = doc.getroot()
-
- def makeClones(under, to):
- for r in range(0,num[rows]):
- for c in range(0,num[cols]):
- if r == 0 and c == 0: continue
- sub(under, 'use', {
- 'xlink:href': '#' + to,
- 'transform': 'translate(%f,%f)' %
- (c*sep[width], r*sep[height])})
-
- # guidelayer #####################################################
- if set(['inner', 'outer']).intersection(show):
- layer = sub(root, 'g', {'id':'guidelayer',
- 'inkscape:groupmode':'layer'})
- if 'inner' in show:
- padbox[1]['id'] = 'innerguide'
- padbox[1]['style'] = padbox[1]['style'].replace('stroke:#000000',
- 'stroke:#8080ff')
- sub(layer, *padbox)
- del padbox[1]['id']
- padbox[1]['style'] = padbox[1]['style'].replace('stroke:#8080ff',
- 'stroke:#000000')
- makeClones(layer, 'innerguide')
- if 'outer' in show:
- margbox[1]['id'] = 'outerguide'
- margbox[1]['style'] = padbox[1]['style'].replace('stroke:#000000',
- 'stroke:#8080ff')
- sub(layer, *margbox)
- del margbox[1]['id']
- margbox[1]['style'] = padbox[1]['style'].replace('stroke:#8080ff',
- 'stroke:#000000')
- makeClones(layer, 'outerguide')
-
- # crosslayer #####################################################
- if set(['crosses']).intersection(show):
- layer = sub(root, 'g', {'id':'cutlayer',
- 'inkscape:groupmode':'layer'})
-
- if 'crosses' in show:
- crosslen = 12
- group = sub(layer, 'g', id='cross')
- x,y = 0,0
- path = 'M%f %f' % (x+pgEdge[left] + margin[left],
- y+pgEdge[top] + margin[top]-crosslen)
- path += ' L%f %f' % (x+pgEdge[left] + margin[left],
- y+pgEdge[top] + margin[top]+crosslen)
- path += ' M%f %f' % (x+pgEdge[left] + margin[left]-crosslen,
- y+pgEdge[top] + margin[top])
- path += ' L%f %f' % (x+pgEdge[left] + margin[left]+crosslen,
- y+pgEdge[top] + margin[top])
- sub(group, 'path', style=style+'stroke-width:0.05',
- d = path, id = 'crossmarker')
- for r in 0, 1:
- for c in 0, 1:
- if r or c:
- x,y = c*size[width], r*size[height]
- sub(group, 'use', {
- 'xlink:href': '#crossmarker',
- 'transform': 'translate(%f,%f)' %
- (x,y)})
- makeClones(layer, 'cross')
-
- # clonelayer #####################################################
- layer = sub(root, 'g', {'id':'clonelayer', 'inkscape:groupmode':'layer'})
- makeClones(layer, 'main')
-
- # mainlayer ######################################################
- layer = sub(root, 'g', {'id':'mainlayer', 'inkscape:groupmode':'layer'})
- group = sub(layer, 'g', {'id':'main'})
-
- if 'innerbox' in show:
- sub(group, *padbox)
- if 'outerbox' in show:
- sub(group, *margbox)
- if 'holder' in show:
- x, y = (pgEdge[left] + margin[left] + padding[left],
- pgEdge[top] + margin[top] + padding[top])
- w, h = (size[width] - padding[left] - padding[right],
- size[height] - padding[top] - padding[bottom])
- path = 'M%f %f' % (x + w/2., y)
- path += ' L%f %f' % (x + w, y + h/2.)
- path += ' L%f %f' % (x + w/2., y + h)
- path += ' L%f %f' % (x, y + h/2.)
- path += ' Z'
- sub(group, 'path', style=style, d = path)
-
- if returnTree:
- return doc
- else:
- return ElementTree.tostring(root)
-
-if __name__ == '__main__':
- print GenerateNup(num=(10,3), margin=(5,5), show=['default', 'outer'])
-#@-node:tbrown.20070622103716.2:GenerateNup
-#@-others
-#@-node:tbrown.20070622094435.1:@thin pageframe.py
-#@-leo
-
-