Patch:xpm:Fix bashism downloaded from http://navit.latouche.info/tmp/navit_svg2png...
[navit-package] / navit / xpm / navit_svg2png
1 #!/bin/sh
2
3 svgtopng()
4 {
5         case $svgtopng in
6         *ksvgtopng|*ksvgtopng4)
7                 $svgtopng $*
8                 ;;
9         *rsvg-convert)
10                 $svgtopng --width=$1 --height=$2 --output $4 $3
11                 ;;
12         *inkscape)
13                 $svgtopng --without-gui --export-width=$1 --export-height=$2 --export-png=$BUILDDIR/$4 $3
14                 ;;
15         *convert)
16                 $svgtopng $3 -resize $1x$2 $4
17                 ;;
18         esac
19 }
20
21 if [ "$OSTYPE" != "cygwin" -a "$OSTYPE" != "msys" ]; then
22         ulimit -t 5
23 fi
24
25 svgtopng=$1
26 png=$2
27 case "$png" in
28         *_[1-9]*_[1-9]*.png)
29                 svg=${png%_*_*.png};
30                 h=${png##*_}
31                 w=${png%_$h}
32                 h=${h%.png}
33                 w=${w##*_}
34                 ;;
35         *)
36                 svg=${png%.png}
37                 ;;
38 esac
39 if [ ! -f $svg.svg -a ! -f $svg.svgz ]
40 then
41         svg="$SRCDIR/$svg"
42 fi
43 if [ -f $png -a ! -f $svg.svg ]; then
44         # width and height seems to be defined as part of the file name
45         touch $png
46 else
47         # use width and height from the svg image
48         if [ -f $svg.svg ]
49         then
50                 if [ -z "$w" ]
51                 then
52                         w=$(grep 'width="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*width="//' -e 's/[pxt]*".*//')
53                 fi
54                 if [ -z "$h" ]
55                 then
56                         h=$(grep 'height="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*height="//' -e 's/[pxt]*".*//')
57                 fi
58                 svgtopng $w $h $svg.svg $png
59         elif [ -f $svg.svgz ]
60         then
61                 gzip -dc <$svg.svgz >$svg.svg
62                 if [ -z "$w" ]
63                 then
64                         w=$(grep 'width="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*width="//' -e 's/[pxt]*".*//')
65                 fi
66                 if [ -z "$h" ]
67                 then
68                         h=$(grep 'height="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*height="//' -e 's/[pxt]*".*//')
69                 fi
70                 svgtopng $w $h $svg.svg $png
71                 rm -f $svg.svg
72         fi
73 fi
74 exit 0