]> de.git.xonotic.org Git - xonotic/mediasource.git/blob - gfx/luma/render-svg.sh
Merge branch 'LegendaryGuard/decompile_weapons' into 'master'
[xonotic/mediasource.git] / gfx / luma / render-svg.sh
1 #!/bin/sh -e
2 # TASK
3 #   Render SVGFILEs from path/filename.svg to DATADIR/path/filename.tga,
4 #   if they are newer than their target tga file.
5 #
6 # NOTES
7 #   To compensate for filter rendering errors and to reduce rbg noise,
8 #   the svg files are rendered at a large size and then scaled down.
9 #
10 # DEPENDENCIES
11 #   rsvg-convert (librsvg 2.39.0)
12 #   convert (imagemagick 6.8.6-9)
13 #
14 # USAGE
15 #   ./render-svg.sh DATADIR [SVGFILE...]
16 #
17 # USAGE EXAMPLES
18 #   Single file: ./render-svg.sh ~/.xonotic/data gfx/menu/luma/cursor.svg
19 #   All files:   ./render-svg.sh ~/.xonotic/data $(find . -name "*.svg")
20
21
22 # Check for arguments
23 if [ -z "$1" ] || [ "${1##*.}" = "svg" ]; then
24         echo "Usage: $0 DATADIR [SVGFILE...]"
25         exit 1
26 fi
27
28
29 data="$1"; shift
30 maxScale=8
31 maxPixels=100000000
32
33
34 for svg in "$@"; do
35         ext="${svg##*.}"
36         dir="$data/${svg%/*}"
37         tga="$data/${svg%.*}.tga"
38
39         # IF source file has extension .svg AND it exists AND
40         # destination file does NOT exist, OR source file is newer than destination file
41         if [ "$ext" = "svg" ] && [ -f "$svg" ] && [ ! -f "$tga" -o "$svg" -nt "$tga" ]; then
42                 echo "Rendering $tga"
43
44                 w=$(identify -format "%w" "$svg")
45                 h=$(identify -format "%h" "$svg")
46                 scale=$(echo "s=sqrt($maxPixels/$w/$h);if(s>$maxScale)s=$maxScale;s" | bc)
47
48                 mkdir -p "$dir"
49                 # -auto-orient works around an inversion regression present in imagemagick 6.9.11-60
50                 rsvg-convert -z "$scale" "$svg" | convert - -auto-orient -scale "$w" "$tga"
51         else
52                 printf "NOT rendering source $svg because "
53                 if [ ! "$ext" = "svg" ]; then
54                         printf "file extension is not \".svg\"\n"
55                 elif [ ! -f "$svg" ]; then
56                         printf "file not found\n"
57                 else
58                         printf "$svg is not newer than $tga\n"
59                 fi
60         fi
61 done