mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 15:03:28 +00:00
desktopToDarwinBundle: Fall back to scaling available
Sometimes scalable icons or icons within the thresholds from the desired resolutions aren't available. In this case it's still nicer to end up with a blocky scaled icon rather than the generic default.
This commit is contained in:
parent
08a2b83c96
commit
6aa5c53748
@ -50,8 +50,10 @@ convertIconTheme() {
|
||||
else
|
||||
echo "threshold $icon"
|
||||
fi
|
||||
return 0
|
||||
elif [[ -a $icon ]]; then
|
||||
echo "fallback $icon"
|
||||
fi
|
||||
return 0
|
||||
done
|
||||
done
|
||||
echo "scalable"
|
||||
@ -101,6 +103,17 @@ convertIconTheme() {
|
||||
scalableIcon=('-')
|
||||
fi
|
||||
|
||||
# Tri-state variable, NONE means no icons have been found, an empty
|
||||
# icns file will be generated, not sure that's necessary because macOS
|
||||
# will default to a generic icon if no icon can be found.
|
||||
#
|
||||
# OTHER means an appropriate icon was found.
|
||||
#
|
||||
# Any other value is a path to an icon file that isn't scalable or
|
||||
# within the threshold. This is used as a fallback in case no better
|
||||
# icon can be found and will be scaled as much as
|
||||
# necessary to result in appropriate icon sizes.
|
||||
local foundIcon=NONE
|
||||
for iconSize in "${iconSizes[@]}"; do
|
||||
for scale in "${!scales[@]}"; do
|
||||
local iconResult=$(findIcon $iconSize $scale)
|
||||
@ -112,6 +125,7 @@ convertIconTheme() {
|
||||
fixed)
|
||||
local density=$((72 * scale))x$((72 * scale))
|
||||
magick convert -density "$density" -units PixelsPerInch "$icon" "$result"
|
||||
foundIcon=OTHER
|
||||
;;
|
||||
threshold)
|
||||
# Synthesize an icon of the exact size if a scalable icon is available
|
||||
@ -119,15 +133,32 @@ convertIconTheme() {
|
||||
if ! synthesizeIcon "${scalableIcon[0]}" "$result" "$iconSize" "$scale"; then
|
||||
resizeIcon "$icon" "$result" "$iconSize" "$scale"
|
||||
fi
|
||||
foundIcon=OTHER
|
||||
;;
|
||||
scalable)
|
||||
synthesizeIcon "${scalableIcon[0]}" "$result" "$iconSize" "$scale" || true
|
||||
foundIcon=OTHER
|
||||
;;
|
||||
fallback)
|
||||
# Use the largest size available to scale to
|
||||
# appropriate sizes.
|
||||
if [[ $foundIcon != OTHER ]]; then
|
||||
foundIcon=$icon
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
if [[ $foundIcon != NONE && $foundIcon != OTHER ]]; then
|
||||
# Ideally we'd only resize to whatever the closest sizes are,
|
||||
# starting from whatever icon sizes are available.
|
||||
for iconSize in 16 32 128 256 512; do
|
||||
local result=${resultdir}/${iconSize}x${iconSize}.png
|
||||
resizeIcon "$foundIcon" "$result" "$iconSize" 1
|
||||
done
|
||||
fi
|
||||
echo "$resultdir"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user