f40ec2da6605a445957125c161361a4a5fdde3c9
[navit-package] / navit / xpm / navit_svg2png
1 #!/bin/bash
2
3 function 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 test "$OSTYPE" != "cygwin" -a "$OSTYPE" != "msys"; then
22         ulimit -t 5
23 fi
24
25 svgtopng=$1
26 png=$2
27 if [[ "$png" = *_[1-9]*_[1-9]*.png ]];
28 then
29         svg=${png%_*_*.png};
30         h=${png##*_}
31         w=${png%_$h}
32         h=${h%.png}
33         w=${w##*_}
34 else
35         svg=${png%.png}
36 fi
37 if [ ! -f $svg.svg -a ! -f $svg.svgz ]
38 then
39         svg="$SRCDIR/$svg"
40 fi
41 if [ -f $png -a ! -f $svg.svg ]; then
42         # width and height seems to be defined as part of the file name
43         touch $png
44 else
45         # use width and hight from the svg image
46         if [ -f $svg.svg ]
47         then
48                 if [ -z "$w" ]
49                 then
50                         w=$(grep 'width="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*width="//' -e 's/[pxt]*".*//')
51                 fi
52                 if [ -z "$h" ]
53                 then
54                         h=$(grep 'height="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*height="//' -e 's/[pxt]*".*//')
55                 fi
56                 svgtopng $w $h $svg.svg $png
57         elif [ -f $svg.svgz ]
58         then
59                 gzip -dc <$svg.svgz >$svg.svg
60                 if [ -z "$w" ]
61                 then
62                         w=$(grep 'width="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*width="//' -e 's/[pxt]*".*//')
63                 fi
64                 if [ -z "$h" ]
65                 then
66                         h=$(grep 'height="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*height="//' -e 's/[pxt]*".*//')
67                 fi
68                 svgtopng $w $h $svg.svg $png
69                 rm -f $svg.svg
70         fi
71 fi
72 exit 0