More customization
This commit is contained in:
parent
60444e3584
commit
0761bacc12
2 changed files with 97 additions and 63 deletions
50
generate.zsh
50
generate.zsh
|
@ -1,29 +1,57 @@
|
|||
#!/bin/zsh
|
||||
|
||||
zparseopts -D -E -tabs:=tabs -vertical=vertical
|
||||
zparseopts -D -E -vertical=vertical
|
||||
|
||||
get-icon-size() {
|
||||
xmllint --xpath 'string(/*[local-name()="svg"]/@viewBox)' $1 | cut -d' ' -f3,4
|
||||
}
|
||||
|
||||
tabs=${tabs[2]:-4}
|
||||
index=0
|
||||
|
||||
scad_args=(
|
||||
-D "icon=\"$icon\""
|
||||
-D "index=$index"
|
||||
)
|
||||
scad_args=()
|
||||
|
||||
if [[ $vertical ]]; then
|
||||
scad_args+=(-D "vertical=87.0" -D "horizontal=61.0")
|
||||
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
|
||||
echo "Usage: $0 <path-to-icon-dir> [--tabs <number-of-tabs>]"
|
||||
if [[ -d $1 ]]; then
|
||||
files=($1/*.svg)
|
||||
else
|
||||
files=($@)
|
||||
fi
|
||||
for icon in $1/*.svg; do
|
||||
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"
|
||||
colorscad -o $target -i divider.scad -- ${scad_args[@]}
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue