mirror of
https://gitlab.constantvzw.org/osp/tools.cobbled-paths.git
synced 2024-12-23 21:11:24 +01:00
solved conflict
This commit is contained in:
commit
c294eccc1a
41
README.md
41
README.md
@ -7,10 +7,47 @@ smooth connected paths are made out of an extremely restrictive grid, like multi
|
|||||||
|
|
||||||
## dependencies
|
## 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
|
## font database
|
||||||
|
|
||||||
* figlet offical ftp at <ftp://ftp.figlet.org>
|
* 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
|
* `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
|
* `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.
|
* `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 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
36
app.py
@ -350,29 +350,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': f'attachment; filename="cobbled-paths-{id}.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__':
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
Flask
|
Flask
|
||||||
pyinkscape
|
|
||||||
requests
|
requests
|
30
scripts/make_flf.py
Normal file
30
scripts/make_flf.py
Normal file
@ -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)
|
@ -5,7 +5,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<script src="/static/js/FileSaver.js"></script>
|
<script src="/static/js/FileSaver.js"></script>
|
||||||
<style>
|
<style>
|
||||||
#save-svg{
|
#save-buttons{
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0.5em;
|
top: 0.5em;
|
||||||
right: 0.5em;
|
right: 0.5em;
|
||||||
@ -31,7 +31,10 @@
|
|||||||
|
|
||||||
{{ svg|safe }}
|
{{ 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>
|
<script>
|
||||||
function get2bodyclass(){
|
function get2bodyclass(){
|
||||||
@ -62,6 +65,25 @@
|
|||||||
let blob = new Blob([source], {type: "text/plain;charset=utf-8"});
|
let blob = new Blob([source], {type: "text/plain;charset=utf-8"});
|
||||||
saveAs(blob, 'cobbled-paths.svg');
|
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>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@ -58,7 +58,10 @@
|
|||||||
|
|
||||||
<div class="f-ascii"><pre>{{ ascii|safe }}</pre></div>
|
<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>
|
<script>
|
||||||
function get2bodyclass(){
|
function get2bodyclass(){
|
||||||
@ -88,6 +91,25 @@
|
|||||||
let blob = new Blob([source], {type: "text/plain;charset=utf-8"});
|
let blob = new Blob([source], {type: "text/plain;charset=utf-8"});
|
||||||
saveAs(blob, 'cobbled-paths.svg');
|
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>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user