forked from brianlow/plotter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean.sh
More file actions
executable file
·40 lines (31 loc) · 1.33 KB
/
clean.sh
File metadata and controls
executable file
·40 lines (31 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# can be used to clean up a svg
# need to play around with parameters yourself though
# https://vpype.readthedocs.io/en/latest/reference.html
INPUT=$1
OUTPUT=${INPUT%.svg}-cleaned.svg
FILTERED=$(mktemp --suffix=.svg)
echo $INPUT -> $OUTPUT
# Pre-filter: remove inactive segments (elements without class "rune-segment--active")
# so vpype doesn't process intentionally hidden lines.
python3 - "$INPUT" "$FILTERED" <<'EOF'
import sys, xml.etree.ElementTree as ET
ET.register_namespace('', 'http://www.w3.org/2000/svg')
ET.register_namespace('xlink', 'http://www.w3.org/1999/xlink')
tree = ET.parse(sys.argv[1])
root = tree.getroot()
def remove_inactive(parent):
for el in list(parent):
cls = el.get('class', '')
# Remove segments that exist but are not active
if 'rune-segment' in cls and 'rune-segment--active' not in cls:
parent.remove(el)
else:
remove_inactive(el)
remove_inactive(root)
tree.write(sys.argv[2], xml_declaration=True, encoding='unicode')
EOF
#vpype read "$INPUT" linemerge --tolerance 0.01mm linemerge --tolerance 0.05mm linemerge --tolerance 0.1mm linesimplify linesimplify --tolerance 0.1mm linesort write ${OUTPUT}
vpype read "$FILTERED" snap 0.1mm linemerge --tolerance 0.1mm linesort write ${OUTPUT}
#vpype read "$INPUT" snap 0.5mm write ${OUTPUT}
rm "$FILTERED"