summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2015-07-22 22:13:09 -0400
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2015-07-22 22:13:09 -0400
commit39726e3936c5fa5c50158727e8eb7f5d01cb1b49 (patch)
tree2a8a4467a6728599c1df15e4b13330bc86d31dab
parentb3f6ec558ca35a19bd60440f2a114eb98c0a4263 (diff)
downloadgerbonara-39726e3936c5fa5c50158727e8eb7f5d01cb1b49.tar.gz
gerbonara-39726e3936c5fa5c50158727e8eb7f5d01cb1b49.tar.bz2
gerbonara-39726e3936c5fa5c50158727e8eb7f5d01cb1b49.zip
Fix multiple layer issue in cairo-unification branch (see #33)
-rw-r--r--examples/cairo_example.pngbin2125223 -> 110829 bytes
-rw-r--r--gerber/cam.py2
-rw-r--r--gerber/render/cairo_backend.py23
3 files changed, 14 insertions, 11 deletions
diff --git a/examples/cairo_example.png b/examples/cairo_example.png
index 723faaf..485586e 100644
--- a/examples/cairo_example.png
+++ b/examples/cairo_example.png
Binary files differ
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")