Browse Source

Added conversion to HPGL with vpye.

master
Gijs 6 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 ## dependencies
* [vpype](https://github.com/abey79/vpype), for converting to HPGL, [Installation instructions](https://github.com/abey79/vpype#installation)
## font database ## font database
* figlet offical ftp at <ftp://ftp.figlet.org> * 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 JS
* factorise CSS * factorise CSS
* show font-info file * 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 # to SVG
svg = ascii2svg(ascii, params['weight']) 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'\<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) 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 # store as a temporary file
(svg_file, svg_path) = tempfile.mkstemp('.svg') (svg_file, svg_path) = tempfile.mkstemp('.svg')
(hpgl_file, hpgl_path) = tempfile.mkstemp('.hpgl')
with open(svg_file, 'w') as svg_handle: with open(svg_file, 'w') as svg_handle:
svg_handle.write(svg) svg_handle.write(svg)
# transform to hpgl output = subprocess.run([
hpgl = svgToHPGL(svg_path) "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 # remove tmp file
os.remove(svg_path) os.remove(svg_path)
os.remove(hpgl_path)
r = Response(hpgl, mimetype='application/hpgl')
r.headers.extend({
'Content-Disposition': 'attachment; filename="cobbled-paths.hpgl"'
})
return r return r
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save