summaryrefslogtreecommitdiff
path: root/scripts/newbitmaps/images/make_default_yaml
blob: 69772ca12f03fce5c4810fe34154c3920fd7a77b (plain)
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
#!/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_placeholder.bmp 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="./locale"

# These render right-to-left
rtol="ar fa iw"

# Accept optional args which are the locales to emit. Default is all of 'em.
if [ -n "$*" ]; then
  # Make sure all the args actually match
  for arg in "$@"; do
    if [ ! -d "$localedir/$arg" ]; then
      echo "$0: locale \"$arg\" is unknown" 1>&2
      exit 1
    fi
  done
  locales="$*"
fi

# Arbitrary padding
ypad=5
xpad=5

# Globals used to specify location images are inserted.
cur_x=0
cur_y=0

reset_pos() {
  cur_x=0
  cur_y=0
}

move_pos_up() {
  cur_y=$(expr $cur_y - $1 )
}

move_pos_down() {
  cur_y=$(expr $cur_y + $1 )
}

move_pos_left() {
  cur_x=$(expr $cur_x - $1 )
}

move_pos_right() {
  cur_x=$(expr $cur_x + $1 )
}

# Move insert location to the vertical midline of a specified image.
# Example: set_centered_y_percent 'some_image' 80
# Sets insert point to the center of an image specified by a variable name,
# 80% towards the bottom. Assumes image was inserted at 0,0 so only good
# for the background image.
set_centered_y_percent() {
  cur_x=$(expr $(get_width $1) / 2 )
  cur_y=$(expr $(get_height $1) \* $2 / 100 )
}

# Return width of a .bmp file specified by a variable.
get_width() {
  local filename="$(eval "echo \$$1")"
  identify -format "%[fx:w]" "$filename"
}

# Return the width of a list of images.
total_width() {
  local width=$(expr 0 - $xpad)
  for filename in "$@"; do
    width=$(expr $width + $(get_width ${filename}) + $xpad)
  done
  echo $width
}

# Return height of a .bmp file specified by a variable.
get_height() {
  local filename="$(eval "echo \$${1}")"
  identify -format "%[fx:h]" "$filename"
}

# Returns the max height of a list of images.
get_max_height() {
  local max_height=0
  local height
  for filename in $@; do
    height=$(get_height ${filename})
    [ $max_height -gt $height ] || max_height=$height
  done
  echo $max_height
}

# 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
}

# Add a list of images at provided location.
# Images of different heights are added centered on the tallest image.
add_images() {
  local x=$1
  local y=$2
  local files=${@:3}
  local max_height=$(get_max_height $files)

  for fname in $files; do
    tmp_y=$(echo $( expr $y + "(" $max_height - $(get_height $fname) ")" / 2 ) )
    if [ "$fname" = "th_model_text" ]; then
      tmp_y=$(expr $y - 9)
    fi
    echo "    - [$x, $tmp_y, $fname]" >> "$yaml_file"
    x=$(expr $x + $(get_width $fname) + $xpad)
  done
}

add_centered_below() {
  local images=$@
  local width
  local height
  local x

  width=$(total_width $images)
  x=$(expr $cur_x - $width / 2)

  add_images $x $cur_y $images
}

# This adds a list of images and updates the insert location
# below the new images with a padding of $ypad.
insert_centered_below() {
  local images=$@
  local width
  local height
  local x

  width=$(total_width $images)
  x=$(expr $cur_x - $width / 2)

  add_images $x $cur_y $images

  height=$(get_max_height $images)
  move_pos_down $(expr $height + $ypad)
}

add_right_above() {
  local images=$@
  local height
  local x
  local y

  height=$(get_max_height $images)
  y=$(expr $cur_y - $height)

  add_images $cur_x $y $images
}

add_right_below() {
  add_images $cur_x $cur_y $@
}

add_left_above() {
  local images=$@
  local width
  local height
  local x
  local y

  height=$(get_max_height $images)
  y=$(expr $cur_y - $height)

  width=$(total_width $images)
  x=$(expr $cur_x - $width)

  add_images $x $y $images
}

add_centered() {
  local images=$@
  local width
  local height
  local x
  local y

  height=$(get_max_height $images)
  y=$(expr $cur_y - $height / 2)

  width=$(total_width $images)
  x=$(expr $cur_x - $width / 2)

  add_images $x $y $images
}

add_header() {
  local lc=$1
  set_centered_y_percent "white_bg" 17
  add_centered_below "divider_top"
  move_pos_left $(expr $(get_width "divider_top") / 2 )
  move_pos_up $ypad
  add_right_above "chrome_logo"
  move_pos_right $(get_width "divider_top")
  add_left_above "arrow_left" "${lc}_language_text" "arrow_right"
}

