#!/bin/sh

SVGTOOLICONS=/usr/share/xpaint/bitmaps/toolicons/svg
TOOLICONS=$HOME/.xpaint/toolicons
HEIGHT=$1

if test "$1" = remove
then
    rm -f $TOOLICONS/*.xpm.gz
    echo "Xpaint tool icons removed"
    exit 0
fi

if test "$2" != ""
then
    TOOLICONS=$2
fi

if test "$HEIGHT" = ""
then
    echo "Usage: xpaint_generate_toolicons <HEIGHT> [<DIR>]"
    echo "(Inkscape 1.* must be installed for this purpose)"
    exit 0
fi

INKSCAPE=`inkscape --version 2>\dev\null | grep Inkscape | cut -d"." -f 1`
INKSCAPE=`echo $INKSCAPE`

if test "$INKSCAPE" != "Inkscape 1"
then
    echo "Inkscape 1.* must be installed"
    exit 0
fi

mkdir -p $TOOLICONS
cd $TOOLICONS

LIST=`ls $SVGTOOLICONS/*.svg`

echo "Generating icons as xpm files of height $HEIGHT in $TOOLICONS"

for i in $LIST
do
ii=`basename $i`
j=${ii%.*}
k=${j}Op_xpm
inkscape "$i" --export-height=$HEIGHT --export-type=png \
         --export-background=#dcdada --export-background-opacity=255 \
	 --export-filename "$ii" 2>/dev/null
mv $j.png $k.png
convert $k.png $k.xpm
rm -f $k.png
mv $k.xpm ${j}Op.xpm
gzip -f ${j}Op.xpm
echo "$ii -> ${j}Op.xpm.gz"
done
