57 lines
1.5 KiB
Bash
Executable file
57 lines
1.5 KiB
Bash
Executable file
#!/bin/zsh
|
|
|
|
zparseopts -D -E -vertical=vertical
|
|
|
|
get-icon-size() {
|
|
xmllint --xpath 'string(/*[local-name()="svg"]/@viewBox)' $1 | cut -d' ' -f3,4
|
|
}
|
|
|
|
index=0
|
|
|
|
scad_args=()
|
|
|
|
if [[ $vertical ]]; then
|
|
scad_args+=(-D "vertical=87.0" -D "horizontal=61.0" -D "tabs=3" -D "tab_angle=30" -D "tab_width=14")
|
|
out_basedir=generated/vertical
|
|
tabs=3
|
|
else
|
|
out_basedir=generated/horizontal
|
|
tabs=4
|
|
fi
|
|
|
|
if [[ -d $1 ]]; then
|
|
files=($1/*.svg)
|
|
else
|
|
files=($@)
|
|
fi
|
|
for icon in $files; do
|
|
target=$out_basedir/${${icon#*/}:r}.3mf
|
|
mkdir -p ${target:h}
|
|
|
|
size=( $(get-icon-size $icon) )
|
|
if (( size[1] < size[2] )); then
|
|
scale_factor=$(( 9.0 / size[2] ))
|
|
echo "Scaling factor: $scale_factor"
|
|
width=$(( size[1] * scale_factor ))
|
|
echo "Width: $width"
|
|
scad_args+=(-D "target_icon_width=${width}" -D "target_icon_height=9")
|
|
echo "\e[1;33mIcon size: ${size[1]} x ${size[2]}; scaled to $width x 9\e[0m"
|
|
else
|
|
scale_factor=$(( 9.0 / size[1] ))
|
|
echo "Scaling factor: $scale_factor"
|
|
height=$(( size[2] * scale_factor ))
|
|
echo "Height: $height"
|
|
scad_args+=(-D "target_icon_width=9" -D "target_icon_height=${height}")
|
|
echo "\e[1;33mIcon size: ${size[1]} x ${size[2]}; scaled to 9 x $height\e[0m"
|
|
fi
|
|
|
|
echo "Generating card $icon with tab index $index"
|
|
scad_out=$(colorscad -o $target -i divider.scad -- -D "index=$index" -D "icon=\"$icon\"" ${scad_args[@]})
|
|
if [[ $? -ne 0 ]]; then
|
|
echo "\e[1;31mError generating $target\e[0m"
|
|
echo "$scad_out"
|
|
continue
|
|
fi
|
|
|
|
(( index = (index + 1) % tabs ))
|
|
done
|