add_footer_with_url() {
  local lc=$1
  set_centered_y_percent "white_bg" 80
  insert_centered_below "divider_btm"
  insert_centered_below "${lc}_help_left_text" "url" "${lc}_help_right_text"
  if echo "$rtol" | grep -q -w "$lc" ; then
    insert_centered_below 'hwid' "${lc}_model_text"
  else
    insert_centered_below "${lc}_model_text" 'hwid'
  fi
  echo "" >> "$yaml_file"
}

add_footer_without_url() {
  local lc=$1
  set_centered_y_percent "white_bg" 80
  insert_centered_below "divider_btm"
  if echo "$rtol" | grep -q -w "$lc" ; then
    insert_centered_below 'hwid' "${lc}_model_text"
  else
    insert_centered_below "${lc}_model_text" 'hwid'
  fi
  echo "" >> "$yaml_file"
}

# TODO(hungte) Remove the unnecessary hwid_*.bmp loop below.
# Generate a new yaml file for each specified hwid_*.bmp file.
for hwid_bmp in hwid_placeholder.bmp; do
  echo "$yaml_file"

  # Global variables matching the yaml definitions
  arrow_left='arrow_left.bmp'
  arrow_right='arrow_right.bmp'
  chrome_logo='chrome_logo.bmp'
  divider_btm='divider_btm.bmp'
  divider_top='divider_top.bmp'
  url='Url.bmp'
  white_bg='Background_white.bmp'

  asset_BadSD='BadSD.bmp'
  asset_BadUSB='BadUSB.bmp'
  asset_RemoveDevices='RemoveDevices.bmp'
  asset_VerificationOff='VerificationOff.bmp'
  asset_VerificationOn='VerificationOn.bmp'
  asset_Warning='Warning.bmp'

  hwid=$hwid_bmp

  # List the images. The major difference is the HWID.
  cat >"$yaml_file" <<EOF1
bmpblock: 2.0

compression: 2

images:

  # We must specify a font blob to use to render the HWID
  \$HWID:                  hwid_fonts.bin

  # This URL never changes
  url:                    $(eval echo \$url)

  # Various UI elements
  arrow_left:             $(eval echo \$arrow_left)
  arrow_right:            $(eval echo \$arrow_right)
  chrome_logo:            $(eval echo \$chrome_logo)
  divider_btm:            $(eval echo \$divider_btm)
  divider_top:            $(eval echo \$divider_top)
  white_bg:               $(eval echo \$white_bg)

  asset_BadSD:            $(eval echo \$asset_BadSD)
  asset_BadUSB:           $(eval echo \$asset_BadUSB)
  asset_RemoveDevices:    $(eval echo \$asset_RemoveDevices)
  asset_VerificationOff:  $(eval echo \$asset_VerificationOff)
  asset_VerificationOn:   $(eval echo \$asset_VerificationOn)
  asset_Warning:          $(eval echo \$asset_Warning)

  # The following strings must be approved by the localization people
EOF1


  # Enumerate the bitmaps for each locale-specific string.
  for lc in $locales; do
    # Locale-specific variables matching those in the yaml file.
    eval "${lc}_model_text=${localedir}/$lc/model.bmp"
    eval "${lc}_devmode_text=${localedir}/$lc/devmode.bmp"
    eval "${lc}_remove_text=${localedir}/$lc/remove.bmp"
    eval "${lc}_yuck_text=${localedir}/$lc/yuck.bmp"
    eval "${lc}_insert_text=${localedir}/$lc/insert.bmp"
    eval "${lc}_language_text=${localedir}/$lc/language.bmp"
    eval "${lc}_for_help_text=${localedir}/$lc/for_help.bmp"
    eval "${lc}_help_left_text=${localedir}/$lc/for_help_left.bmp"
    eval "${lc}_help_right_text=${localedir}/$lc/for_help_right.bmp"
    eval "${lc}_todev_text=${localedir}/$lc/todev.bmp"
    eval "${lc}_tonorm_text=${localedir}/$lc/tonorm.bmp"
    eval "${lc}_verif_off_text=${localedir}/$lc/verif_off.bmp"
    eval "${lc}_verif_on_text=${localedir}/$lc/verif_on.bmp"
    eval "${lc}_reboot_erase_text=${localedir}/$lc/reboot_erase.bmp"
    eval "${lc}_back_help_text=${localedir}/$lc/back_help.bmp"
    eval "${lc}_update_text=${localedir}/$lc/update.bmp"

    cat >>"$yaml_file" <<EOF2
  ${lc}_model_text:       $(eval echo \$${lc}_model_text)
  ${lc}_devmode_text:     $(eval echo \$${lc}_devmode_text)
  ${lc}_remove_text:      $(eval echo \$${lc}_remove_text)
  ${lc}_yuck_text:        $(eval echo \$${lc}_yuck_text)
  ${lc}_insert_text:      $(eval echo \$${lc}_insert_text)
  ${lc}_language_text:    $(eval echo \$${lc}_language_text)
  ${lc}_help_left_text:   $(eval echo \$${lc}_help_left_text)
  ${lc}_help_right_text:  $(eval echo \$${lc}_help_right_text)
  ${lc}_todev_text:       $(eval echo \$${lc}_todev_text)
  ${lc}_tonorm_text:      $(eval echo \$${lc}_tonorm_text)
  ${lc}_verif_off_text:   $(eval echo \$${lc}_verif_off_text)
  ${lc}_verif_on_text:    $(eval echo \$${lc}_verif_on_text)
  ${lc}_update_text:      $(eval echo \$${lc}_update_text)
  ${lc}_reboot_erase_text: $(eval echo \$${lc}_reboot_erase_text)

