2022-09-19 11:43:54 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-11-26 19:49:56 +02:00
|
|
|
# Nerd Fonts Version: 3.1.1
|
2023-06-01 11:19:28 +02:00
|
|
|
# Script Version: 1.0.1
|
2022-09-19 11:43:54 +02:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Do not optimize files that are smaller than
|
|
|
|
size_limit=0
|
|
|
|
|
|
|
|
# Do not optimize files, where the new size is more than X% of current size
|
|
|
|
size_ratio_max=80
|
|
|
|
|
|
|
|
function get_size {
|
|
|
|
du -b "$1" | sed 's/\([0-9]\)[^0-9].*$/\1/'
|
|
|
|
}
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Checking for SVG simplifications"
|
|
|
|
|
2023-06-01 11:19:28 +02:00
|
|
|
if [ "$1" != "doit" ]; then
|
|
|
|
dry="dry"
|
|
|
|
else
|
|
|
|
dry=""
|
|
|
|
fi
|
|
|
|
|
2022-09-19 11:43:54 +02:00
|
|
|
if [ -n "${dry}" ]; then
|
|
|
|
echo " This is a dry run: no actual modifications are performed"
|
|
|
|
echo " Specify 'doit' as parameter to actually optimize the svgs"
|
|
|
|
else
|
|
|
|
echo " Files might be MODIFIED by this run ('doit' specified)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
svg_dir="../../src/svgs"
|
|
|
|
|
|
|
|
symbols=()
|
|
|
|
while IFS= read -d $'\0' -r file ; do
|
|
|
|
symbols=("${symbols[@]}" "$file")
|
|
|
|
done < <(find "${svg_dir}" -name "*.svg" -print0)
|
|
|
|
echo "Found ${#symbols[@]} svgs in ${svg_dir}"
|
|
|
|
|
|
|
|
count=0
|
|
|
|
for s in "${symbols[@]}"; do
|
|
|
|
inkscape "$s" "--actions=select-all;object-simplify-path;export-filename:temp.svg;export-do;quit-inkscape" 2>/dev/null
|
|
|
|
old_size=$(get_size "$s")
|
|
|
|
new_size=$(get_size "temp.svg")
|
|
|
|
if [ "${old_size}" -lt "${size_limit}" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2023-06-01 11:19:28 +02:00
|
|
|
ratio=$(dc -e "${new_size} 100 * ${old_size} / p")
|
2022-09-19 11:43:54 +02:00
|
|
|
if [ "${ratio}" -lt "${size_ratio_max}" ]; then
|
2023-06-01 11:19:28 +02:00
|
|
|
echo "Simplification for $(basename "${s}") (${old_size} -> ${new_size}) ${ratio}%"
|
|
|
|
count=$(dc -e "${count} 1 + p")
|
2022-09-19 11:43:54 +02:00
|
|
|
if [ -z "${dry}" ]; then
|
|
|
|
mv temp.svg "${s}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "Found ${count} svgs to simplify"
|
|
|
|
rm temp.svg
|