-
Notifications
You must be signed in to change notification settings - Fork 242
/
render-assets.sh
executable file
·158 lines (134 loc) · 4.07 KB
/
render-assets.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#! /usr/bin/env bash
set -ueo pipefail
set -o physical
INKSCAPE="/usr/bin/inkscape"
OPTIPNG="/usr/bin/optipng"
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ASRC_DIR="${REPO_DIR}/src/assets"
# import environment variables with care
empty_if_unset() {
for name in "$@"; do
eval "if ! [ -v $name ]; then
export $name=
fi"
done
}
# check command avalibility
has_command() {
command -v "${1}" > /dev/null 2>&1
}
missing=
for cmd in inkscape optipng; do
if ! has_command $cmd; then
missing="${missing} $cmd"
fi
done
if [ "${missing}" ]; then
echo "Missing required dependencies: ${missing}"
if has_command zypper; then
sudo zypper in inkscape optipng
elif has_command apt; then
sudo apt install inkscape optipng
elif has_command dnf; then
sudo dnf install -y inkscape optipng
elif has_command dnf; then
sudo dnf install inkscape optipng
elif has_command pacman; then
sudo pacman -S --noconfirm inkscape optipng
elif had_command brew; then
brew install --cask inkscape
brew install optipng
else
exit 1
fi
fi
render_thumbnail() {
local dest="$1"
local color="$2"
local in="$ASRC_DIR/${dest}/thumbnail.svg"
local out="$ASRC_DIR/${dest}/thumbnail${color}.png"
if [ $(jobs -p | wc -l) -ge ${BUILD_THREADS} ]; then wait; fi
echo "Rendering $out"
rm -rf "$out"
"$INKSCAPE" --export-id="thumbnail${color@L}" \
--export-id-only \
--export-filename="$out" "$in" >/dev/null 2>&1 &&
"$OPTIPNG" -o7 --quiet "$out" &
}
# Configuration loading
# Prefer existing values if defined (not empty)
empty_if_unset BUILD_THREADS MAX_SCALE_FACTOR XFWM4_SCALE_FACTOR
eval $( awk -F= '
BEGIN { stage=0; arr[0]=0; delete arr[0] }
stage == 0 {
if ($2 != "")
arr[ $1]=$2
}
stage == 1 {
name = substr( $1, length( "export ") + 1)
print $1 "=" (arr[ name] != "" ? "\"" arr[ name] "\"" : $2);
}
ENDFILE { stage=1 }
' - config.sh <<- eof
BUILD_THREADS=$BUILD_THREADS
MAX_SCALE_FACTOR=$MAX_SCALE_FACTOR
XFWM4_SCALE_FACTOR=$XFWM4_SCALE_FACTOR
eof
)
export BUILD_THREADS=$(( BUILD_THREADS >= 1 ? BUILD_THREADS : 1 ))
export MAX_SCALE_FACTOR=$(( MAX_SCALE_FACTOR > 2 ? MAX_SCALE_FACTOR : 2 ))
export XFWM4_SCALE_FACTOR=$(( XFWM4_SCALE_FACTOR >= 1 ? XFWM4_SCALE_FACTOR : 1 ))
echo "Assets configuration environment variables:"
echo
echo "BUILD_THREADS = ${BUILD_THREADS}"
echo "MAX_SCALE_FACTOR = '${MAX_SCALE_FACTOR}'"
echo "XFWM4_SCALE_FACTOR = ${XFWM4_SCALE_FACTOR}"
echo
echo 'Waiting 3 seconds...' && sleep 3
cat > config.sh <<- eof
export BUILD_THREADS="${BUILD_THREADS}"
export MAX_SCALE_FACTOR="${MAX_SCALE_FACTOR}"
export XFWM4_SCALE_FACTOR="${XFWM4_SCALE_FACTOR}"
eof
# Can't skip lower factors if MAX_SCALE_FACTOR > 2
# -gtk-scaled seems to get it from positional information instead of image size.
export SCALE_FACTORS=$( seq -s' ' 2 $MAX_SCALE_FACTOR )
echo
for color in '-Light' '-Dark' ; do
render_thumbnail "${dest:-metacity-1}" "${color}"
done
echo
echo "Rendering cinnamon thumbnails"
cd "$ASRC_DIR/cinnamon/thumbnails" && ./render-thumbnails.sh
echo
echo "Rendering gtk thumbnails"
cd "$ASRC_DIR/gtk/thumbnails" && ./render-thumbnails.sh
echo
echo Rendering gtk-2.0 assets
cd "$ASRC_DIR/gtk-2.0" && ./render-assets.sh
echo
echo Rendering gtk-3.0 / gtk-4.0 assets
cd "$ASRC_DIR/gtk/common-assets" && ./render-assets.sh
cd "$ASRC_DIR/gtk/windows-assets" && ./render-assets.sh && ./render-alt-assets.sh
echo
echo Rendering metacity-1 assets
cd "$ASRC_DIR/metacity-1" && ./render-assets.sh
echo
echo Rendering unity assets
cd "$ASRC_DIR/unity" && ./render-assets.sh
echo
echo Rendering xfwm4 assets
cd "$ASRC_DIR/xfwm4" && ./render-assets.sh && ./render-small-assets.sh
cd "${REPO_DIR}/src/main/xfwm4" && {
for suf in 'Light' 'Dark'; do
[ -f themerc-${suf}.orig ] || cp themerc-${suf}{,.orig}
awk -F= -vscale=${XFWM4_SCALE_FACTOR} '
/^(button_(offset|spacing)|title_horizontal_offset|shadow_(delta_(height|width|x|y)|opacity))/ {
print $1 "=" $2 * scale
next }
{ print }
' themerc-${suf}.orig > themerc-${suf}
done
}
wait
exit 0