|
|
@ -345,29 +345,45 @@ def hpgl (id): |
|
|
|
|
|
|
|
# to SVG |
|
|
|
svg = ascii2svg(ascii, params['weight']) |
|
|
|
|
|
|
|
# Remove background rect inserted by SVG Bob |
|
|
|
svg = re.sub(r'\<rect class="backdrop" x="\d+" y="\d+" width="\d+" height="\d+">\<\/rect\>', '', svg, flags=re.M) |
|
|
|
|
|
|
|
svg = re.sub(r'<svg xmlns="http://www.w3.org/2000/svg" width="(\d+)" height="(\d+)" class="svgbob">', resizeSVG,svg) |
|
|
|
|
|
|
|
#print(svg) |
|
|
|
|
|
|
|
# store as a temporary file |
|
|
|
(svg_file, svg_path) = tempfile.mkstemp('.svg') |
|
|
|
(hpgl_file, hpgl_path) = tempfile.mkstemp('.hpgl') |
|
|
|
|
|
|
|
with open(svg_file, 'w') as svg_handle: |
|
|
|
svg_handle.write(svg) |
|
|
|
|
|
|
|
# transform to hpgl |
|
|
|
hpgl = svgToHPGL(svg_path) |
|
|
|
output = subprocess.run([ |
|
|
|
"vpype", |
|
|
|
"read", |
|
|
|
"--single-layer", |
|
|
|
svg_path, |
|
|
|
"scaleto", |
|
|
|
"297mm", "420mm", |
|
|
|
"linemerge", |
|
|
|
"-t", "0.25mm", |
|
|
|
"linesort", |
|
|
|
"write", |
|
|
|
"--device", "dxy", |
|
|
|
"--color-mode", "none", |
|
|
|
"--page-size", "a3", |
|
|
|
"--landscape", |
|
|
|
hpgl_path |
|
|
|
]) |
|
|
|
|
|
|
|
with open(hpgl_file, 'r') as hpgl_handle: |
|
|
|
r = Response(hpgl_handle.read(), mimetype='application/hpgl') |
|
|
|
r.headers.extend({ |
|
|
|
'Content-Disposition': 'attachment; filename="cobbled-paths.hpgl"' |
|
|
|
}) |
|
|
|
|
|
|
|
# remove tmp file |
|
|
|
os.remove(svg_path) |
|
|
|
|
|
|
|
r = Response(hpgl, mimetype='application/hpgl') |
|
|
|
r.headers.extend({ |
|
|
|
'Content-Disposition': 'attachment; filename="cobbled-paths.hpgl"' |
|
|
|
}) |
|
|
|
os.remove(hpgl_path) |
|
|
|
return r |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|