diff options
Diffstat (limited to 'gerber/render')
-rw-r--r-- | gerber/render/cairo_backend.py | 20 | ||||
-rw-r--r-- | gerber/render/svgwrite_backend.py | 14 |
2 files changed, 33 insertions, 1 deletions
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py index 1c69725..125a125 100644 --- a/gerber/render/cairo_backend.py +++ b/gerber/render/cairo_backend.py @@ -56,13 +56,31 @@ class GerberCairoContext(GerberContext): self.ctx.line_to(*end)
self.ctx.stroke()
+ def _render_arc(self, arc, color):
+ center = map(mul, arc.center, self.scale)
+ start = map(mul, arc.start, self.scale)
+ end = map(mul, arc.end, self.scale)
+ radius = SCALE * arc.radius
+ angle1 = arc.start_angle
+ angle2 = arc.end_angle
+ width = arc.width if arc.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) # You actually have to do this...
+ if arc.direction == 'counterclockwise':
+ self.ctx.arc(*center, radius=radius, angle1=angle1, angle2=angle2)
+ else:
+ self.ctx.arc_negative(*center, radius=radius, angle1=angle1, angle2=angle2)
+ self.ctx.move_to(*end) # ...lame
+
def _render_region(self, region, color):
points = [tuple(map(mul, point, self.scale)) for point in region.points]
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:]:
- self.ctx.move_to(*point)
+ self.ctx.line_to(*point)
self.ctx.fill()
def _render_circle(self, circle, color):
diff --git a/gerber/render/svgwrite_backend.py b/gerber/render/svgwrite_backend.py index aeb680c..27783d6 100644 --- a/gerber/render/svgwrite_backend.py +++ b/gerber/render/svgwrite_backend.py @@ -18,6 +18,7 @@ from .render import GerberContext from operator import mul +import math import svgwrite SCALE = 400. @@ -64,6 +65,19 @@ class GerberSvgContext(GerberContext): aline.stroke(opacity=self.alpha) self.dwg.add(aline) + def _render_arc(self, arc, color): + start = tuple(map(mul, arc.start, self.scale)) + end = tuple(map(mul, arc.end, self.scale)) + radius = SCALE * arc.radius + width = arc.width if arc.width != 0 else 0.001 + arc_path = self.dwg.path(d='M %f, %f' % start, + stroke=svg_color(color), + stroke_width=SCALE * width) + large_arc = arc.sweep_angle >= 2 * math.pi + direction = '-' if arc.direction == 'clockwise' else '+' + arc_path.push_arc(end, 0, radius, large_arc, direction, True) + self.dwg.add(arc_path) + def _render_region(self, region, color): points = [tuple(map(mul, point, self.scale)) for point in region.points] region_path = self.dwg.path(d='M %f, %f' % points[0], |