Browse Source

Added conversion to HPGL with vpye.

master
Gijs 4 months ago
parent
commit
8b8a1cf80f
  1. 4
      README.md
  2. 36
      app.py

4
README.md

@ -7,6 +7,8 @@ smooth connected paths are made out of an extremely restrictive grid, like multi
## dependencies
* [vpype](https://github.com/abey79/vpype), for converting to HPGL, [Installation instructions](https://github.com/abey79/vpype#installation)
## font database
* figlet offical ftp at <ftp://ftp.figlet.org>
@ -28,4 +30,4 @@ smooth connected paths are made out of an extremely restrictive grid, like multi
* factorise JS
* factorise CSS
* show font-info file
* option to save as hpgl
* option to save as hpgl

36
app.py

@ -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__':

Loading…
Cancel
Save