Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alignement grid to svg sheets to aid posterprint layout #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions svg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
## {{{ http://code.activestate.com/recipes/325823/ (r1)
#!/usr/bin/env python
"""\
SVG.py - Construct/display SVG scenes.
Expand All @@ -23,8 +22,12 @@ def add(self,item): self.items.append(item)
def strarray(self):
var = ["<?xml version=\"1.0\"?>\n",
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="%dmm" width="%dmm" >\n' % (self.height,self.width),
' <g style="fill-opacity:1.0; stroke:black; stroke-width:1;">\n'
' <g style="fill-opacity:1.0; stroke:darkgrey; stroke-width:0.5;">\n'
]
grid = Grid(self.width,self.height)
var += grid.strarray()
var += [" </g>\n",
' <g style="fill-opacity:1.0; stroke:black; stroke-width:1;">\n']
for item in self.items: var += item.strarray()
var += [" </g>\n</svg>\n"]
return var
Expand All @@ -43,6 +46,34 @@ def display(self):
os.system("%s" % (self.svgname))
return

class Grid:
def __init__(self,width,height,spacing=20):
self.width = width
self.height = height
return
def strarray(self):
w = self.width
h = self.height
return [' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(0,0,w,h),
' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(0,h,w,0),
' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(0,h*0.3333,w*0.3333,0),
' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(0,h*0.6667,w*0.6667,0),
' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(0,h*0.3333,w*0.6667,h),
' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(0,h*0.6667,w*0.3333,h),
' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(w*0.3333,h,w,h*0.3333),
' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(w*0.3333,0,w,h*0.6667),
' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(w*0.6667,0,w,h*0.3333),
' <line x1="%fmm" y1="%fmm" x2="%fmm" y2="%fmm" />\n' %
(w*0.6667,h,w,h*0.6667)]

class Line:
def __init__(self,start,end):
Expand Down Expand Up @@ -108,5 +139,5 @@ def test():
scene.display()
return

if __name__ == '__main__': test()
## end of http://code.activestate.com/recipes/325823/ }}}
if __name__ == '__main__':
test()