download simplified svg without bounding rectangle

This commit is contained in:
Doriane 2024-09-23 11:08:21 +02:00
parent ded8d13858
commit 0192fecef7
6 changed files with 74 additions and 38 deletions

35
app.py
View File

@ -413,18 +413,31 @@ def resizeSVG (m):
return f'<svg xmlns="http://www.w3.org/2000/svg" viewbox="{viewbox}" width="{newWidth}mm" height="{newHeight}mm" class="svgbob">' return f'<svg xmlns="http://www.w3.org/2000/svg" viewbox="{viewbox}" width="{newWidth}mm" height="{newHeight}mm" class="svgbob">'
# @app.route('/svg/<id>') @app.route('/svg/<id>')
# def svg (id): def svg (id):
# params = { params = {
# 'pad': id or 'default', 'pad': id or 'default',
# 'weight': request.args.get('w') or '2', 'weight': request.args.get('w') or '2',
# } }
# params['pad-full'] = etherpad + prefix + params['pad'] params['pad-full'] = etherpad + prefix + params['pad']
# # get pad content # get pad content
# print(' getting ' + params['pad-full']) print(' getting ' + params['pad-full'])
# pad_export = requests.get(params['pad-full'] + '/export/txt') pad_export = requests.get(params['pad-full'] + '/export/txt')
# ascii = pad_export.text ascii = pad_export.text
# to SVG
svg = simplifySVG(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)
r = Response(svg, mimetype='application/svg')
r.headers.extend({
'Content-Disposition': f'attachment; filename="cobbled-paths-{id}.svg"'
})
return r
@app.route('/hpgl/<id>') @app.route('/hpgl/<id>')

View File

@ -302,6 +302,11 @@ details[open] > summary{
color: white; color: white;
} }
#current-figfont,
.category{
width: 15em;
}
.collection-menu{ .collection-menu{
position: relative; position: relative;
} }
@ -348,7 +353,7 @@ summary + div{
max-height: calc(100vh - 1px - var(--bar-h)); max-height: calc(100vh - 1px - var(--bar-h));
overflow: auto; overflow: auto;
width: calc(100vw - 24rem); width: calc(100vw - 30rem);
display: grid; display: grid;
grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
gap: 1px; gap: 1px;
@ -394,6 +399,14 @@ summary + div{
mix-blend-mode: darken; mix-blend-mode: darken;
display: block; display: block;
} }
.legend{
width: 24rem;
font-size: 0.825rem;
margin-top: 1em;
}
.legend::before{ .legend::before{
content: ''; content: '';
width: 0.75rem; width: 0.75rem;

View File

@ -29,8 +29,8 @@
<ul> <ul>
<li><a {% if request.url_rule.endpoint == "index" %}class="active"{% endif %} href="/">about</a></li> <li><a {% if request.url_rule.endpoint == "index" %}class="active"{% endif %} href="/">about</a></li>
<li><a {% if request.url_rule.endpoint == "draw" %}class="active"{% endif %} href="/draw.html">ASCII draw</a></li> <li><a {% if request.url_rule.endpoint == "draw" %}class="active"{% endif %} href="/draw.html">ASCII draw</a></li>
<li><a {% if request.url_rule.endpoint == "font" %}class="active"{% endif %} href="/font.html">FIGfont make</a></li>
<li><a {% if request.url_rule.endpoint == "catalogue" %}class="active"{% endif %} href="/catalogue.html">FIGfont catalogue</a></li> <li><a {% if request.url_rule.endpoint == "catalogue" %}class="active"{% endif %} href="/catalogue.html">FIGfont catalogue</a></li>
<li><a {% if request.url_rule.endpoint == "font" %}class="active"{% endif %} href="/font.html">FIGfont make</a></li>
<!-- <li><a {% if request.url_rule.endpoint == "image" %}class="active"{% endif %} href="/image.html">image</a></li> --> <!-- <li><a {% if request.url_rule.endpoint == "image" %}class="active"{% endif %} href="/image.html">image</a></li> -->
<li><a {% if request.url_rule.endpoint == "gallery" %}class="active"{% endif %} href="/gallery.html">gallery</a></li> <li><a {% if request.url_rule.endpoint == "gallery" %}class="active"{% endif %} href="/gallery.html">gallery</a></li>
</ul> </ul>

View File

@ -22,7 +22,7 @@
</div> </div>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
<a class="specimen-link" href="/specimen/{{type}}" target="_blank">see all {{type}}</a> <!-- <a class="specimen-link" href="/specimen/{{type}}" target="_blank">see all {{type}}</a> -->
</div> </div>
</details> </details>

View File

@ -41,18 +41,23 @@
</script> </script>
<script> <script>
let save_button = document.getElementById('save-svg'); let save_button_svg = document.getElementById('save-svg');
save_button_svg.addEventListener('click', function(){
save_button.addEventListener('click', function(){ let url = document.URL,
//get svg element. parts = url.split('/'),
let svg = document.getElementsByTagName("svg")[0]; name = parts[parts.length-1],
svg_url = '/svg/' + name,
//get svg source. a = document.createElement('a');
let serializer = new XMLSerializer(); a.href = svg_url;
let source = serializer.serializeToString(svg); a.setAttribute('download', 'download');
if (document.createEvent) {
let blob = new Blob([source], {type: "text/plain;charset=utf-8"}); const event = document.createEvent('MouseEvents');
saveAs(blob, 'cobbled-paths.svg'); event.initEvent('click', true, true);
a.dispatchEvent(event);
}
else {
a.click();
}
}); });
let save_button_hpgl = document.getElementById('save-hpgl'); let save_button_hpgl = document.getElementById('save-hpgl');

View File

@ -45,18 +45,23 @@
</script> </script>
<script> <script>
let save_button = document.getElementById('save-svg'); let save_button_svg = document.getElementById('save-svg');
save_button_svg.addEventListener('click', function(){
save_button.addEventListener('click', function(){ let url = document.URL,
//get svg element. parts = url.split('/'),
let svg = document.getElementsByTagName("svg")[0]; name = parts[parts.length-1],
svg_url = '/svg/' + name,
//get svg source. a = document.createElement('a');
let serializer = new XMLSerializer(); a.href = svg_url;
let source = serializer.serializeToString(svg); a.setAttribute('download', 'download');
if (document.createEvent) {
let blob = new Blob([source], {type: "text/plain;charset=utf-8"}); const event = document.createEvent('MouseEvents');
saveAs(blob, 'cobbled-paths.svg'); event.initEvent('click', true, true);
a.dispatchEvent(event);
}
else {
a.click();
}
}); });
let save_button_hpgl = document.getElementById('save-hpgl'); let save_button_hpgl = document.getElementById('save-hpgl');