summaryrefslogtreecommitdiff
path: root/scripts/newbitmaps/images/make_default_yaml
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/newbitmaps/images/make_default_yaml')
-rwxr-xr-xscripts/newbitmaps/images/make_default_yaml225
1 files changed, 225 insertions, 0 deletions
diff --git a/scripts/newbitmaps/images/make_default_yaml b/scripts/newbitmaps/images/make_default_yaml
new file mode 100755
index 00000000..8f4f0128
--- /dev/null
+++ b/scripts/newbitmaps/images/make_default_yaml
@@ -0,0 +1,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 ""