blob: 186bfcee033e5f6970220b04dff0352f84f3f64e [file] [log] [blame]
#!/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.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="./localized_images"
# 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=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 .bmp file
get_x() {
file $1 | awk '{print $7}' | sed -e 's/[^0-9]//g'
}
get_xx() {
local ffile=$(eval "echo \$$1")
get_x $ffile
}
# Return height of the specified .bmp file
get_y() {
file $1 | awk '{print $9}' | sed -e 's/[^0-9]//g'
}
# Return height of the specified .bmp 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 .bmp file
reset_base() {
cur_x=$(get_x "$1")
cur_y=$(expr $(get_y $1) - $yborder)
}
# Emit a screen line entry centering the given .bmp 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
if [ "$fname" = "th_model_text" ]; then
tmp_y=$(expr $cur_y - 9)
echo " - [$x, $tmp_y, $fname]" >> "$yaml_file"
else
echo " - [$x, $cur_y, $fname]" >> "$yaml_file"
fi
x=$(expr $x + $(get_xx $fname) + $xpad)
done
}
# Generate a new yaml file for each specified hwid_*.bmp file.
for hwid_bmp in hwid_unknown.bmp; do
echo "$yaml_file"
# List the images. The major difference is the HWID.
cat >"$yaml_file" <<'EOF1'
bmpblock: 1.2
compression: 1
images:
# We must specify a font blob to use to render the HWID
$HWID: hwid_fonts.bin
# This URL never changes
url: Url.bmp
# The background images are from the UI people
devmode_bg: Devmode.bmp
remove_bg: Remove.bmp
yuck_bg: Yuck.bmp
insert_bg: Insert.bmp
# The following strings must be approved by the localization people
EOF1
# some global variables matching the yaml definitions
hwid=$hwid_bmp
url="Url.bmp"
# Enumerate the bitmaps for each locale-specific string.
for lc in $locales; do
cat >>"$yaml_file" <<EOF2
${lc}_model_text: ${localedir}/$lc/model.bmp
${lc}_devmode_text: ${localedir}/$lc/devmode.bmp
${lc}_remove_text: ${localedir}/$lc/remove.bmp
${lc}_yuck_text: ${localedir}/$lc/yuck.bmp
${lc}_insert_text: ${localedir}/$lc/insert.bmp
EOF2
# Also define global 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"
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.bmp
center_up "${lc}_devmode_text"
echo "" >> "$yaml_file"
echo " ${lc}_remove:" >> "$yaml_file"
echo " - [ 0, 0, remove_bg]" >> "$yaml_file"
reset_base Remove.bmp
if echo "$rtol" | grep -q -w "$lc" ; then
center_up 'hwid' "${lc}_model_text"
else
center_up "${lc}_model_text" 'hwid'
fi
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.bmp
if echo "$rtol" | grep -q -w "$lc" ; then
center_up 'hwid' "${lc}_model_text"
else
center_up "${lc}_model_text" 'hwid'
fi
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.bmp
if echo "$rtol" | grep -q -w "$lc" ; then
center_up 'hwid' "${lc}_model_text"
else
center_up "${lc}_model_text" 'hwid'
fi
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
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'.
perl -i -p -e 's/\bhwid\b/\$HWID/g;' "$yaml_file"
echo ""