-
Notifications
You must be signed in to change notification settings - Fork 3
/
export-color-svg.sh
executable file
·42 lines (37 loc) · 1.21 KB
/
export-color-svg.sh
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
41
42
TEMPDIR=$(mktemp -d)
COLOR_ID_TAG=mowmow
INPUT_CSG='a good version of the logo.scad'
PARAMFILE='a good version of the logo.json'
function export_svg() {
COLORS=$(
openscad -p "${PARAMFILE}" -P "${PROFILE}" "$INPUT_CSG" -o "${TEMPDIR}/no_color.svg" -D "module color(c) {echo(mowmow = str(c));}" 2>&1 |
grep -Po '(?<=(mowmow = \"))(#[0-9a-fA-F]{6}|[0-9a-fA-F]{8})' |
sort -u
);
{
cat <<EOF
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="0mm" height="0mm" xmlns="http://www.w3.org/2000/svg" version="1.1">
<title>${PROFILE}</title>
EOF
for color in $COLORS; do
openscad -p "${PARAMFILE}" -P "${PROFILE}" "$INPUT_CSG" --export-format svg -o - -D "module color(c) {if (c == \"${color}\") children();}" 2>/dev/null|
sed "s/stroke=\"black\"//g" |
sed "s/stroke-width=\"0.5\"//g" |
sed "s/lightgray/${color}/g" |
grep -Pzo '<path(\n|\N)*/>' |
# drop the Null
head -c-1
echo
done
cat <<EOF
</svg>
EOF
} > ${PROFILE}.svg
inkscape ${PROFILE}.svg --actions='select-all;page-fit-to-selection' -o ${PROFILE}.svg
}
for profile in nix nix-grid nix-gapless; do
export PROFILE=$profile
export_svg
done