OLD | NEW |
(Empty) | |
| 1 #!/bin/bash -eu |
| 2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 # |
| 6 # Generate a new yaml file for each specified hwid_*.bmp file. |
| 7 # |
| 8 |
| 9 # Do initial release locales only, 'cause I'm in a hurry. GB == US. |
| 10 locales="en es fr it nl de" |
| 11 localedir="./localized_bitmaps" |
| 12 |
| 13 # Arbitrary padding |
| 14 ypad=5 |
| 15 xpad=10 |
| 16 yborder=40 |
| 17 |
| 18 |
| 19 # Stuff to center and position bitmaps from the bottom of the screen upwards. |
| 20 |
| 21 # Globals |
| 22 cur_x=0 |
| 23 cur_y=0 |
| 24 |
| 25 |
| 26 # Return width of the specified .bmp file |
| 27 get_x() { |
| 28 file $1 | awk '{print $7}' |
| 29 } |
| 30 |
| 31 get_xx() { |
| 32 local ffile=$(eval "echo \$$1") |
| 33 get_x $ffile |
| 34 } |
| 35 |
| 36 # Return height of the specified .bmp file |
| 37 get_y() { |
| 38 file $1 | awk '{print $9}' |
| 39 } |
| 40 |
| 41 # Return height of the specified .bmp file |
| 42 get_yy() { |
| 43 local ffile=$(eval "echo \$$1") |
| 44 get_y $ffile |
| 45 } |
| 46 |
| 47 |
| 48 # Guess the locale based on the filename, set a global "newlocales" list |
| 49 # accordingly. |
| 50 guess_locale() { |
| 51 local lc |
| 52 local islc |
| 53 local matches |
| 54 islc= |
| 55 |
| 56 matches=0 |
| 57 for lc in $locales; do |
| 58 case "$1" in |
| 59 *[_-]${lc}_* ) |
| 60 matches=$(expr $matches + 1) |
| 61 islc=$lc |
| 62 ;; |
| 63 esac |
| 64 done |
| 65 if (( $matches != 1 )); then |
| 66 islc='en' |
| 67 fi |
| 68 |
| 69 local newlist |
| 70 newlist="$islc" |
| 71 for lc in $locales; do |
| 72 if [ "$lc" != "$islc" ]; then |
| 73 newlist="$newlist $lc" |
| 74 fi |
| 75 done |
| 76 |
| 77 newlocales=$newlist |
| 78 } |
| 79 |
| 80 |
| 81 # Reset the current baseline and width to the size of the specified .bmp file |
| 82 reset_base() { |
| 83 cur_x=$(get_x "$1") |
| 84 cur_y=$(expr $(get_y $1) - $yborder) |
| 85 } |
| 86 |
| 87 # Emit a screen line entry centering the given .bmp files at the current |
| 88 # baseline. We assume that all args are the same height. |
| 89 center_up() { |
| 90 local totalx |
| 91 local totaly |
| 92 local x |
| 93 local ffile |
| 94 |
| 95 totaly=$(get_yy "$1") |
| 96 cur_y=$(expr $cur_y - $totaly - $ypad) |
| 97 |
| 98 totalx=$(expr 0 - $xpad / 2) |
| 99 for fname in "$@"; do |
| 100 totalx=$(expr $totalx + $(get_xx $fname) + $xpad) |
| 101 done |
| 102 |
| 103 x=$(expr "(" $cur_x - $totalx ")" / 2) |
| 104 |
| 105 for fname in $*; do |
| 106 echo " - [$x, $cur_y, $fname]" >> "$yaml_file" |
| 107 x=$(expr $x + $(get_xx $fname) + $xpad) |
| 108 done |
| 109 } |
| 110 |
| 111 |
| 112 |
| 113 # Generate a new yaml file for each specified hwid_*.bmp file. |
| 114 for hwid_bmp in "$@"; do |
| 115 yaml_file=$(echo $(basename "$hwid_bmp" .bmp) | tr 'A-Z' 'a-z').yaml |
| 116 echo "$yaml_file" |
| 117 |
| 118 # List the images. The major difference is the HWID. |
| 119 cat >"$yaml_file" <<EOF1 |
| 120 bmpblock: 1.0 |
| 121 |
| 122 compression: 1 |
| 123 |
| 124 images: |
| 125 |
| 126 # The HWID must change for every BOM |
| 127 hwid: $hwid_bmp |
| 128 |
| 129 # This URL never changes |
| 130 url: URL.bmp |
| 131 |
| 132 # The background images are from the UI people |
| 133 devmode_bg: Devmode.bmp |
| 134 remove_bg: Remove.bmp |
| 135 yuck_bg: Yuck.bmp |
| 136 insert_bg: Insert.bmp |
| 137 |
| 138 # The following strings must be approved by the localization people |
| 139 EOF1 |
| 140 |
| 141 # some global variables matching the yaml definitions |
| 142 hwid=$hwid_bmp |
| 143 url="URL.bmp" |
| 144 |
| 145 # Enumerate the bitmaps for each locale-specific string. |
| 146 for lc in $locales; do |
| 147 cat >>"$yaml_file" <<EOF2 |
| 148 ${lc}_model_text: ${localedir}/$lc/model.bmp |
| 149 ${lc}_devmode_text: ${localedir}/$lc/devmode.bmp |
| 150 ${lc}_remove_text: ${localedir}/$lc/remove.bmp |
| 151 ${lc}_yuck_text: ${localedir}/$lc/yuck.bmp |
| 152 ${lc}_insert_text: ${localedir}/$lc/insert.bmp |
| 153 |
| 154 EOF2 |
| 155 |
| 156 # Also define global variables matching those in the yaml file. |
| 157 eval "${lc}_model_text=${localedir}/$lc/model.bmp" |
| 158 eval "${lc}_devmode_text=${localedir}/$lc/devmode.bmp" |
| 159 eval "${lc}_remove_text=${localedir}/$lc/remove.bmp" |
| 160 eval "${lc}_yuck_text=${localedir}/$lc/yuck.bmp" |
| 161 eval "${lc}_insert_text=${localedir}/$lc/insert.bmp" |
| 162 done |
| 163 |
| 164 # List the screens. We need to composite four screens for each locale. |
| 165 echo "screens:" >> "$yaml_file" |
| 166 |
| 167 for lc in $locales; do |
| 168 echo " ${lc}_devel:" >> "$yaml_file" |
| 169 echo " - [ 0, 0, devmode_bg]" >> "$yaml_file" |
| 170 reset_base Devmode.bmp |
| 171 center_up "${lc}_devmode_text" |
| 172 echo "" >> "$yaml_file" |
| 173 |
| 174 echo " ${lc}_remove:" >> "$yaml_file" |
| 175 echo " - [ 0, 0, remove_bg]" >> "$yaml_file" |
| 176 reset_base Remove.bmp |
| 177 center_up "${lc}_model_text" "hwid" |
| 178 center_up "url" |
| 179 center_up "${lc}_remove_text" |
| 180 echo "" >> "$yaml_file" |
| 181 |
| 182 echo " ${lc}_yuck:" >> "$yaml_file" |
| 183 echo " - [ 0, 0, yuck_bg]" >> "$yaml_file" |
| 184 reset_base Yuck.bmp |
| 185 center_up "${lc}_model_text" "hwid" |
| 186 center_up "url" |
| 187 center_up "${lc}_yuck_text" |
| 188 echo "" >> "$yaml_file" |
| 189 |
| 190 echo " ${lc}_insert:" >> "$yaml_file" |
| 191 echo " - [ 0, 0, insert_bg]" >> "$yaml_file" |
| 192 reset_base Insert.bmp |
| 193 center_up "${lc}_model_text" "hwid" |
| 194 center_up "url" |
| 195 center_up "${lc}_insert_text" |
| 196 echo "" >> "$yaml_file" |
| 197 |
| 198 done |
| 199 |
| 200 |
| 201 # Finally list the localizations. |
| 202 |
| 203 cat >>"$yaml_file" <<EOF2 |
| 204 localizations: |
| 205 |
| 206 # This determines the order in which the localizations appear. The first |
| 207 # one is the default. |
| 208 |
| 209 EOF2 |
| 210 |
| 211 # Let's try to use the native one first, if we can. |
| 212 guess_locale "$yaml_file" |
| 213 |
| 214 for lc in $newlocales; do |
| 215 echo " - [ ${lc}_devel, ${lc}_remove, ${lc}_yuck, ${lc}_insert ]" >> \ |
| 216 "$yaml_file" |
| 217 done |
| 218 |
| 219 done |
OLD | NEW |