summaryrefslogtreecommitdiff
path: root/gerber/render/cairo_backend.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2015-12-20 23:54:20 -0500
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2015-12-20 23:54:20 -0500
commitaf5541ac93b222c05229ee05c9def8dbae5f6e25 (patch)
tree947d56c540c66e589dff563ccb367c47547dfdad /gerber/render/cairo_backend.py
parentd1598b46c91ee36719460d49d7ba2ed5ecd0ef45 (diff)
downloadgerbonara-af5541ac93b222c05229ee05c9def8dbae5f6e25.tar.gz
gerbonara-af5541ac93b222c05229ee05c9def8dbae5f6e25.tar.bz2
gerbonara-af5541ac93b222c05229ee05c9def8dbae5f6e25.zip
Allow renderer to write to memory per #38
Some updates to rendering colors/themes
Diffstat (limited to 'gerber/render/cairo_backend.py')
-rw-r--r--gerber/render/cairo_backend.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py
index c8f94ff..8283ae0 100644
--- a/gerber/render/cairo_backend.py
+++ b/gerber/render/cairo_backend.py
@@ -15,16 +15,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from .render import GerberContext
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):
@@ -184,7 +188,7 @@ class GerberCairoContext(GerberContext):
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.color, alpha=self.alpha)
self.mask_ctx.paint()
@@ -214,7 +218,16 @@ class GerberCairoContext(GerberContext):
else:
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()