diff options
Diffstat (limited to 'gerber/render')
-rw-r--r-- | gerber/render/cairo_backend.py | 13 | ||||
-rw-r--r-- | gerber/render/svgwrite_backend.py | 63 |
2 files changed, 13 insertions, 63 deletions
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py index df513bb..1c69725 100644 --- a/gerber/render/cairo_backend.py +++ b/gerber/render/cairo_backend.py @@ -20,7 +20,7 @@ from operator import mul import cairocffi as cairo
import math
-SCALE = 300.
+SCALE = 400.
class GerberCairoContext(GerberContext):
@@ -48,8 +48,9 @@ class GerberCairoContext(GerberContext): def _render_line(self, line, color):
start = map(mul, line.start, self.scale)
end = map(mul, line.end, self.scale)
- self.ctx.set_source_rgb (*color)
- self.ctx.set_line_width(line.width * SCALE)
+ width = line.width if line.width != 0 else 0.001
+ self.ctx.set_source_rgba(*color, alpha=self.alpha)
+ self.ctx.set_line_width(width * SCALE)
self.ctx.set_line_cap(cairo.LINE_CAP_ROUND)
self.ctx.move_to(*start)
self.ctx.line_to(*end)
@@ -57,7 +58,7 @@ class GerberCairoContext(GerberContext): def _render_region(self, region, color):
points = [tuple(map(mul, point, self.scale)) for point in region.points]
- self.ctx.set_source_rgb (*color)
+ self.ctx.set_source_rgba(*color, alpha=self.alpha)
self.ctx.set_line_width(0)
self.ctx.move_to(*points[0])
for point in points[1:]:
@@ -66,7 +67,7 @@ class GerberCairoContext(GerberContext): def _render_circle(self, circle, color):
center = map(mul, circle.position, self.scale)
- self.ctx.set_source_rgb (*color)
+ self.ctx.set_source_rgba(*color, alpha=self.alpha)
self.ctx.set_line_width(0)
self.ctx.arc(*center, radius=circle.radius * SCALE, angle1=0, angle2=2 * math.pi)
self.ctx.fill()
@@ -74,7 +75,7 @@ class GerberCairoContext(GerberContext): def _render_rectangle(self, rectangle, color):
ll = map(mul, rectangle.lower_left, self.scale)
width, height = tuple(map(mul, (rectangle.width, rectangle.height), map(abs, self.scale)))
- self.ctx.set_source_rgb (*color)
+ self.ctx.set_source_rgba(*color, alpha=self.alpha)
self.ctx.set_line_width(0)
self.ctx.rectangle(*ll,width=width, height=height)
self.ctx.fill()
diff --git a/gerber/render/svgwrite_backend.py b/gerber/render/svgwrite_backend.py index 2df87b3..aeb680c 100644 --- a/gerber/render/svgwrite_backend.py +++ b/gerber/render/svgwrite_backend.py @@ -20,7 +20,7 @@ from .render import GerberContext from operator import mul import svgwrite -SCALE = 300 +SCALE = 400. def svg_color(color): @@ -56,9 +56,10 @@ class GerberSvgContext(GerberContext): def _render_line(self, line, color): start = map(mul, line.start, self.scale) end = map(mul, line.end, self.scale) + width = line.width if line.width != 0 else 0.001 aline = self.dwg.line(start=start, end=end, stroke=svg_color(color), - stroke_width=SCALE * line.width, + stroke_width=SCALE * width, stroke_linecap='round') aline.stroke(opacity=self.alpha) self.dwg.add(aline) @@ -91,62 +92,10 @@ class GerberSvgContext(GerberContext): self.dwg.add(arect) def _render_obround(self, obround, color): - x, y = tuple(map(mul, obround.position, self.scale)) - xsize, ysize = tuple(map(mul, (obround.width, obround.height), - self.scale)) - xscale, yscale = self.scale - - # Corner case... - if xsize == ysize: - circle = self.dwg.circle(center=(x, y), - r = (xsize / 2.0), - fill=svg_color(color)) - circle.fill(opacity=self.alpha) - self.dwg.add(circle) - - # Horizontal obround - elif xsize > ysize: - rectx = xsize - ysize - recty = ysize - c1 = self.dwg.circle(center=(x - (rectx / 2.0), y), - r = (ysize / 2.0), - fill=svg_color(color)) - - c2 = self.dwg.circle(center=(x + (rectx / 2.0), y), - r = (ysize / 2.0), - fill=svg_color(color)) - - rect = self.dwg.rect(insert=(x, y), - size=(xsize, ysize), - fill=svg_color(color)) - c1.fill(opacity=self.alpha) - c2.fill(opacity=self.alpha) - rect.fill(opacity=self.alpha) - self.dwg.add(c1) - self.dwg.add(c2) - self.dwg.add(rect) + self._render_circle(obround.subshapes['circle1'], color) + self._render_circle(obround.subshapes['circle2'], color) + self._render_rectangle(obround.subshapes['rectangle'], color) - # Vertical obround - else: - rectx = xsize - recty = ysize - xsize - c1 = self.dwg.circle(center=(x, y - (recty / 2.)), - r = (xsize / 2.), - fill=svg_color(color)) - - c2 = self.dwg.circle(center=(x, y + (recty / 2.)), - r = (xsize / 2.), - fill=svg_color(color)) - - rect = self.dwg.rect(insert=(x, y), - size=(xsize, ysize), - fill=svg_color(color)) - c1.fill(opacity=self.alpha) - c2.fill(opacity=self.alpha) - rect.fill(opacity=self.alpha) - self.dwg.add(c1) - self.dwg.add(c2) - self.dwg.add(rect) def _render_drill(self, circle, color): center = map(mul, circle.position, self.scale) |