diff options
-rw-r--r-- | examples/pcb_bottom.png | bin | 39174 -> 40567 bytes | |||
-rw-r--r-- | gerber/render/cairo_backend.py | 19 | ||||
-rw-r--r-- | gerber/render/theme.py | 11 |
3 files changed, 18 insertions, 12 deletions
diff --git a/examples/pcb_bottom.png b/examples/pcb_bottom.png Binary files differindex 1e8c369..b2dab0c 100644 --- a/examples/pcb_bottom.png +++ b/examples/pcb_bottom.png 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:
diff --git a/gerber/render/theme.py b/gerber/render/theme.py index 6135ccb..4d325c5 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -41,11 +41,11 @@ class Theme(object): self.name = 'Default' if name is None else name self.background = kwargs.get('background', RenderSettings(COLORS['black'], alpha=0.0)) self.topsilk = kwargs.get('topsilk', RenderSettings(COLORS['white'])) - self.bottomsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white'])) + self.bottomsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white'], mirror=True)) self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True)) - self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True)) + self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True, mirror=True)) self.top = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) - self.bottom = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) + self.bottom = kwargs.get('bottom', RenderSettings(COLORS['hasl copper'], mirror=True)) self.drill = kwargs.get('drill', RenderSettings(COLORS['black'])) self.ipc_netlist = kwargs.get('ipc_netlist', RenderSettings(COLORS['red'])) @@ -61,9 +61,10 @@ THEMES = { 'default': Theme(), 'OSH Park': Theme(name='OSH Park', top=RenderSettings(COLORS['enig copper']), - bottom=RenderSettings(COLORS['enig copper']), + bottom=RenderSettings(COLORS['enig copper'], mirror=True), topmask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True), - bottommask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True)), + bottommask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True, mirror=True)), + 'Blue': Theme(name='Blue', topmask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True), bottommask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True)), |