diff options
author | Garret Fick <garret@ficksworkshop.com> | 2016-07-17 21:04:15 +0800 |
---|---|---|
committer | Garret Fick <garret@ficksworkshop.com> | 2016-07-17 21:04:15 +0800 |
commit | 34f20ee90fc54ca046460bfae06bce927870536f (patch) | |
tree | f29e30bf0747b45cab5545ad4d49ff07518aad00 /gerber/render/cairo_backend.py | |
parent | f0585baefa54c5cd891ba04c81053956b1a59977 (diff) | |
parent | af5541ac93b222c05229ee05c9def8dbae5f6e25 (diff) | |
download | gerbonara-34f20ee90fc54ca046460bfae06bce927870536f.tar.gz gerbonara-34f20ee90fc54ca046460bfae06bce927870536f.tar.bz2 gerbonara-34f20ee90fc54ca046460bfae06bce927870536f.zip |
Manually merge af5541ac93b222c05229ee05c9def8dbae5f6e25
Diffstat (limited to 'gerber/render/cairo_backend.py')
-rw-r--r-- | gerber/render/cairo_backend.py | 25 |
1 files changed, 19 insertions, 6 deletions
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()
|