diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2016-01-21 03:57:44 -0500 |
---|---|---|
committer | Garret Fick <garret@ficksworkshop.com> | 2016-09-24 02:28:36 +0800 |
commit | 5af19af190c1fb0f0c5be029d46d63e657dde4d9 (patch) | |
tree | dd60a0b21e1d1ca7258b9f978ce973354d96062c /gerber/render | |
parent | 8d5e782ccf220d77f0aad5a4e5605dc5cbe0f410 (diff) | |
download | gerbonara-5af19af190c1fb0f0c5be029d46d63e657dde4d9.tar.gz gerbonara-5af19af190c1fb0f0c5be029d46d63e657dde4d9.tar.bz2 gerbonara-5af19af190c1fb0f0c5be029d46d63e657dde4d9.zip |
Commit partial merge so I can work on the plane
Diffstat (limited to 'gerber/render')
-rw-r--r-- | gerber/render/cairo_backend.py | 92 | ||||
-rw-r--r-- | gerber/render/render.py | 1 |
2 files changed, 90 insertions, 3 deletions
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py index dc39607..8c7232f 100644 --- a/gerber/render/cairo_backend.py +++ b/gerber/render/cairo_backend.py @@ -12,6 +12,7 @@ # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and # limitations under the License. @@ -22,14 +23,14 @@ except ImportError: import math
from operator import mul, div
- import tempfile
+import cairocffi as cairo
+
from ..primitives import *
from .render import GerberContext, RenderSettings
from .theme import THEMES
-
try:
from cStringIO import StringIO
except(ImportError):
@@ -138,20 +139,35 @@ class GerberCairoContext(GerberContext): start = [pos * scale for pos, scale in zip(line.start, self.scale)]
end = [pos * scale for pos, scale in zip(line.end, self.scale)]
if not self.invert:
+<<<<<<< HEAD self.ctx.set_source_rgba(color[0], color[1], color[2], alpha=self.alpha)
self.ctx.set_operator(cairo.OPERATOR_OVER
if line.level_polarity == "dark"
else cairo.OPERATOR_CLEAR) +======= + self.ctx.set_source_rgba(*color, alpha=self.alpha)
+ self.ctx.set_operator(cairo.OPERATOR_OVER
+ if line.level_polarity == 'dark'
+ else cairo.OPERATOR_CLEAR)
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. else:
self.ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
self.ctx.set_operator(cairo.OPERATOR_CLEAR)
if isinstance(line.aperture, Circle):
+<<<<<<< HEAD width = line.aperture.diameter +======= + width = line.aperture.diameter
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. self.ctx.set_line_width(width * self.scale[0])
self.ctx.set_line_cap(cairo.LINE_CAP_ROUND)
self.ctx.move_to(*start)
self.ctx.line_to(*end)
+<<<<<<< HEAD self.ctx.stroke() +======= + self.ctx.stroke()
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. elif isinstance(line.aperture, Rectangle):
points = [self.scale_point(x) for x in line.vertices]
self.ctx.set_line_width(0)
@@ -176,6 +192,7 @@ class GerberCairoContext(GerberContext): width = max(arc.aperture.width, arc.aperture.height, 0.001)
if not self.invert:
+<<<<<<< HEAD self.ctx.set_source_rgba(color[0], color[1], color[2], alpha=self.alpha)
self.ctx.set_operator(cairo.OPERATOR_OVER
if arc.level_polarity == "dark"\
@@ -184,25 +201,50 @@ class GerberCairoContext(GerberContext): self.ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
self.ctx.set_operator(cairo.OPERATOR_CLEAR)
+======= + self.ctx.set_source_rgba(*color, alpha=self.alpha)
+ self.ctx.set_operator(cairo.OPERATOR_OVER
+ if arc.level_polarity == 'dark'
+ else cairo.OPERATOR_CLEAR)
+ else:
+ self.ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
+ self.ctx.set_operator(cairo.OPERATOR_CLEAR)
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. self.ctx.set_line_width(width * self.scale[0])
self.ctx.set_line_cap(cairo.LINE_CAP_ROUND)
self.ctx.move_to(*start) # You actually have to do this...
if arc.direction == 'counterclockwise':
+<<<<<<< HEAD self.ctx.arc(center[0], center[1], radius, angle1, angle2)
else:
self.ctx.arc_negative(center[0], center[1], radius, angle1, angle2)
+======= + self.ctx.arc(*center, radius=radius, angle1=angle1, angle2=angle2)
+ else:
+ self.ctx.arc_negative(*center, radius=radius,
+ angle1=angle1, angle2=angle2)
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. self.ctx.move_to(*end) # ...lame
def _render_region(self, region, color):
if not self.invert:
+<<<<<<< HEAD self.ctx.set_source_rgba(color[0], color[1], color[2], alpha=self.alpha)
self.ctx.set_operator(cairo.OPERATOR_OVER
if region.level_polarity == "dark"
+======= + self.ctx.set_source_rgba(*color, alpha=self.alpha)
+ self.ctx.set_operator(cairo.OPERATOR_OVER
+ if region.level_polarity == 'dark'
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. else cairo.OPERATOR_CLEAR)
else:
self.ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
self.ctx.set_operator(cairo.OPERATOR_CLEAR)
+<<<<<<< HEAD +======= +>>>>>>> 5476da8... Fix a bunch of rendering bugs. self.ctx.set_line_width(0)
self.ctx.set_line_cap(cairo.LINE_CAP_ROUND)
self.ctx.move_to(*self.scale_point(region.primitives[0].start))
@@ -220,6 +262,7 @@ class GerberCairoContext(GerberContext): else:
self.ctx.arc_negative(*center, radius=radius,
angle1=angle1, angle2=angle2)
+<<<<<<< HEAD self.ctx.fill()
def _render_circle(self, circle, color):
center = self.scale_point(circle.position)
@@ -249,10 +292,28 @@ class GerberCairoContext(GerberContext): self.ctx.pop_group_to_source()
self.ctx.paint_with_alpha(1) +======= + self.ctx.fill()
+
+ def _render_circle(self, circle, color):
+ center = self.scale_point(circle.position)
+ if not self.invert:
+ self.ctx.set_source_rgba(*color, alpha=self.alpha)
+ self.ctx.set_operator(
+ cairo.OPERATOR_OVER if circle.level_polarity == 'dark' else cairo.OPERATOR_CLEAR)
+ else:
+ self.ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
+ self.ctx.set_operator(cairo.OPERATOR_CLEAR)
+ self.ctx.set_line_width(0)
+ self.ctx.arc(*center, radius=circle.radius *
+ self.scale[0], angle1=0, angle2=2 * math.pi)
+ self.ctx.fill()
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. def _render_rectangle(self, rectangle, color):
lower_left = self.scale_point(rectangle.lower_left)
width, height = tuple([abs(coord) for coord in self.scale_point((rectangle.width, rectangle.height))])
+<<<<<<< HEAD if not self.invert:
self.ctx.set_source_rgba(color[0], color[1], color[2], alpha=self.alpha)
@@ -295,6 +356,19 @@ class GerberCairoContext(GerberContext): if rectangle.rotation != 0:
self.ctx.restore() +======= +
+ if not self.invert:
+ self.ctx.set_source_rgba(*color, alpha=self.alpha)
+ self.ctx.set_operator(
+ cairo.OPERATOR_OVER if rectangle.level_polarity == 'dark' else cairo.OPERATOR_CLEAR)
+ else:
+ self.ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
+ self.ctx.set_operator(cairo.OPERATOR_CLEAR)
+ self.ctx.set_line_width(0)
+ self.ctx.rectangle(*lower_left, width=width, height=height)
+ self.ctx.fill()
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. def _render_obround(self, obround, color):
@@ -424,7 +498,11 @@ class GerberCairoContext(GerberContext): def _flatten(self):
self.output_ctx.set_operator(cairo.OPERATOR_OVER)
+<<<<<<< HEAD ptn = cairo.SurfacePattern(self.active_layer) +======= + ptn = cairo.SurfacePattern(self.active_layer)
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. ptn.set_matrix(self._xform_matrix)
self.output_ctx.set_source(ptn)
self.output_ctx.paint()
@@ -435,8 +513,16 @@ class GerberCairoContext(GerberContext): if (not self.bg) or force: self.bg = True
self.output_ctx.set_operator(cairo.OPERATOR_OVER)
+<<<<<<< HEAD self.output_ctx.set_source_rgba(self.background_color[0], self.background_color[1], self.background_color[2], alpha=1.0)
self.output_ctx.paint()
def scale_point(self, point):
- return tuple([coord * scale for coord, scale in zip(point, self.scale)])
\ No newline at end of file + return tuple([coord * scale for coord, scale in zip(point, self.scale)])
+======= + self.output_ctx.set_source_rgba(*self.background_color, alpha=1.0)
+ self.output_ctx.paint()
+
+ def scale_point(self, point):
+ return tuple([coord * scale for coord, scale in zip(point, self.scale)])
+>>>>>>> 5476da8... Fix a bunch of rendering bugs. diff --git a/gerber/render/render.py b/gerber/render/render.py index 7bd4c00..b319648 100644 --- a/gerber/render/render.py +++ b/gerber/render/render.py @@ -182,6 +182,7 @@ class GerberContext(object): return + def _render_line(self, primitive, color): pass |