qubes-rpc: fix SVG icon scaling

rsvg-convert doesn't scale the image. Do it with convert, only when
really needed. Don't upscale the icon after converting to raster
version.

Fixes QubesOS/qubes-issues#1884
This commit is contained in:
Marek Marczykowski-Górecki 2016-03-29 16:38:04 +02:00
parent 1c251487fa
commit 7b5f2b77d1
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -5,7 +5,7 @@ ICON_MAXSIZE=512
if [ "${filename%%:*}" = xdgicon ]; then if [ "${filename%%:*}" = xdgicon ]; then
filename="$(/usr/lib/qubes/xdg-icon "${filename#*:}" "$ICON_MAXSIZE")" filename="$(/usr/lib/qubes/xdg-icon "${filename#*:}" "$ICON_MAXSIZE")"
forcesize="$ICON_MAXSIZE" forcemaxsize="$ICON_MAXSIZE"
[ -n "${filename}" ] [ -n "${filename}" ]
elif [ "${filename}" = "-" ] || [ "${filename##*:}" = "-" ]; then elif [ "${filename}" = "-" ] || [ "${filename##*:}" = "-" ]; then
@ -25,12 +25,17 @@ w="$(echo "$s"|cut -d " " -f 1)"
h="$(echo "$s"|cut -d " " -f 2)" h="$(echo "$s"|cut -d " " -f 2)"
m="$(echo "$s"|cut -d " " -f 3)" m="$(echo "$s"|cut -d " " -f 3)"
if [ "$m" = SVG ]; then if [ "$m" = SVG ]; then
if [ -n "$forcesize" ]; then
w="$forcesize"
h="$forcesize"
fi
tmpfile2="$(mktemp /tmp/qimg-XXXXXXXX.png)" tmpfile2="$(mktemp /tmp/qimg-XXXXXXXX.png)"
rsvg-convert -w "$w" -h "$h" -o "$tmpfile2" "$filename" rsvg-convert -o "$tmpfile2" "$filename"
# downscale the image if necessary
if [ -n "$forcemaxsize" -a \
\( "$w" -gt "$forcemaxsize" -o "$h" -gt "$forcemaxsize" \) ]; then
convert "$tmpfile2" -scale "${forcemaxsize}x${forcemaxsize}" "$tmpfile2"
# read the size again, because icon may not be a square
s="$(identify -format '%w %h' "$tmpfile2")"
w="$(echo "$s"|cut -d " " -f 1)"
h="$(echo "$s"|cut -d " " -f 2)"
fi
filename="$tmpfile2" filename="$tmpfile2"
fi fi
echo "$w $h" echo "$w $h"