More licenses converted to SPDX.
[metze/wireshark/wip.git] / image / stock_icons / svg-to-png.sh
1 #!/bin/bash
2 # svg-to-png
3 # Convert SVG files to 1x and 2x PNGs. Dump a list of Qt resource
4 # file entries upon successful completion.
5 #
6 # Copyright 2014 Gerald Combs <gerald [AT] wireshark.org>
7 #
8 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 1998 Gerald Combs
11 #
12 # SPDX-License-Identifier: GPL-2.0-or-later
13
14 COMMON_ARGS="--export-area-page"
15
16 set_source_svgs() {
17     local out_icon=$1
18     case $out_icon in
19     x-capture-options)
20         out_icon=x-capture-options-gear
21         ;;
22     x-capture-restart)
23         out_icon=x-capture-restart-fin
24         ;;
25     x-capture-stop)
26         out_icon=x-capture-stop-red
27         ;;
28     esac
29     ONE_X_SVG=${out_icon}.svg
30     TWO_X_SVG=${out_icon}@2x.svg
31     if [ ! -f ${TWO_X_SVG} ] ; then
32         TWO_X_SVG=$ONE_X_SVG
33     fi
34 }
35
36 ICONS="
37     edit-find
38     go-first
39     go-jump
40     go-last
41     go-next
42     go-previous
43     x-capture-file-close
44     x-capture-file-save
45     x-capture-file-reload
46     x-capture-filter-bookmark
47     x-capture-filter-bookmark.active
48     x-capture-filter-bookmark.selected
49     x-capture-options
50     x-capture-restart
51     x-capture-start.on
52     x-capture-start
53     x-capture-stop
54     x-colorize-packets
55     x-display-filter-bookmark
56     x-display-filter-bookmark.active
57     x-display-filter-bookmark.selected
58     x-filter-apply
59     x-filter-apply.active
60     x-filter-apply.selected
61     x-filter-clear
62     x-filter-clear.active
63     x-filter-clear.selected
64     x-filter-dropdown
65     x-filter-matching-bookmark
66     x-filter-matching-bookmark.active
67     x-filter-matching-bookmark.selected
68     x-resize-columns
69     x-stay-last
70     zoom-in
71     zoom-original
72     zoom-out
73     "
74
75 QRC_FILES=""
76
77 # 12x12
78 for SIZE in 14x14 16x16 24x14 24x14 ; do
79     WIDTH=${SIZE/x*/}
80     HEIGHT=${SIZE/*x/}
81     SIZE_DIR=${SIZE}
82
83     TWO_X_WIDTH=`expr $WIDTH \* 2`
84     TWO_X_HEIGHT=`expr $HEIGHT \* 2`
85     ONE_X_ARGS="--export-width=${WIDTH} --export-height=${HEIGHT}"
86     TWO_X_ARGS="--export-width=${TWO_X_WIDTH} --export-height=${TWO_X_HEIGHT}"
87
88     echo "Converting $SIZE_DIR"
89     cd $SIZE_DIR || exit 1
90
91     for ICON in $ICONS ; do
92         set_source_svgs $ICON
93
94         if [ ! -f ${ONE_X_SVG} ] ; then
95             >&2 echo "Skipping ${ONE_X_SVG}"
96             continue
97         fi
98
99         ONE_X_PNG=${ICON}.png
100         TWO_X_PNG=${ICON}@2x.png
101
102         if [ $ONE_X_SVG -nt $ONE_X_PNG ] ; then
103             inkscape $COMMON_ARGS $ONE_X_ARGS \
104                 --file="$PWD/$ONE_X_SVG" --export-png="$PWD/$ONE_X_PNG" || exit 1
105         fi
106
107         if [ $TWO_X_SVG -nt $TWO_X_PNG ] ; then
108             inkscape $COMMON_ARGS $TWO_X_ARGS \
109                 --file="$PWD/$TWO_X_SVG" --export-png="$PWD/$TWO_X_PNG" || exit 1
110         fi
111
112         QRC_FILES="${QRC_FILES} ${SIZE_DIR}/${ONE_X_PNG} ${SIZE_DIR}/${TWO_X_PNG}"
113     done
114
115     cd ..
116
117 done
118
119 for QRC_FILE in $QRC_FILES ; do
120     echo "        <file>toolbar/${QRC_FILE}</file>"
121 done
122
123 #
124 # Editor modelines  -  https://www.wireshark.org/tools/modelines.html
125 #
126 # Local variables:
127 # c-basic-offset: 4
128 # tab-width: 8
129 # indent-tabs-mode: nil
130 # End:
131 #
132 # vi: set shiftwidth=4 tabstop=8 expandtab:
133 # :indentSize=4:tabSize=8:noTabs=true:
134 #