summaryrefslogtreecommitdiff
path: root/gerber/render/svgwrite_backend.py
diff options
context:
space:
mode:
authorHamilton Kibbe <ham@hamiltonkib.be>2014-10-13 12:38:57 -0400
committerHamilton Kibbe <ham@hamiltonkib.be>2014-10-13 12:38:57 -0400
commit6adcdbae5fc06959203761616e778ba4594475cc (patch)
tree1b878d7fe63645899a0d631849596b70bd002b07 /gerber/render/svgwrite_backend.py
parent152fca07685d6f96f5e5bad723f1f62de99d8b7d (diff)
parent8c5c7ec8bbc8a074884ef04b566f9c0ecd6e78bb (diff)
downloadgerbonara-6adcdbae5fc06959203761616e778ba4594475cc.tar.gz
gerbonara-6adcdbae5fc06959203761616e778ba4594475cc.tar.bz2
gerbonara-6adcdbae5fc06959203761616e778ba4594475cc.zip
Merge branch 'master' of https://github.com/hamiltonkibbe/gerber-tools
Diffstat (limited to 'gerber/render/svgwrite_backend.py')
-rw-r--r--gerber/render/svgwrite_backend.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/gerber/render/svgwrite_backend.py b/gerber/render/svgwrite_backend.py
index 7570c84..78961da 100644
--- a/gerber/render/svgwrite_backend.py
+++ b/gerber/render/svgwrite_backend.py
@@ -117,17 +117,25 @@ class GerberSvgContext(GerberContext):
self.apertures = {}
self.dwg = svgwrite.Drawing()
+ self.dwg.transform = 'scale 1 -1'
self.background = False
+ self.region_path = None
def set_bounds(self, bounds):
xbounds, ybounds = bounds
size = (SCALE * (xbounds[1] - xbounds[0]), SCALE * (ybounds[1] - ybounds[0]))
if not self.background:
+ self.dwg = svgwrite.Drawing(viewBox='%f, %f, %f, %f' % (SCALE*xbounds[0], -SCALE*ybounds[1],size[0], size[1]))
self.dwg.add(self.dwg.rect(insert=(SCALE * xbounds[0],
-SCALE * ybounds[1]),
- size=size, fill="black"))
+ size=size, fill=convert_color(self.background_color)))
self.background = True
+ def set_alpha(self, alpha):
+ super(GerberSvgContext, self).set_alpha(alpha)
+ import warnings
+ warnings.warn('SVG output does not support transparency')
+
def define_aperture(self, d, shape, modifiers):
aperture = None
if shape == 'C':
@@ -173,7 +181,8 @@ class GerberSvgContext(GerberContext):
ap = self.apertures.get(self.aperture, None)
if ap is None:
return
- color = (convert_color(self.color) if self.level_polarity == 'dark'
+
+ color = (convert_color(self.color) if self.level_polarity == 'dark'
else convert_color(self.background_color))
for shape in ap.flash(self, x, y, color):
self.dwg.add(shape)
@@ -185,5 +194,21 @@ class GerberSvgContext(GerberContext):
fill=convert_color(self.drill_color))
self.dwg.add(hit)
+ def region_contour(self, x, y):
+ super(GerberSvgContext, self).region_contour(x, y)
+ x, y = self.resolve(x, y)
+ color = (convert_color(self.color) if self.level_polarity == 'dark'
+ else convert_color(self.background_color))
+ if self.region_path is None:
+ self.region_path = self.dwg.path(d = 'M %f, %f' %
+ (self.x*SCALE, -self.y*SCALE),
+ fill = color, stroke = 'none')
+ self.region_path.push('L %f, %f' % (x*SCALE, -y*SCALE))
+ self.move(x, y, resolve=False)
+
+ def fill_region(self):
+ self.dwg.add(self.region_path)
+ self.region_path = None
+
def dump(self, filename):
self.dwg.saveas(filename)