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:
parent
abacdd486e
commit
c5d434105b
|
@ -281,8 +281,14 @@ class Boxes:
|
||||||
self.bedBoltSettings = (3, 5.5, 2, 20, 15) # d, d_nut, h_nut, l, l1
|
self.bedBoltSettings = (3, 5.5, 2, 20, 15) # d, d_nut, h_nut, l, l1
|
||||||
self.hexHolesSettings = (5, 3, 'circle') # r, dist, style
|
self.hexHolesSettings = (5, 3, 'circle') # r, dist, style
|
||||||
self.surface, self.ctx = self.formats.getSurface(self.format, self.output)
|
self.surface, self.ctx = self.formats.getSurface(self.format, self.output)
|
||||||
|
|
||||||
|
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.ctx.set_line_width(max(2 * self.burn, 0.05))
|
||||||
self.set_source_color(Color.BLACK)
|
self.set_source_color(Color.BLACK)
|
||||||
|
|
||||||
self.spacing = 2 * self.burn + 0.5 * self.thickness
|
self.spacing = 2 * self.burn + 0.5 * self.thickness
|
||||||
self.ctx.select_font_face("sans-serif")
|
self.ctx.select_font_face("sans-serif")
|
||||||
self._buildObjects()
|
self._buildObjects()
|
||||||
|
@ -404,8 +410,9 @@ class Boxes:
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
# Change file ending to format if not given explicitly
|
# Change file ending to format if not given explicitly
|
||||||
|
format = getattr(self, "format", "svg")
|
||||||
if getattr(self, 'output', None) == 'box.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):
|
def addPart(self, part, name=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -22,7 +22,6 @@ import cairo
|
||||||
import re
|
import re
|
||||||
from boxes import svgutil
|
from boxes import svgutil
|
||||||
|
|
||||||
|
|
||||||
class PSFile:
|
class PSFile:
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
@ -43,10 +42,14 @@ class PSFile:
|
||||||
|
|
||||||
|
|
||||||
class Formats:
|
class Formats:
|
||||||
|
|
||||||
pstoedit = "/usr/bin/pstoedit"
|
pstoedit = "/usr/bin/pstoedit"
|
||||||
|
|
||||||
|
_BASE_FORMATS = ['svg', 'svg_Ponoko', 'ps']
|
||||||
|
|
||||||
formats = {
|
formats = {
|
||||||
"svg": None,
|
"svg": None,
|
||||||
|
"svg_Ponoko": None,
|
||||||
"ps": None,
|
"ps": None,
|
||||||
"dxf": "-flat 0.1 -f dxf:-mm".split(),
|
"dxf": "-flat 0.1 -f dxf:-mm".split(),
|
||||||
"gcode": "-f gcode".split(),
|
"gcode": "-f gcode".split(),
|
||||||
|
@ -57,6 +60,7 @@ class Formats:
|
||||||
|
|
||||||
http_headers = {
|
http_headers = {
|
||||||
"svg": [('Content-type', 'image/svg+xml; charset=utf-8')],
|
"svg": [('Content-type', 'image/svg+xml; charset=utf-8')],
|
||||||
|
"svg_Ponoko": [('Content-type', 'image/svg+xml; charset=utf-8')],
|
||||||
"ps": [('Content-type', 'application/postscript')],
|
"ps": [('Content-type', 'application/postscript')],
|
||||||
"dxf": [('Content-type', 'image/vnd.dxf')],
|
"dxf": [('Content-type', 'image/vnd.dxf')],
|
||||||
"plt": [('Content-type', ' application/vnd.hp-hpgl')],
|
"plt": [('Content-type', ' application/vnd.hp-hpgl')],
|
||||||
|
@ -72,13 +76,13 @@ class Formats:
|
||||||
if os.path.isfile(self.pstoedit):
|
if os.path.isfile(self.pstoedit):
|
||||||
return sorted(self.formats.keys())
|
return sorted(self.formats.keys())
|
||||||
else:
|
else:
|
||||||
return ['svg', 'ps']
|
return self._BASE_FORMATS
|
||||||
|
|
||||||
def getSurface(self, fmt, filename):
|
def getSurface(self, fmt, filename):
|
||||||
|
|
||||||
width = height = 10000 # mm
|
width = height = 10000 # mm
|
||||||
|
|
||||||
if fmt == "svg":
|
if fmt in ("svg", "svg_Ponoko"):
|
||||||
surface = cairo.SVGSurface(filename, width, height)
|
surface = cairo.SVGSurface(filename, width, height)
|
||||||
mm2pt = 1.0
|
mm2pt = 1.0
|
||||||
else:
|
else:
|
||||||
|
@ -95,7 +99,7 @@ class Formats:
|
||||||
|
|
||||||
def convert(self, filename, fmt):
|
def convert(self, filename, fmt):
|
||||||
|
|
||||||
if fmt == 'svg':
|
if fmt in ['svg', 'svg_Ponoko']:
|
||||||
svg = svgutil.SVGFile(filename)
|
svg = svgutil.SVGFile(filename)
|
||||||
svg.getEnvelope()
|
svg.getEnvelope()
|
||||||
svg.rewriteViewPort()
|
svg.rewriteViewPort()
|
||||||
|
@ -103,7 +107,7 @@ class Formats:
|
||||||
ps = PSFile(filename)
|
ps = PSFile(filename)
|
||||||
ps.adjustDocumentMedia()
|
ps.adjustDocumentMedia()
|
||||||
|
|
||||||
if fmt not in ("svg", "ps"):
|
if fmt not in self._BASE_FORMATS:
|
||||||
fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(filename))
|
fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(filename))
|
||||||
cmd = [self.pstoedit] + self.formats[fmt] + [filename, tmpfile]
|
cmd = [self.pstoedit] + self.formats[fmt] + [filename, tmpfile]
|
||||||
err = subprocess.call(cmd)
|
err = subprocess.call(cmd)
|
||||||
|
|
Loading…
Reference in New Issue