summaryrefslogtreecommitdiff
path: root/scripts/newbitmaps/images/make_yaml_from_hwids
blob: 7e7da3f17231422fdb102898ff7b4ac4e04389da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/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