Add svg_Ponoko output format

This is just regular SVG with Ponoko-specific line properties
Yes, the lines are too thin to be seen in a regular web browser.

Resolves: #112
This commit is contained in:
Wayne Wylupski 2019-01-21 23:40:16 -05:00 committed by Florian Festi
parent abacdd486e
commit c5d434105b
2 changed files with 19 additions and 8 deletions

View File

@ -281,8 +281,14 @@ class Boxes:
self.bedBoltSettings = (3, 5.5, 2, 20, 15) # d, d_nut, h_nut, l, l1
self.hexHolesSettings = (5, 3, 'circle') # r, dist, style
self.surface, self.ctx = self.formats.getSurface(self.format, self.output)
self.ctx.set_line_width(max(2 * self.burn, 0.05))
self.set_source_color(Color.BLACK)
if self.format == 'svg_Ponoko':
self.ctx.set_line_width(0.01)
self.set_source_color(Color.BLUE)
else:
self.ctx.set_line_width(max(2 * self.burn, 0.05))
self.set_source_color(Color.BLACK)
self.spacing = 2 * self.burn + 0.5 * self.thickness
self.ctx.select_font_face("sans-serif")
self._buildObjects()
@ -404,8 +410,9 @@ class Boxes:
setattr(self, key, value)
# Change file ending to format if not given explicitly
format = getattr(self, "format", "svg")
if getattr(self, 'output', None) == 'box.svg':
self.output = 'box.' + getattr(self, "format", "svg")
self.output = 'box.' + format.split("_")[0]
def addPart(self, part, name=None):
"""

View File

@ -22,7 +22,6 @@ import cairo
import re
from boxes import svgutil
class PSFile:
def __init__(self, filename):
self.filename = filename
@ -43,10 +42,14 @@ class PSFile:
class Formats:
pstoedit = "/usr/bin/pstoedit"
_BASE_FORMATS = ['svg', 'svg_Ponoko', 'ps']
formats = {
"svg": None,
"svg_Ponoko": None,
"ps": None,
"dxf": "-flat 0.1 -f dxf:-mm".split(),
"gcode": "-f gcode".split(),
@ -57,6 +60,7 @@ class Formats:
http_headers = {
"svg": [('Content-type', 'image/svg+xml; charset=utf-8')],
"svg_Ponoko": [('Content-type', 'image/svg+xml; charset=utf-8')],
"ps": [('Content-type', 'application/postscript')],
"dxf": [('Content-type', 'image/vnd.dxf')],
"plt": [('Content-type', ' application/vnd.hp-hpgl')],
@ -72,13 +76,13 @@ class Formats:
if os.path.isfile(self.pstoedit):
return sorted(self.formats.keys())
else:
return ['svg', 'ps']
return self._BASE_FORMATS
def getSurface(self, fmt, filename):
width = height = 10000 # mm
if fmt == "svg":
if fmt in ("svg", "svg_Ponoko"):
surface = cairo.SVGSurface(filename, width, height)
mm2pt = 1.0
else:
@ -95,7 +99,7 @@ class Formats:
def convert(self, filename, fmt):
if fmt == 'svg':
if fmt in ['svg', 'svg_Ponoko']:
svg = svgutil.SVGFile(filename)
svg.getEnvelope()
svg.rewriteViewPort()
@ -103,7 +107,7 @@ class Formats:
ps = PSFile(filename)
ps.adjustDocumentMedia()
if fmt not in ("svg", "ps"):
if fmt not in self._BASE_FORMATS:
fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(filename))
cmd = [self.pstoedit] + self.formats[fmt] + [filename, tmpfile]
err = subprocess.call(cmd)