2017-08-27 15:03:22 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Try to find Inkscape or ImageMagick's convert
|
2017-09-02 13:32:14 +02:00
|
|
|
find_converter() {
|
2017-08-27 15:03:22 +02:00
|
|
|
if [ -z "$INKSCAPE" ]
|
|
|
|
then
|
|
|
|
INKSCAPE=$(which inkscape) ||
|
2020-03-31 20:10:52 +02:00
|
|
|
INKSCAPE='/Applications/Inkscape.app/Contents/MacOS/Inkscape'
|
2017-08-27 15:03:22 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -x "$INKSCAPE" ]
|
|
|
|
then
|
2017-09-02 13:32:14 +02:00
|
|
|
converter() {
|
2017-08-27 15:03:22 +02:00
|
|
|
"$INKSCAPE" \
|
|
|
|
"$PWD/$1" \
|
2020-03-31 20:10:52 +02:00
|
|
|
-o "$PWD/$2" \
|
2017-08-27 15:03:22 +02:00
|
|
|
-w "$3" \
|
2017-09-02 13:32:14 +02:00
|
|
|
-h "$4"
|
2017-08-27 15:03:22 +02:00
|
|
|
}
|
|
|
|
elif which convert &>/dev/null
|
|
|
|
then
|
2017-09-02 13:32:14 +02:00
|
|
|
converter() {
|
2017-08-27 15:03:22 +02:00
|
|
|
convert \
|
|
|
|
-background none \
|
|
|
|
"$1" \
|
2017-09-02 13:32:14 +02:00
|
|
|
-thumbnail "${3}x${4}" \
|
2017-08-27 15:03:22 +02:00
|
|
|
-strip \
|
|
|
|
"$2"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-09-02 13:32:14 +02:00
|
|
|
# Scale a length and cut off fraction
|
2017-08-27 15:03:22 +02:00
|
|
|
#
|
2017-09-02 13:32:14 +02:00
|
|
|
# @param 1 - length
|
|
|
|
# @param 2 - multiplier
|
|
|
|
scale() {
|
|
|
|
echo "$1*$2" | bc -l | cut -d '.' -f 1
|
|
|
|
}
|
2017-08-27 15:03:22 +02:00
|
|
|
|
2017-09-02 13:32:14 +02:00
|
|
|
# Make sure $DIR exists
|
|
|
|
check_dir() {
|
|
|
|
[ -d "$DIR" ] || mkdir -p "$DIR" || {
|
|
|
|
echo "error: couldn't create $DIR" >&2
|
|
|
|
return $?
|
2017-08-27 15:03:22 +02:00
|
|
|
}
|
2017-09-02 13:32:14 +02:00
|
|
|
}
|
2017-08-27 15:03:22 +02:00
|
|
|
|
2017-09-02 13:32:14 +02:00
|
|
|
# Returns true if source is older than target file
|
|
|
|
#
|
|
|
|
# @param 1 - target file
|
|
|
|
# @param 2 - source file
|
|
|
|
newer_than() {
|
|
|
|
[ -r "$1" ] && [ -z "$(find "$2" -type f -newer "$1")" ]
|
|
|
|
}
|
2017-08-27 15:03:22 +02:00
|
|
|
|
2017-09-02 13:32:14 +02:00
|
|
|
# Convert SVG files in multiple resolutions to PNG
|
|
|
|
#
|
|
|
|
# @param 1 - output path
|
|
|
|
update() {
|
|
|
|
local SVG SIZE NEGATE
|
2017-08-27 15:03:22 +02:00
|
|
|
while read -r SVG SIZE NEGATE
|
|
|
|
do
|
|
|
|
SIZE=${SIZE:-24}
|
|
|
|
|
2017-09-02 13:32:14 +02:00
|
|
|
local DPI MULTIPLIER DIR PNG
|
2017-08-27 15:03:22 +02:00
|
|
|
while read -r DPI MULTIPLIER
|
|
|
|
do
|
|
|
|
DIR="$1-$DPI"
|
2017-09-02 13:32:14 +02:00
|
|
|
check_dir || return $?
|
2017-08-27 15:03:22 +02:00
|
|
|
|
|
|
|
PNG=${SVG##*/}
|
|
|
|
PNG="$DIR/${PNG%.*}.png"
|
|
|
|
|
2017-09-02 13:32:14 +02:00
|
|
|
newer_than "$PNG" "$SVG" && continue
|
2017-08-27 15:03:22 +02:00
|
|
|
|
|
|
|
converter \
|
|
|
|
"$SVG" \
|
|
|
|
"$PNG" \
|
2017-09-02 13:32:14 +02:00
|
|
|
"$(scale "${SIZE%%x*}" "$MULTIPLIER")" \
|
|
|
|
"$(scale "${SIZE##*x}" "$MULTIPLIER")"
|
2017-08-27 15:03:22 +02:00
|
|
|
|
|
|
|
if (( NEGATE ))
|
|
|
|
then
|
|
|
|
convert "$PNG" -negate "$PNG"
|
|
|
|
fi
|
|
|
|
done <<EOF
|
|
|
|
xxxhdpi 4
|
|
|
|
xxhdpi 3
|
|
|
|
xhdpi 2
|
|
|
|
hdpi 1.5
|
|
|
|
mdpi 1
|
|
|
|
ldpi .75
|
|
|
|
EOF
|
2017-09-02 13:32:14 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
type converter &>/dev/null || find_converter || {
|
|
|
|
echo "error: no Inkscape and no ImageMagick convert" >&2
|
|
|
|
exit 1
|
2017-08-27 15:03:22 +02:00
|
|
|
}
|
|
|
|
|
2017-08-27 18:47:41 +02:00
|
|
|
update app/src/debug/res/mipmap << EOF
|
|
|
|
svg/debug/ic_launcher.svg 48
|
|
|
|
EOF
|
|
|
|
|
2017-08-27 15:03:22 +02:00
|
|
|
update app/src/main/res/mipmap << EOF
|
|
|
|
svg/ic_launcher.svg 48
|
|
|
|
EOF
|
2017-10-26 21:50:11 +02:00
|
|
|
|
|
|
|
update app/src/main/res/drawable << EOF
|
2020-04-13 17:48:30 +02:00
|
|
|
svg/ic_shortcut_decode.svg 48
|
|
|
|
svg/ic_shortcut_encode.svg 48
|
|
|
|
svg/ic_shortcut_preferences.svg 48
|
2018-04-30 11:01:54 +02:00
|
|
|
svg/logo.svg 80
|
2020-04-13 17:48:30 +02:00
|
|
|
svg/wallpaper.svg 384
|
2017-10-26 21:50:11 +02:00
|
|
|
EOF
|