| #!/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 |
| local old_xpad="$xpad" |
| set_centered_y_percent "white_bg" 80 |
| insert_centered_below "divider_btm" |
| # Temporarily change padding to zero because both help_*_text and url |
| # have margins. |
| xpad="0" |
| 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" |
| xpad="$old_xpad" |
| } |
| |
| 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" |
| |
| # 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: Url.bmp |
| |
| # Various UI elements |
| arrow_left: arrow_left.bmp |
| arrow_right: arrow_right.bmp |
| chrome_logo: chrome_logo.bmp |
| devmode_graphic: Devmode_graphic.bmp |
| divider_btm: divider_btm.bmp |
| divider_top: divider_top.bmp |
| remove_graphic: Remove_graphic_usbonly.bmp |
| insert_graphic: Insert_graphic.bmp |
| white_bg: Background_white.bmp |
| yuck_graphic: Yuck_graphic.bmp |
| |
| # The following strings must be approved by the localization people |
| EOF1 |
| |
| # Global variables matching the yaml definitions |
| arrow_left='arrow_left.bmp' |
| arrow_right='arrow_right.bmp' |
| chrome_logo='chrome_logo.bmp' |
| devmode_graphic='Devmode_graphic.bmp' |
| divider_btm='divider_btm.bmp' |
| divider_top='divider_top.bmp' |
| hwid=$hwid_bmp |
| insert_graphic='Insert_graphic.bmp' |
| remove_graphic='Remove_graphic_usbonly.bmp' |
| url='Url.bmp' |
| white_bg='Background_white.bmp' |
| yuck_graphic='Yuck_graphic.bmp' |
| |
| # 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_kiev_text=${localedir}/$lc/insert_kiev.bmp" |
| eval "${lc}_language_text=${localedir}/$lc/language.bmp" |
| eval "${lc}_help_left_text=${localedir}/$lc/for_help_left.bmp" |
| eval "${lc}_help_right_text=${localedir}/$lc/for_help_right.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_kiev_text: $(eval echo \$${lc}_insert_kiev_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) |
| |
| 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" 40 |
| add_centered "devmode_graphic" |
| set_centered_y_percent "white_bg" 50 |
| add_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 "remove_graphic" |
| 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 "yuck_graphic" |
| 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" 40 |
| add_centered "insert_graphic" |
| set_centered_y_percent "white_bg" 50 |
| add_centered_below "${lc}_insert_kiev_text" |
| add_footer_with_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 |
| 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'. |
| sed -i 's/\bhwid\b/\$HWID/g' "$yaml_file" |
| |
| echo "" |