diff --git a/README.md b/README.md index 9593e387a8c303867b1a83d240ce5a94ca28af2e..46c4938e73e39d5ea048de625479da51e3cf7ab0 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,47 @@ smooth connected paths are made out of an extremely restrictive grid, like multi ## dependencies +* python +* flask +* figlet +* svgbob +* [optional] [vpype](https://github.com/abey79/vpype), for converting to HPGL + +## installation + +Firstly [download](https://gitlab.constantvzw.org/osp/tools.cobbled-paths/-/archive/master/tools.cobbled-paths-master.zip) this repository, or clone it: `git clone git@gitlab.constantvzw.org:osp/tools.cobbled-paths.git` + +### Python + +The interface uses python and require python 3, find information on how to [install python here](https://www.python.org/downloads/) + +Then, use pip to install the requirements with: + +```pip install -r requirements.txt``` + +### Figlet + +On **linux**, install it with package manager: `apt install figlet`, or `pacman -S figlet` + +On **Mac**, you can either download a pre-built binary from the [figlet website](http://www.figlet.org/), or install it with [Homebrew](https://brew.sh/): `brew install figlet`. + + +### To install SVG Bob + +Ensure you have rust installed, [installation instructions here](https://www.rust-lang.org/tools/install) + +Then `cargo install svgbob_cli` + +### vpype + +Installation of vpype is optional. It is used to convert the SVG files to HPGL. + +Please follow the [installation instructions](https://github.com/abey79/vpype#installation) + ## font database * figlet offical ftp at <ftp://ftp.figlet.org> - * `ours` the original default font made by the developper and given with the program, in early 1993 + * `ours` the original default font made by the developer and given with the program, in early 1993 * `contributed` fonts made by figlet amateur and submitted to the official figlet ftp, from before 1993 to 2005 * `c64` are fonts that are only made of the `#` character, the most black ascii char, is if it was a pixel * `bdffont` are fonts automatically made using bdf2figlet, converting [Glyph Bitmap Distribution Format](https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format), often from adobe to `c64` like font. @@ -28,4 +65,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 342a7b90a150c1326e0f5bff02b1c229014e7f5a..13a7e7cc59ca257a6cfce6df8001fdb9dc878217 100644 --- a/app.py +++ b/app.py @@ -350,29 +350,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': f'attachment; filename="cobbled-paths-{id}.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__': diff --git a/requirements.txt b/requirements.txt index 0021545742166a0cda9256e87f6c634a25919d33..0eb56cde55b46acb6505560d24f7cc6d5b5ba89f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ Flask -pyinkscape requests \ No newline at end of file diff --git a/scripts/make_flf.py b/scripts/make_flf.py new file mode 100644 index 0000000000000000000000000000000000000000..750a103a450d159c7bb7da68226f1add93b6fa39 --- /dev/null +++ b/scripts/make_flf.py @@ -0,0 +1,30 @@ +import sys + +""" + Generates glyphs entries for an FLF file. + It does not generate the file header. + + Run like: make_flf.py [glyph_height] +""" + +height = int(sys.argv[1]) + +flf = '' + +for chr_code in range(32, 126): + for line in range(height): + flf += " " + + if line == 0: + flf += chr(chr_code) + else: + flf += " " + + flf += "@" + + if line == height-1: + flf += "@" + + flf += "\n" + +print(flf) \ No newline at end of file diff --git a/templates/drawing.html b/templates/drawing.html index f34a745ec0ed68ca35153025bb38c7e32e9ead6e..b7e80554134042f5d05aec81fe5a8f6fb06a9727 100644 --- a/templates/drawing.html +++ b/templates/drawing.html @@ -5,7 +5,7 @@ <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="/static/js/FileSaver.js"></script> <style> - #save-svg{ + #save-buttons{ position: fixed; top: 0.5em; right: 0.5em; @@ -31,7 +31,10 @@ {{ svg|safe }} - <button id="save-svg">get SVG</button> + <div id="save-buttons"> + <button id="save-svg">get SVG</button> + <button id="save-hpgl">get HPGL</button> + </div> <script> function get2bodyclass(){ @@ -62,6 +65,25 @@ let blob = new Blob([source], {type: "text/plain;charset=utf-8"}); saveAs(blob, 'cobbled-paths.svg'); }); + + let save_button_hpgl = document.getElementById('save-hpgl'); + save_button_hpgl.addEventListener('click', function () { + let url = document.URL, + parts = url.split('/'), + name = parts[parts.length-1], + hpgl_url = '/hpgl/' + name, + a = document.createElement('a'); + a.href = hpgl_url; + a.setAttribute('download', 'download'); + if (document.createEvent) { + const event = document.createEvent('MouseEvents'); + event.initEvent('click', true, true); + a.dispatchEvent(event); + } + else { + a.click(); + } + }); </script> </body> diff --git a/templates/writing.html b/templates/writing.html index 0e08a0b3dd8b8017dddd7397fd5d63968cba56ef..317e7d243fb6dd2af49bab52c5b85654b445bb21 100644 --- a/templates/writing.html +++ b/templates/writing.html @@ -58,7 +58,10 @@ <div class="f-ascii"><pre>{{ ascii|safe }}</pre></div> - <button id="save-svg">get SVG</button> + <div id="save-buttons"> + <button id="save-svg">get SVG</button> + <button id="save-hpgl">get HPGL</button> + </div> <script> function get2bodyclass(){ @@ -88,6 +91,25 @@ let blob = new Blob([source], {type: "text/plain;charset=utf-8"}); saveAs(blob, 'cobbled-paths.svg'); }); + + let save_button_hpgl = document.getElementById('save-hpgl'); + save_button_hpgl.addEventListener('click', function () { + let url = document.URL, + parts = url.split('/'), + name = parts[parts.length-1], + hpgl_url = '/hpgl/' + name, + a = document.createElement('a'); + a.href = hpgl_url; + a.setAttribute('download', 'download'); + if (document.createEvent) { + const event = document.createEvent('MouseEvents'); + event.initEvent('click', true, true); + a.dispatchEvent(event); + } + else { + a.click(); + } + }); </script> </body>