EOF2

  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"

    # Dev Screen
    echo "  ${lc}_devel:" >> "$yaml_file"
    reset_pos
    add_right_below "white_bg"
    add_header ${lc}
    set_centered_y_percent "white_bg" 30
    insert_centered_below "asset_VerificationOff"
    insert_centered_below "${lc}_verif_off_text"
    insert_centered_below "${lc}_devmode_text"
    add_footer_without_url ${lc}

    # Remove Screen
    echo "  ${lc}_remove:" >> "$yaml_file"
    reset_pos
    add_right_below "white_bg"
    add_header ${lc}
    set_centered_y_percent "white_bg" 25
    add_centered_below "${lc}_remove_text"
    set_centered_y_percent "white_bg" 50
    add_centered "asset_RemoveDevices"
    add_footer_with_url ${lc}

    # Yuck Screen
    echo "  ${lc}_yuck:" >> "$yaml_file"
    reset_pos
    add_right_below "white_bg"
    add_header ${lc}
    set_centered_y_percent "white_bg" 25
    add_centered_below "${lc}_yuck_text"
    set_centered_y_percent "white_bg" 50
    add_centered "asset_BadSD" "asset_BadUSB"
    add_footer_with_url ${lc}

    # Insert Screen
    echo "  ${lc}_insert:" >> "$yaml_file"
    reset_pos
    add_right_below "white_bg"
    add_header ${lc}
    set_centered_y_percent "white_bg" 30
    insert_centered_below "asset_Warning"
    insert_centered_below "${lc}_insert_text"
    add_footer_with_url ${lc}

    # ToDeveloper Screen
    echo "  ${lc}_todev:" >> "$yaml_file"
    reset_pos
    add_right_below "white_bg"
    add_header ${lc}
    set_centered_y_percent "white_bg" 45
    add_centered "${lc}_todev_text"
    add_footer_without_url ${lc}

    # ToNormal Screen
    echo "  ${lc}_tonorm:" >> "$yaml_file"
    reset_pos
    add_right_below "white_bg"
    add_header ${lc}
    set_centered_y_percent "white_bg" 30
    insert_centered_below "asset_VerificationOff"
    insert_centered_below "${lc}_verif_off_text"
    insert_centered_below "${lc}_tonorm_text"
    add_footer_without_url ${lc}

    # Update (WAIT) Screen
    echo "  ${lc}_update:" >> "$yaml_file"
    reset_pos
    add_right_below "white_bg"
    add_header ${lc}
    set_centered_y_percent "white_bg" 50
    add_centered "${lc}_update_text"
    add_footer_without_url ${lc}

    # ToNormalConfirm Screen
    echo "  ${lc}_tonorm_confirm:" >> "$yaml_file"
    reset_pos
    add_right_below "white_bg"
    add_header ${lc}
    set_centered_y_percent "white_bg" 30
    insert_centered_below "asset_VerificationOn"
    insert_centered_below "${lc}_verif_on_text"
    insert_centered_below "${lc}_reboot_erase_text"
    add_footer_without_url ${lc}

  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
    screen_list="${lc}_devel, ${lc}_remove, ${lc}_yuck, ${lc}_insert"
    # todev/tonorm/update are supported only by newer firmware.
    screen_list="${screen_list}, ${lc}_todev, ${lc}_tonorm, ${lc}_update"
    screen_list="${screen_list}, ${lc}_tonorm_confirm"
    echo "  - [ $screen_list ]" >>"$yaml_file"
  done

  cat >>"$yaml_file" <<EOF3

locale_index:

  # List the locale names in order so we can choose the default at the factory

EOF3

  for lc in $newlocales; do
    echo "  - ${lc}" >> "$yaml_file"
  done

done

# Now replace the 'hwid' string with '$HWID'.
sed -i 's/\bhwid\b/\$HWID/g' "$yaml_file"

echo ""