blob: 7e7da3f17231422fdb102898ff7b4ac4e04389da [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 yaml file for each specified hwid_*.bmp file.
#
# Do initial release locales only, 'cause I'm in a hurry. GB == US.
locales="en es fr it nl de"
localedir="./localized_bitmaps"
# 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}'
}
get_xx() {
local ffile=$(eval "echo \$$1")
get_x $ffile
}
# Return height of the specified .bmp file
get_y() {
file $1 | awk '{print $9}'
}
# 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
echo " - [$x, $cur_y, $fname]" >> "$yaml_file"
x=$(expr $x + $(get_xx $fname) + $xpad)
done
}
# Generate a new yaml file for each specified hwid_*.bmp file.
for hwid_bmp in "$@"; do
yaml_file=$(echo $(basename "$hwid_bmp" .bmp) | tr 'A-Z' 'a-z').yaml
echo "$yaml_file"
# List the images. The major difference is the HWID.
cat >"$yaml_file" <<EOF1
bmpblock: 1.0
compression: 1
images:
# The HWID must change for every BOM
hwid: $hwid_bmp
# 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 " ${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
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.bmp
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.bmp
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