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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
#!/bin/bash -eu
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Generate a new DEFAULT.yaml file using hwid_unknown.png as a placeholder.
#
yaml_file="DEFAULT.yaml"
# I'm sorting the locales in more-or-less geographical order. Right should move
# east, left should move west. Of course we'll start in the US. :-)
locales="en es_419 pt_BR en_GB fr es pt_PT ca it de el nl da no sv fi et lv lt ru pl cs sk hu sl sr hr bg ro uk tr iw ar fa hi th vi id fil zh_CN zh_TW ko ja"
localedir="./localized_images"
# Arbitrary padding
ypad=5
xpad=10
yborder=40
# Stuff to center and position bitmaps from the bottom of the screen upwards.
# Globals
cur_x=0
cur_y=0
# Return width of the specified .png file
get_x() {
file $1 | awk '{print $4}' | sed -e 's/[^0-9]//g'
}
get_xx() {
local ffile=$(eval "echo \$$1")
get_x $ffile
}
# Return height of the specified .png file
get_y() {
file $1 | awk '{print $6}' | sed -e 's/[^0-9]//g'
}
# Return height of the specified .png file
get_yy() {
local ffile=$(eval "echo \$$1")
get_y $ffile
}
# Guess the locale based on the filename, set a global "newlocales" list
# accordingly.
guess_locale() {
local lc
local islc
local matches
islc=
matches=0
for lc in $locales; do
case "$1" in
*[_-]${lc}_* )
matches=$(expr $matches + 1)
islc=$lc
;;
esac
done
if (( $matches != 1 )); then
islc='en'
fi
local newlist
newlist="$islc"
for lc in $locales; do
if [ "$lc" != "$islc" ]; then
newlist="$newlist $lc"
fi
done
newlocales=$newlist
}
# Reset the current baseline and width to the size of the specified .png file
reset_base() {
cur_x=$(get_x "$1")
cur_y=$(expr $(get_y $1) - $yborder)
}
# Emit a screen line entry centering the given .png files at the current
# baseline. We assume that all args are the same height.
center_up() {
local totalx
local totaly
local x
local ffile
totaly=$(get_yy "$1")
cur_y=$(expr $cur_y - $totaly - $ypad)
totalx=$(expr 0 - $xpad / 2)
for fname in "$@"; do
totalx=$(expr $totalx + $(get_xx $fname) + $xpad)
done
x=$(expr "(" $cur_x - $totalx ")" / 2)
for fname in $*; do
echo " - [$x, $cur_y, $fname]" >> "$yaml_file"
x=$(expr $x + $(get_xx $fname) + $xpad)
done
}
# Generate a new yaml file for each specified hwid_*.png file.
for hwid_bmp in hwid_unknown.png; do
echo "$yaml_file"
# List the images. The major difference is the HWID.
cat >"$yaml_file" <<EOF1
bmpblock: 1.1
compression: 1
images:
# The HWID must change for every BOM
# hwid: $hwid_bmp
# This URL never changes
url: URL.png
# The background images are from the UI people
devmode_bg: Devmode.png
remove_bg: Remove.png
yuck_bg: Yuck.png
insert_bg: Insert.png
# The following strings must be approved by the localization people
EOF1
# some global variables matching the yaml definitions
hwid=$hwid_bmp
url="URL.png"
# Enumerate the bitmaps for each locale-specific string.
for lc in $locales; do
cat >>"$yaml_file" <<EOF2
${lc}_model_text: ${localedir}/$lc/model.png
${lc}_devmode_text: ${localedir}/$lc/devmode.png
${lc}_remove_text: ${localedir}/$lc/remove.png
${lc}_yuck_text: ${localedir}/$lc/yuck.png
${lc}_insert_text: ${localedir}/$lc/insert.png
EOF2
# Also define global variables matching those in the yaml file.
eval "${lc}_model_text=${localedir}/$lc/model.png"
eval "${lc}_devmode_text=${localedir}/$lc/devmode.png"
eval "${lc}_remove_text=${localedir}/$lc/remove.png"
eval "${lc}_yuck_text=${localedir}/$lc/yuck.png"
eval "${lc}_insert_text=${localedir}/$lc/insert.png"
done
# List the screens. We need to composite four screens for each locale.
echo "screens:" >> "$yaml_file"
for lc in $locales; do
echo -n " $lc"
echo " ${lc}_devel:" >> "$yaml_file"
echo " - [ 0, 0, devmode_bg]" >> "$yaml_file"
reset_base Devmode.png
center_up "${lc}_devmode_text"
echo "" >> "$yaml_file"
echo " ${lc}_remove:" >> "$yaml_file"
echo " - [ 0, 0, remove_bg]" >> "$yaml_file"
reset_base Remove.png
center_up "${lc}_model_text" 'hwid'
center_up "url"
center_up "${lc}_remove_text"
echo "" >> "$yaml_file"
echo " ${lc}_yuck:" >> "$yaml_file"
echo " - [ 0, 0, yuck_bg]" >> "$yaml_file"
reset_base Yuck.png
center_up "${lc}_model_text" 'hwid'
center_up "url"
center_up "${lc}_yuck_text"
echo "" >> "$yaml_file"
echo " ${lc}_insert:" >> "$yaml_file"
echo " - [ 0, 0, insert_bg]" >> "$yaml_file"
reset_base Insert.png
center_up "${lc}_model_text" 'hwid'
center_up "url"
center_up "${lc}_insert_text"
echo "" >> "$yaml_file"
done
# Finally list the localizations.
cat >>"$yaml_file" <<EOF2
localizations:
# This determines the order in which the localizations appear. The first
# one is the default.
EOF2
# Let's try to use the native one first, if we can.
guess_locale "$yaml_file"
for lc in $newlocales; do
echo " - [ ${lc}_devel, ${lc}_remove, ${lc}_yuck, ${lc}_insert ]" >> \
"$yaml_file"
done
done
# Now replace the 'hwid' string with '$HWID'.
perl -i -p -e 's/\bhwid\b/\$HWID/g;' "$yaml_file"
echo ""
|