summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gerber/cam.py3
-rw-r--r--gerber/exceptions.py4
-rw-r--r--gerber/render/cairo_backend.py25
-rw-r--r--gerber/render/theme.py17
-rw-r--r--gerber/rs274x.py3
-rw-r--r--gerber/tests/test_cairo_backend.py3
6 files changed, 39 insertions, 16 deletions
diff --git a/gerber/cam.py b/gerber/cam.py
index ae96474..28918cb 100644
--- a/gerber/cam.py
+++ b/gerber/cam.py
@@ -262,9 +262,10 @@ class CamFile(object):
ctx.set_bounds(self.bounds)
ctx._paint_background()
+
if invert:
ctx.invert = True
- ctx._paint_inverted_layer()
+ ctx._clear_mask()
for p in self.primitives:
ctx.render(p)
if invert:
diff --git a/gerber/exceptions.py b/gerber/exceptions.py
index 71defd1..fdd548c 100644
--- a/gerber/exceptions.py
+++ b/gerber/exceptions.py
@@ -18,14 +18,18 @@
class ParseError(Exception):
pass
+
class GerberParseError(ParseError):
pass
+
class ExcellonParseError(ParseError):
pass
+
class ExcellonFileError(IOError):
pass
+
class GerberFileError(IOError):
pass
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py
index 3c4a395..fe27d60 100644
--- a/gerber/render/cairo_backend.py
+++ b/gerber/render/cairo_backend.py
@@ -15,19 +15,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from .render import GerberContext
-
+
try:
import cairo
except ImportError:
- import cairocffi as cairo
-
+ import cairocffi as cairo
from operator import mul
import math
import tempfile
+from .render import GerberContext
from ..primitives import *
+try:
+ from cStringIO import StringIO
+except(ImportError):
+ from io import StringIO
+
class GerberCairoContext(GerberContext):
def __init__(self, scale=300):
@@ -272,8 +276,8 @@ class GerberCairoContext(GerberContext):
self.ctx.scale(1, -1)
self.ctx.show_text(primitive.net_name)
self.ctx.scale(1, -1)
-
- def _paint_inverted_layer(self):
+
+ def _clear_mask(self):
self.mask_ctx.set_operator(cairo.OPERATOR_OVER)
self.mask_ctx.set_source_rgba(self.background_color[0], self.background_color[1], self.background_color[2], alpha=self.alpha)
self.mask_ctx.paint()
@@ -302,7 +306,16 @@ class GerberCairoContext(GerberContext):
else:
return self.surface.write_to_png(filename)
+ def dump_str(self):
+ """ Return a string containing the rendered image.
+ """
+ fobj = StringIO()
+ self.surface.write_to_png(fobj)
+ return fobj.getvalue()
+
def dump_svg_str(self):
+ """ Return a string containg the rendered SVG.
+ """
self.surface.finish()
self.surface_buffer.flush()
return self.surface_buffer.read()
diff --git a/gerber/render/theme.py b/gerber/render/theme.py
index 5d39bb6..eae3735 100644
--- a/gerber/render/theme.py
+++ b/gerber/render/theme.py
@@ -19,12 +19,13 @@
COLORS = {
'black': (0.0, 0.0, 0.0),
'white': (1.0, 1.0, 1.0),
- 'fr-4': (0.702, 0.655, 0.192),
+ 'fr-4': (0.290, 0.345, 0.0),
'green soldermask': (0.0, 0.612, 0.396),
'blue soldermask': (0.059, 0.478, 0.651),
'red soldermask': (0.968, 0.169, 0.165),
'black soldermask': (0.298, 0.275, 0.282),
- 'enig copper': (0.780, 0.588, 0.286),
+ 'purple soldermask': (0.2, 0.0, 0.334),
+ 'enig copper': (0.686, 0.525, 0.510),
'hasl copper': (0.871, 0.851, 0.839)
}
@@ -40,11 +41,19 @@ class Theme(object):
def __init__(self, **kwargs):
self.background = kwargs.get('background', RenderSettings(COLORS['black'], 0.0))
self.topsilk = kwargs.get('topsilk', RenderSettings(COLORS['white']))
- self.topsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white']))
- self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], 0.8, True))
+ self.bottomsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white']))
self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], 0.8, True))
+ self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], 0.8, True))
self.top = kwargs.get('top', RenderSettings(COLORS['hasl copper']))
self.bottom = kwargs.get('top', RenderSettings(COLORS['hasl copper']))
self.drill = kwargs.get('drill', self.background)
+THEMES = {
+ 'Default': Theme(),
+ 'Osh Park': Theme(top=COLORS['enig copper'],
+ bottom=COLORS['enig copper'],
+ topmask=COLORS['purple soldermask'],
+ bottommask=COLORS['purple soldermask']),
+}
+
diff --git a/gerber/rs274x.py b/gerber/rs274x.py
index f8b3222..260fbf8 100644
--- a/gerber/rs274x.py
+++ b/gerber/rs274x.py
@@ -114,16 +114,13 @@ class GerberFile(CamFile):
def bounds(self):
min_x = min_y = 1000000
max_x = max_y = -1000000
-
for stmt in [stmt for stmt in self.statements if isinstance(stmt, CoordStmt)]:
if stmt.x is not None:
min_x = min(stmt.x, min_x)
max_x = max(stmt.x, max_x)
-
if stmt.y is not None:
min_y = min(stmt.y, min_y)
max_y = max(stmt.y, max_y)
-
return ((min_x, max_x), (min_y, max_y))
@property
diff --git a/gerber/tests/test_cairo_backend.py b/gerber/tests/test_cairo_backend.py
index d7ec7b3..e298439 100644
--- a/gerber/tests/test_cairo_backend.py
+++ b/gerber/tests/test_cairo_backend.py
@@ -2,15 +2,14 @@
# -*- coding: utf-8 -*-
# Author: Garret Fick <garret@ficksworkshop.com>
-import os
import io
+import os
from ..render.cairo_backend import GerberCairoContext
from ..rs274x import read, GerberFile
from .tests import *
-
TWO_BOXES_FILE = os.path.join(os.path.dirname(__file__),
'resources/example_two_square_boxes.gbr')
TWO_BOXES_EXPECTED = os.path.join(os.path.dirname(__file__),