From 91584a306a8e458b447bf79aa40eed73e5d8feab Mon Sep 17 00:00:00 2001 From: Gijs Date: Thu, 28 Mar 2024 10:40:32 +0100 Subject: [PATCH 1/4] HPGL export works now. --- app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index d010bf9..f31025b 100644 --- a/app.py +++ b/app.py @@ -243,8 +243,11 @@ def hpgl (id): svg = ascii2svg(ascii_input, params['weight']) # store as a temporary file - (svg_file, svg_path) = tempfile.mkstemp() - svg_file.write(svg) + (svg_file, svg_path) = tempfile.mkstemp('.svg') + + + with open(svg_file, 'w') as svg_handle: + svg_handle.write(svg) # transform to hpgl hpgl = svgToHPGL(svg_path) From 3719c7a1ec4a1e2810aa10f2df254defb661e4ef Mon Sep 17 00:00:00 2001 From: Gijs Date: Thu, 28 Mar 2024 14:33:32 +0100 Subject: [PATCH 2/4] Remove background from SVGBob file. --- app.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app.py b/app.py index 5993b6d..7f089f1 100644 --- a/app.py +++ b/app.py @@ -247,6 +247,10 @@ def hpgl (id): # to SVG svg = ascii2svg(ascii_input, params['weight']) + svg = re.sub(r'\\<\/rect\>', '', svg, flags=re.M) + + #print(svg) + # store as a temporary file (svg_file, svg_path) = tempfile.mkstemp('.svg') From 64839e50bd2335c6e3161e0d05a9066fb2fab4c9 Mon Sep 17 00:00:00 2001 From: Gijs Date: Fri, 29 Mar 2024 10:17:28 +0100 Subject: [PATCH 3/4] Set correct dimensions on HPGL export --- app.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app.py b/app.py index 06dfeff..e079df3 100644 --- a/app.py +++ b/app.py @@ -290,6 +290,16 @@ def catalogue(): # # FIGLET 2 SVGBOB INTERACTIVE CATALOGUE +def resizeSVG (m): + width = int(m.group(1)) + height = int(m.group(2)) + + viewbox = f'0 0 {width} {height}' + + newHeight = 420 + newWidth = (width/height) * newHeight + + return f'' @app.route('/hpgl/') def hpgl (id): @@ -309,6 +319,8 @@ def hpgl (id): svg = re.sub(r'\\<\/rect\>', '', svg, flags=re.M) + svg = re.sub(r'', resizeSVG,svg) + #print(svg) # store as a temporary file From 07328fdbaeae6e7160d0235bfec4effc64d86b0f Mon Sep 17 00:00:00 2001 From: Gijs Date: Fri, 29 Mar 2024 10:18:03 +0100 Subject: [PATCH 4/4] Diffent event listener to avoid overload. --- svg_to_hpgl.py | 19 ++++++++++++++----- templates/font.html | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/svg_to_hpgl.py b/svg_to_hpgl.py index 0a3acf3..7e55b91 100644 --- a/svg_to_hpgl.py +++ b/svg_to_hpgl.py @@ -1,14 +1,23 @@ -# from hpgl_multipen_output import HpglMultipenOutput -from hpgl_output_adapted import HpglOutputAdapted +from hpgl_multipen_output import HpglMultipenOutput +import subprocess +# from hpgl_output_adapted import HpglOutputAdapted def svgToHPGL (path, speed=1, penCount=8, force=2): - e = HpglOutputAdapted() + + subprocess.call(['inkscape', + '-f', path, + '--verb', 'EditSelectAll', + '--verb', 'ObjectToPath', + '--verb', 'FileSave', + '--verb', 'FileQuit' ]) + + e = HpglMultipenOutput() e.affect([ - '--orientation', '0', + '--orientation', '270', '--force', '0', '--overcut', '0', '--precut', 'false', - '--flat', '4', + '--flat', '8', '--toolOffset', '0', '--autoAlign', 'false', '--speed', str(speed), diff --git a/templates/font.html b/templates/font.html index bdc6638..62bed1c 100644 --- a/templates/font.html +++ b/templates/font.html @@ -72,7 +72,7 @@ // --- get-input but on the pad and checkbox but on the pad let inputs = document.getElementsByClassName('get-input'); for(let input of inputs){ - input.addEventListener('input', function(){ + input.addEventListener('change', function(){ let frame = document.getElementById(input.dataset.frame); const url = new URL(frame.src);