summaryrefslogtreecommitdiff
path: root/gerber/render/cairo_backend.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2016-01-21 04:39:55 -0500
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2016-01-21 04:39:55 -0500
commit66a0d09e72b078da5820820aa5c6a2a7d7430507 (patch)
tree9c65368f91deb934859969fc4e155fcca35819f8 /gerber/render/cairo_backend.py
parent5476da8aa3f4ee424f56f4f2491e7af1c4b7b758 (diff)
downloadgerbonara-66a0d09e72b078da5820820aa5c6a2a7d7430507.tar.gz
gerbonara-66a0d09e72b078da5820820aa5c6a2a7d7430507.tar.bz2
gerbonara-66a0d09e72b078da5820820aa5c6a2a7d7430507.zip
Add support for mirrored rendering
- The default theme now renders the bottom layers mirrored. - see https://github.com/curtacircuitos/pcb-tools/blob/master/examples/pcb_bottom.png for an example.
Diffstat (limited to 'gerber/render/cairo_backend.py')
-rw-r--r--gerber/render/cairo_backend.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py
index cc2722a..2370eb9 100644
--- a/gerber/render/cairo_backend.py
+++ b/gerber/render/cairo_backend.py
@@ -18,6 +18,7 @@
import cairocffi as cairo
import tempfile
+import copy
from .render import GerberContext, RenderSettings
from .theme import THEMES
@@ -37,6 +38,7 @@ class GerberCairoContext(GerberContext):
self.surface = None
self.ctx = None
self.active_layer = None
+ self.active_matrix = None
self.output_ctx = None
self.bg = False
self.mask = None
@@ -120,9 +122,7 @@ class GerberCairoContext(GerberContext):
self.invert = settings.invert
# Get a new clean layer to render on
- self._new_render_layer()
- if settings.mirror:
- raise Warning('mirrored layers aren\'t supported yet...')
+ self._new_render_layer(mirror=settings.mirror)
for prim in layer.primitives:
self.render(prim)
# Add layer to image
@@ -262,30 +262,35 @@ class GerberCairoContext(GerberContext):
self.ctx.show_text(primitive.net_name)
self.ctx.scale(1, -1)
- def _new_render_layer(self, color=None):
+ def _new_render_layer(self, color=None, mirror=False):
size_in_pixels = self.scale_point(self.size_in_inch)
layer = cairo.SVGSurface(None, size_in_pixels[0], size_in_pixels[1])
ctx = cairo.Context(layer)
ctx.set_fill_rule(cairo.FILL_RULE_EVEN_ODD)
ctx.scale(1, -1)
ctx.translate(-(self.origin_in_inch[0] * self.scale[0]),
- (-self.origin_in_inch[1] * self.scale[0])
- - size_in_pixels[1])
+ (-self.origin_in_inch[1] * self.scale[0]) - size_in_pixels[1])
if self.invert:
ctx.set_operator(cairo.OPERATOR_OVER)
ctx.set_source_rgba(*self.color, alpha=self.alpha)
ctx.paint()
+ matrix = copy.copy(self._xform_matrix)
+ if mirror:
+ matrix.xx = -1.0
+ matrix.x0 = self.origin_in_pixels[0] + self.size_in_pixels[0]
self.ctx = ctx
self.active_layer = layer
+ self.active_matrix = matrix
def _flatten(self):
self.output_ctx.set_operator(cairo.OPERATOR_OVER)
ptn = cairo.SurfacePattern(self.active_layer)
- ptn.set_matrix(self._xform_matrix)
+ ptn.set_matrix(self.active_matrix)
self.output_ctx.set_source(ptn)
self.output_ctx.paint()
self.ctx = None
self.active_layer = None
+ self.active_matrix = None
def _paint_background(self, force=False):
if (not self.bg) or force: