diff --git a/README.md b/README.md index 9593e387a8c303867b1a83d240ce5a94ca28af2e..a9f41b872c7ea449e84b9bf918cd4e28d6769d86 100644 --- a/README.md +++ b/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 \ No newline at end of file +* option to save as hpgl diff --git a/app.py b/app.py index dce53a129e213258192647b6191fe4346b861e1f..9462b4c07a21d7fb73c5ec1c40beeac0b8756bdc 100644 --- a/app.py +++ b/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__':