summaryrefslogtreecommitdiff
path: root/gerber
diff options
context:
space:
mode:
Diffstat (limited to 'gerber')
-rw-r--r--gerber/cam.py2
-rw-r--r--gerber/render/cairo_backend.py23
2 files changed, 14 insertions, 11 deletions
diff --git a/gerber/cam.py b/gerber/cam.py
index 804e366..0a68b23 100644
--- a/gerber/cam.py
+++ b/gerber/cam.py
@@ -253,8 +253,8 @@ class CamFile(object):
filename : string <optional>
If provided, save the rendered image to `filename`
"""
+ ctx.set_bounds(self.bounds)
ctx._paint_background()
-
if ctx.invert:
ctx._paint_inverted_layer()
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py
index 16638f5..2791d76 100644
--- a/gerber/render/cairo_backend.py
+++ b/gerber/render/cairo_backend.py
@@ -31,20 +31,21 @@ class GerberCairoContext(GerberContext):
self.scale = (scale, scale)
self.surface = None
self.ctx = None
+ self.bg = False
def set_bounds(self, bounds):
origin_in_inch = (bounds[0][0], bounds[1][0])
size_in_inch = (abs(bounds[0][1] - bounds[0][0]), abs(bounds[1][1] - bounds[1][0]))
size_in_pixels = map(mul, size_in_inch, self.scale)
- self.surface_buffer = tempfile.NamedTemporaryFile()
-
- self.surface = cairo.SVGSurface(self.surface_buffer, size_in_pixels[0], size_in_pixels[1])
- self.ctx = cairo.Context(self.surface)
- self.ctx.set_fill_rule(cairo.FILL_RULE_EVEN_ODD)
- self.ctx.scale(1, -1)
- self.ctx.translate(-(origin_in_inch[0] * self.scale[0]), (-origin_in_inch[1]*self.scale[0]) - size_in_pixels[1])
- # self.ctx.translate(-(origin_in_inch[0] * self.scale[0]), -origin_in_inch[1]*self.scale[1])
+ if self.surface is None:
+ self.surface_buffer = tempfile.NamedTemporaryFile()
+ self.surface = cairo.SVGSurface(self.surface_buffer, size_in_pixels[0], size_in_pixels[1])
+ self.ctx = cairo.Context(self.surface)
+ self.ctx.set_fill_rule(cairo.FILL_RULE_EVEN_ODD)
+ self.ctx.scale(1, -1)
+ self.ctx.translate(-(origin_in_inch[0] * self.scale[0]), (-origin_in_inch[1]*self.scale[0]) - size_in_pixels[1])
+ # self.ctx.translate(-(origin_in_inch[0] * self.scale[0]), -origin_in_inch[1]*self.scale[1])
def _render_line(self, line, color):
start = map(mul, line.start, self.scale)
@@ -140,8 +141,10 @@ class GerberCairoContext(GerberContext):
self.ctx.set_operator(cairo.OPERATOR_CLEAR)
def _paint_background(self):
- self.ctx.set_source_rgba(*self.background_color)
- self.ctx.paint()
+ if not self.bg:
+ self.bg = True
+ self.ctx.set_source_rgba(*self.background_color)
+ self.ctx.paint()
def dump(self, filename):
is_svg = filename.lower().endswith(".svg")