layout_nup_pageframe.py revision 358b46a388b1e316e51bc6fc5c4c7b10525db5ca
#@+leo-ver=4-thin
#@+node:tbrown.20070622094435.1:@thin pageframe.py
"""Create n-up SVG layouts"""
#@+others
#@+node:tbrown.20070622103716:imports
try:
except:
try:
except:
try:
except:
in Python 2.5 or supplied by lxml or elementtree modules.
""")
#@-node:tbrown.20070622103716:imports
#@+node:tbrown.20070622103716.1:expandTuple
try:
iter(x)
except:
return None
raise Exception("expandTuple: requires 2 or 4 item tuple")
try:
except:
return None
#@-node:tbrown.20070622103716.1:expandTuple
#@+node:tbrown.20070622103716.2:GenerateNup
size=None,
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:
# num = tuple(map(lambda ev: eval(str(ev)), num))
)
else:
# sep is separation between same points on pieces
style = 'stroke:#000000;stroke-opacity:1;fill:none;fill-opacity:1;'
padbox = 'rect', {
'style': style,
}
margbox = 'rect', {
'style': style,
}
{'xmlns:inkscape':"http://www.inkscape.org/namespaces/inkscape",
'xmlns:xlink':"http://www.w3.org/1999/xlink",
}))
if r == 0 and c == 0: continue
'transform': 'translate(%f,%f)' %
# guidelayer #####################################################
'inkscape:groupmode':'layer'})
if 'inner' in show:
'stroke:#8080ff')
'stroke:#000000')
if 'outer' in show:
'stroke:#8080ff')
'stroke:#000000')
# crosslayer #####################################################
'inkscape:groupmode':'layer'})
if 'crosses' in show:
crosslen = 12
x,y = 0,0
for r in 0, 1:
for c in 0, 1:
if r or c:
'xlink:href': '#crossmarker',
'transform': 'translate(%f,%f)' %
(x,y)})
# clonelayer #####################################################
# mainlayer ######################################################
if 'innerbox' in show:
if 'outerbox' in show:
if 'holder' in show:
path += ' Z'
if returnTree:
return doc
else:
if __name__ == '__main__':
#@-node:tbrown.20070622103716.2:GenerateNup
#@-others
#@-node:tbrown.20070622094435.1:@thin pageframe.py
#@-leo