Don't have a background element, just insert all default elements.
Chris Pressey
7 years ago
106 | 106 |
|
107 | 107 |
def to_svg(self, min_x, min_y, max_x, max_y, stylesheet=None):
|
108 | 108 |
if stylesheet is None:
|
109 | |
stylesheet = 'rect { fill: black } .SVGBackground { fill: white }'
|
|
109 |
stylesheet = 'rect { fill: white } .{} { fill: black }'.format(self.default)
|
110 | 110 |
rects = []
|
111 | 111 |
y = min_y
|
112 | 112 |
while y is not None and y <= max_y:
|
113 | 113 |
x = min_x
|
114 | 114 |
while x <= max_x:
|
115 | 115 |
state = self.get(x, y)
|
116 | |
if state != self.default:
|
117 | |
rects.append(
|
118 | |
'<rect class="{}" x="{}" y="{}" width="1" height="1" />'.format(state, x, y)
|
119 | |
)
|
|
116 |
rects.append(
|
|
117 |
'<rect class="{}" x="{}" y="{}" width="1" height="1" />'.format(state, x, y)
|
|
118 |
)
|
120 | 119 |
x += 1
|
121 | 120 |
y += 1
|
122 | 121 |
return """\
|
|
126 | 125 |
<style type="text/css">
|
127 | 126 |
{}
|
128 | 127 |
</style>
|
129 | |
<rect class="SVGBackground" width="100%" height="100%" />
|
130 | 128 |
{}
|
131 | 129 |
</svg>""".format(min_x, min_y, max_x, max_y, stylesheet, '\n '.join(rects))
|