blob: 552484e8a7c9f1573e10c5318cb17c4ce9733b49 [file] [log] [blame]
Yu-Ping Wud71b4452020-06-16 11:00:26 +08001#!/usr/bin/env python
Hung-Te Lin707e2ef2013-08-06 10:20:04 +08002# Copyright (c) 2013 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.
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +08005"""Script to generate bitmaps for firmware screens."""
Hung-Te Lin707e2ef2013-08-06 10:20:04 +08006
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +08007import argparse
8from collections import defaultdict, namedtuple
9import copy
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080010import glob
Jes Klinke1687a992020-06-16 13:47:17 -070011import json
Hung-Te Lin04addcc2015-03-23 18:43:30 +080012import multiprocessing
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080013import os
14import re
Jes Klinke1687a992020-06-16 13:47:17 -070015import shutil
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080016import signal
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080017import subprocess
18import sys
Jes Klinke1687a992020-06-16 13:47:17 -070019import tempfile
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080020from xml.etree import ElementTree
Hung-Te Lin04addcc2015-03-23 18:43:30 +080021
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080022import yaml
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080023from PIL import Image
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080024
25SCRIPT_BASE = os.path.dirname(os.path.abspath(__file__))
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080026
27STRINGS_GRD_FILE = 'firmware_strings.grd'
28STRINGS_JSON_FILE_TMPL = '{}.json'
29FORMAT_FILE = 'format.yaml'
30BOARDS_CONFIG_FILE = 'boards.yaml'
31
32TXT_TO_PNG_SVG = os.path.join(SCRIPT_BASE, 'text_to_png_svg')
33STRINGS_DIR = os.path.join(SCRIPT_BASE, 'strings')
34LOCALE_DIR = os.path.join(STRINGS_DIR, 'locale')
35OUTPUT_DIR = os.getenv('OUTPUT', os.path.join(SCRIPT_BASE, 'build'))
36STAGE_DIR = os.path.join(OUTPUT_DIR, '.stage')
37STAGE_LOCALE_DIR = os.path.join(STAGE_DIR, 'locale')
38STAGE_FONT_DIR = os.path.join(STAGE_DIR, 'font')
39
40ONE_LINE_DIR = 'one_line'
41SVG_FILES = '*.svg'
42PNG_FILES = '*.png'
43
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +080044DIAGNOSTIC_UI = os.getenv('DIAGNOSTIC_UI') == '1'
45
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080046# String format YAML key names.
Yu-Ping Wu10cf2892020-08-10 17:20:11 +080047DEFAULT_NAME = '_DEFAULT_'
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080048KEY_LOCALES = 'locales'
Yu-Ping Wu338f0832020-10-23 16:14:40 +080049KEY_GENERIC_FILES = 'generic_files'
50KEY_LOCALIZED_FILES = 'localized_files'
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080051KEY_FONTS = 'fonts'
52KEY_STYLES = 'styles'
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +080053KEY_BGCOLOR = 'bgcolor'
54KEY_FGCOLOR = 'fgcolor'
55KEY_HEIGHT = 'height'
Yu-Ping Wued95df32020-11-04 17:08:15 +080056KEY_MAX_WIDTH = 'max_width'
Matt Delco4c5580d2019-03-07 14:00:28 -080057DIAGNOSTIC_FILES = 'diagnostic_files'
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080058
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080059# Board config YAML key names.
60SCREEN_KEY = 'screen'
61PANEL_KEY = 'panel'
62SDCARD_KEY = 'sdcard'
63BAD_USB3_KEY = 'bad_usb3'
64LOCALES_KEY = 'locales'
65RTL_KEY = 'rtl'
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080066TEXT_COLORS_KEY = 'text_colors'
67RW_OVERRIDE_KEY = 'rw_override'
68
69BMP_HEADER_OFFSET_NUM_LINES = 6
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080070
Jes Klinke1687a992020-06-16 13:47:17 -070071# Regular expressions used to eliminate spurious spaces and newlines in
72# translation strings.
73NEWLINE_PATTERN = re.compile(r'([^\n])\n([^\n])')
74NEWLINE_REPLACEMENT = r'\1 \2'
75CRLF_PATTERN = re.compile(r'\r\n')
76MULTIBLANK_PATTERN = re.compile(r' *')
77
Yu-Ping Wu11027f02020-10-14 17:35:42 +080078GLYPH_FONT = 'Noto Sans Mono'
79
Yu-Ping Wuabb9afb2020-10-27 17:15:22 +080080LocaleInfo = namedtuple('LocaleInfo', ['code', 'rtl'])
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080081
Yu-Ping Wu6b282c52020-03-19 12:54:15 +080082
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080083class DataError(Exception):
84 pass
85
86
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080087class BuildImageError(Exception):
88 """The exception class for all errors generated during build image process."""
89
90
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +080091def get_config_with_defaults(configs, key):
92 """Gets config of `key` from `configs`.
93
94 If `key` is not present in `configs`, the default config will be returned.
95 Similarly, if some config values are missing for `key`, the default ones will
96 be used.
97 """
98 config = configs[DEFAULT_NAME].copy()
99 config.update(configs.get(key, {}))
100 return config
101
102
Yu-Ping Wued95df32020-11-04 17:08:15 +0800103def convert_text_to_png(locale, input_file, font, output_dir, height=None,
104 max_width=None, margin='0', bgcolor='#000000',
105 fgcolor='#ffffff', **options):
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800106 """Converts text files into PNG image files.
107
108 Args:
109 locale: Locale (language) to select implicit rendering options. None for
110 locale-independent strings.
111 input_file: Path of input text file.
112 font: Font spec.
Yu-Ping Wued95df32020-11-04 17:08:15 +0800113 height: Height.
114 max_width: Maximum width.
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800115 margin: CSS-style margin.
116 output_dir: Directory to generate image files.
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800117 bgcolor: Background color (#rrggbb).
118 fgcolor: Foreground color (#rrggbb).
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800119 **options: Other options to be added.
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800120 """
121 name, _ = os.path.splitext(os.path.basename(input_file))
122 command = [TXT_TO_PNG_SVG, '--outdir=%s' % output_dir]
123 if locale:
124 command.append('--lan=%s' % locale)
125 if font:
126 command.append("--font='%s'" % font)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800127 font_size = os.getenv('FONT_SIZE')
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800128 if font_size:
129 command.append('--point=%r' % font_size)
Yu-Ping Wued95df32020-11-04 17:08:15 +0800130 if max_width:
131 # Without the --width option set, the minimum height of the output SVG
132 # image is roughly 22px (for locale 'en'). With --width=WIDTH passed to
133 # pango-view, the width of the output seems to always be (WIDTH * 4 / 3),
134 # regardless of the font being used. Therefore, set the max_width in
135 # points as follows to prevent drawing from exceeding canvas boundary in
136 # depthcharge runtime.
137 max_width_pt = int(22 * max_width / height / (4 / 3))
138 command.append('--width=%d' % max_width_pt)
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800139 if margin:
140 command.append('--margin="%s"' % margin)
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800141 command.append('--bgcolor="%s"' % bgcolor)
142 command.append('--color="%s"' % fgcolor)
143
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800144 for k, v in options.items():
145 command.append('--%s="%s"' % (k, v))
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800146 command.append(input_file)
147
148 return subprocess.call(' '.join(command), shell=True,
149 stdout=subprocess.PIPE) == 0
150
151
152def convert_glyphs():
153 """Converts glyphs of ascii characters."""
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800154 os.makedirs(STAGE_FONT_DIR, exist_ok=True)
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800155 # Remove the extra whitespace at the top/bottom within the glyphs
156 margin = '-3 0 -1 0'
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800157 for c in range(ord(' '), ord('~') + 1):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800158 txt_file = os.path.join(STAGE_FONT_DIR, f'idx{c:03d}_{c:02x}.txt')
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800159 with open(txt_file, 'w', encoding='ascii') as f:
160 f.write(chr(c))
161 f.write('\n')
162 # TODO(b/163109632): Parallelize the conversion of glyphs
Yu-Ping Wued95df32020-11-04 17:08:15 +0800163 convert_text_to_png(None, txt_file, GLYPH_FONT, STAGE_FONT_DIR,
164 margin=margin)
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800165
166
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800167def _load_locale_json_file(locale, json_dir):
Jes Klinke1687a992020-06-16 13:47:17 -0700168 result = {}
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800169 filename = os.path.join(json_dir, STRINGS_JSON_FILE_TMPL.format(locale))
Yu-Ping Wud71b4452020-06-16 11:00:26 +0800170 with open(filename, encoding='utf-8-sig') as input_file:
Jes Klinke1687a992020-06-16 13:47:17 -0700171 for tag, msgdict in json.load(input_file).items():
172 msgtext = msgdict['message']
173 msgtext = re.sub(CRLF_PATTERN, '\n', msgtext)
174 msgtext = re.sub(NEWLINE_PATTERN, NEWLINE_REPLACEMENT, msgtext)
175 msgtext = re.sub(MULTIBLANK_PATTERN, ' ', msgtext)
176 # Strip any trailing whitespace. A trailing newline appears to make
177 # Pango report a larger layout size than what's actually visible.
178 msgtext = msgtext.strip()
179 result[tag] = msgtext
180 return result
181
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800182
183def parse_locale_json_file(locale, json_dir):
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800184 """Parses given firmware string json file.
Mathew King89d48c62019-02-15 10:08:39 -0700185
186 Args:
Yu-Ping Wu8f633b82020-09-22 14:27:57 +0800187 locale: The name of the locale, e.g. "da" or "pt-BR".
Jes Klinke1687a992020-06-16 13:47:17 -0700188 json_dir: Directory containing json output from grit.
Mathew King89d48c62019-02-15 10:08:39 -0700189
190 Returns:
191 A dictionary for mapping of "name to content" for files to be generated.
192 """
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800193 result = _load_locale_json_file(locale, json_dir)
194 original = _load_locale_json_file('en', json_dir)
195 for tag in original:
196 if tag not in result:
197 # Use original English text, in case translation is not yet available
198 print('WARNING: locale "%s", missing entry %s' % (locale, tag))
199 result[tag] = original[tag]
Mathew King89d48c62019-02-15 10:08:39 -0700200
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800201 return result
Mathew King89d48c62019-02-15 10:08:39 -0700202
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800203
204def parse_locale_input_files(locale, json_dir):
205 """Parses all firmware string files for the given locale.
206
207 Args:
208 locale: The name of the locale, e.g. "da" or "pt-BR".
209 json_dir: Directory containing json output from grit.
210
211 Returns:
212 A dictionary for mapping of "name to content" for files to be generated.
213 """
214 result = parse_locale_json_file(locale, json_dir)
215
216 # Walk locale directory to add pre-generated texts such as language names.
Yu-Ping Wu8f633b82020-09-22 14:27:57 +0800217 for input_file in glob.glob(os.path.join(LOCALE_DIR, locale, "*.txt")):
Mathew King89d48c62019-02-15 10:08:39 -0700218 name, _ = os.path.splitext(os.path.basename(input_file))
Yu-Ping Wud71b4452020-06-16 11:00:26 +0800219 with open(input_file, 'r', encoding='utf-8-sig') as f:
Mathew King89d48c62019-02-15 10:08:39 -0700220 result[name] = f.read().strip()
Shelley Chen2f616ac2017-05-22 13:19:40 -0700221
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800222 return result
223
224
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800225def build_text_files(inputs, files, output_dir):
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800226 """Builds text files from given input data.
227
228 Args:
229 inputs: Dictionary of contents for given file name.
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800230 files: List of files.
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800231 output_dir: Directory to generate text files.
232 """
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800233 for name in files:
234 file_name = os.path.join(output_dir, name + '.txt')
235 with open(file_name, 'w', encoding='utf-8-sig') as f:
236 f.write(inputs[name] + '\n')
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800237
238
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800239def convert_localized_strings(formats):
240 """Converts localized strings."""
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800241 # Make a copy of formats to avoid modifying it
242 formats = copy.deepcopy(formats)
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800243
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800244 env_locales = os.getenv('LOCALES')
245 if env_locales:
246 locales = env_locales.split()
247 else:
248 locales = formats[KEY_LOCALES]
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800249
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800250 files = formats[KEY_LOCALIZED_FILES]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800251 if DIAGNOSTIC_UI:
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800252 files.update(formats[DIAGNOSTIC_FILES])
253
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800254 styles = formats[KEY_STYLES]
255 fonts = formats[KEY_FONTS]
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800256 default_font = fonts[DEFAULT_NAME]
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800257
Yu-Ping Wu51940352020-09-17 08:48:55 +0800258 # Sources are one .grd file with identifiers chosen by engineers and
259 # corresponding English texts, as well as a set of .xlt files (one for each
260 # language other than US english) with a mapping from hash to translation.
261 # Because the keys in the xlt files are a hash of the English source text,
262 # rather than our identifiers, such as "btn_cancel", we use the "grit"
263 # command line tool to process the .grd and .xlt files, producing a set of
264 # .json files mapping our identifier to the translated string, one for every
265 # language including US English.
Jes Klinke1687a992020-06-16 13:47:17 -0700266
Yu-Ping Wu51940352020-09-17 08:48:55 +0800267 # Create a temporary directory to place the translation output from grit in.
268 json_dir = tempfile.mkdtemp()
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800269
Yu-Ping Wu51940352020-09-17 08:48:55 +0800270 # This invokes the grit build command to generate JSON files from the XTB
271 # files containing translations. The results are placed in `json_dir` as
272 # specified in firmware_strings.grd, i.e. one JSON file per locale.
273 subprocess.check_call([
274 'grit',
Yu-Ping Wu8f633b82020-09-22 14:27:57 +0800275 '-i', os.path.join(LOCALE_DIR, STRINGS_GRD_FILE),
Yu-Ping Wu51940352020-09-17 08:48:55 +0800276 'build',
277 '-o', os.path.join(json_dir)
278 ])
Jes Klinke1687a992020-06-16 13:47:17 -0700279
Yu-Ping Wuc90a22f2020-04-24 11:17:15 +0800280 # Ignore SIGINT in child processes
281 sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
Hung-Te Lin04addcc2015-03-23 18:43:30 +0800282 pool = multiprocessing.Pool(multiprocessing.cpu_count())
Yu-Ping Wuc90a22f2020-04-24 11:17:15 +0800283 signal.signal(signal.SIGINT, sigint_handler)
284
Hung-Te Lin04addcc2015-03-23 18:43:30 +0800285 results = []
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800286 for locale in locales:
Yu-Ping Wud71b4452020-06-16 11:00:26 +0800287 print(locale, end=' ', flush=True)
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800288 inputs = parse_locale_input_files(locale, json_dir)
289 output_dir = os.path.normpath(os.path.join(STAGE_DIR, 'locale', locale))
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800290 if not os.path.exists(output_dir):
291 os.makedirs(output_dir)
Matt Delco4c5580d2019-03-07 14:00:28 -0800292
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800293 build_text_files(inputs, files, output_dir)
Shelley Chen2f616ac2017-05-22 13:19:40 -0700294
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800295 for name, category in files.items():
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800296 style = get_config_with_defaults(styles, category)
297 args = (
298 locale,
299 os.path.join(output_dir, '%s.txt' % name),
300 fonts.get(locale, default_font),
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800301 output_dir,
302 )
303 kwargs = {
Yu-Ping Wued95df32020-11-04 17:08:15 +0800304 'height': style[KEY_HEIGHT],
305 'max_width': style[KEY_MAX_WIDTH],
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800306 'bgcolor': style[KEY_BGCOLOR],
307 'fgcolor': style[KEY_FGCOLOR],
308 }
309 results.append(pool.apply_async(convert_text_to_png, args, kwargs))
Hung-Te Lin04addcc2015-03-23 18:43:30 +0800310 pool.close()
Jes Klinke1687a992020-06-16 13:47:17 -0700311 if json_dir is not None:
312 shutil.rmtree(json_dir)
Yu-Ping Wud71b4452020-06-16 11:00:26 +0800313 print()
Yu-Ping Wuc90a22f2020-04-24 11:17:15 +0800314
315 try:
316 success = [r.get() for r in results]
317 except KeyboardInterrupt:
318 pool.terminate()
319 pool.join()
320 exit('Aborted by user')
321 else:
322 pool.join()
323 if not all(success):
324 exit('Failed to render some locales')
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800325
326
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800327def build_strings(formats):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800328 """Builds text strings."""
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800329 # Convert glyphs
330 print('Converting glyphs...')
331 convert_glyphs()
332
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800333 # Convert generic (locale-independent) strings
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800334 files = formats[KEY_GENERIC_FILES]
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800335 styles = formats[KEY_STYLES]
336 fonts = formats[KEY_FONTS]
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800337 default_font = fonts[DEFAULT_NAME]
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800338
339 for input_file in glob.glob(os.path.join(STRINGS_DIR, '*.txt')):
340 name, _ = os.path.splitext(os.path.basename(input_file))
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800341 category = files[name]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800342 style = get_config_with_defaults(styles, category)
Yu-Ping Wued95df32020-11-04 17:08:15 +0800343 if not convert_text_to_png(None, input_file, default_font, STAGE_DIR,
344 height=style[KEY_HEIGHT],
345 max_width=style[KEY_MAX_WIDTH],
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800346 bgcolor=style[KEY_BGCOLOR],
347 fgcolor=style[KEY_FGCOLOR]):
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800348 exit('Failed to convert text %s' % input_file)
349
350 # Convert localized strings
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800351 convert_localized_strings(formats)
352
353
354def load_boards_config(filename):
355 """Loads the configuration of all boards from `filename`.
356
357 Args:
358 filename: File name of a YAML config file.
359
360 Returns:
361 A dictionary mapping each board name to its config.
362 """
363 with open(filename, 'rb') as file:
364 raw = yaml.load(file)
365
366 configs = {}
367 default = raw[DEFAULT_NAME]
368 if not default:
369 raise BuildImageError('Default configuration is not found')
370 for boards, params in raw.items():
371 if boards == DEFAULT_NAME:
372 continue
373 config = copy.deepcopy(default)
374 if params:
375 config.update(params)
376 for board in boards.replace(',', ' ').split():
377 configs[board] = config
378
379 return configs
380
381
382class Converter(object):
383 """Converter from assets, texts, URLs, and fonts to bitmap images.
384
385 Attributes:
386 ASSET_DIR (str): Directory of image assets.
387 DEFAULT_OUTPUT_EXT (str): Default output file extension.
388 DEFAULT_REPLACE_MAP (dict): Default mapping of file replacement. For
389 {'a': 'b'}, "a.*" will be converted to "b.*".
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800390 SCALE_BASE (int): See ASSET_HEIGHTS below.
391 DEFAULT_FONT_HEIGHT (tuple): Height of the font images.
392 ASSET_HEIGHTS (dict): Height of each image asset. Key is the image name and
393 value is the height relative to the screen resolution. For example, if
394 `SCALE_BASE` is 1000, height = 500 means the image will be scaled to 50%
395 of the screen height.
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800396 ASSET_MAX_COLORS (int): Maximum colors to use for converting image assets
397 to bitmaps.
398 DEFAULT_BACKGROUND (tuple): Default background color.
399 BACKGROUND_COLORS (dict): Background color of each image. Key is the image
400 name and value is a tuple of RGB values.
401 """
402
403 ASSET_DIR = 'assets'
404 DEFAULT_OUTPUT_EXT = '.bmp'
405
406 DEFAULT_REPLACE_MAP = {
407 'rec_sel_desc1_no_sd': '',
408 'rec_sel_desc1_no_phone_no_sd': '',
409 'rec_disk_step1_desc0_no_sd': '',
410 'rec_to_dev_desc1_phyrec': '',
411 'rec_to_dev_desc1_power': '',
412 'navigate0_tablet': '',
413 'navigate1_tablet': '',
414 'nav-button_power': '',
415 'nav-button_volume_up': '',
416 'nav-button_volume_down': '',
417 'broken_desc_phyrec': '',
418 'broken_desc_detach': '',
419 }
420
421 # scales
422 SCALE_BASE = 1000 # 100.0%
423
424 # These are supposed to be kept in sync with the numbers set in depthcharge
425 # to avoid runtime scaling, which makes images blurry.
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800426 DEFAULT_ASSET_HEIGHT = 30
427 DEFAULT_FONT_HEIGHT = 20
428 ICON_HEIGHT = 45
429 STEP_ICON_HEIGHT = 28
430 BUTTON_ICON_HEIGHT = 24
431 BUTTON_ARROW_HEIGHT = 20
432 QR_FOOTER_HEIGHT = 128
433 QR_DESC_HEIGHT = 228
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800434
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800435 ASSET_HEIGHTS = {
436 'ic_globe': 20,
437 'ic_dropdown': 24,
438 'ic_info': ICON_HEIGHT,
439 'ic_error': ICON_HEIGHT,
440 'ic_dev_mode': ICON_HEIGHT,
441 'ic_restart': ICON_HEIGHT,
442 'ic_1': STEP_ICON_HEIGHT,
443 'ic_1-done': STEP_ICON_HEIGHT,
444 'ic_2': STEP_ICON_HEIGHT,
445 'ic_2-done': STEP_ICON_HEIGHT,
446 'ic_3': STEP_ICON_HEIGHT,
447 'ic_3-done': STEP_ICON_HEIGHT,
448 'ic_done': STEP_ICON_HEIGHT,
449 'ic_search': BUTTON_ICON_HEIGHT,
450 'ic_search_focus': BUTTON_ICON_HEIGHT,
451 'ic_settings': BUTTON_ICON_HEIGHT,
452 'ic_settings_focus': BUTTON_ICON_HEIGHT,
453 'ic_power': BUTTON_ICON_HEIGHT,
454 'ic_power_focus': BUTTON_ICON_HEIGHT,
455 'ic_dropleft': BUTTON_ARROW_HEIGHT,
456 'ic_dropleft_focus': BUTTON_ARROW_HEIGHT,
457 'ic_dropright': BUTTON_ARROW_HEIGHT,
458 'ic_dropright_focus': BUTTON_ARROW_HEIGHT,
459 'qr_rec': QR_FOOTER_HEIGHT,
460 'qr_rec_phone': QR_DESC_HEIGHT,
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800461 }
462
463 # background colors
464 DEFAULT_BACKGROUND = (0x20, 0x21, 0x24)
465 LANG_HEADER_BACKGROUND = (0x16, 0x17, 0x19)
466 LINK_SELECTED_BACKGROUND = (0x2a, 0x2f, 0x39)
467 ASSET_MAX_COLORS = 128
468
469 BACKGROUND_COLORS = {
470 'ic_dropdown': LANG_HEADER_BACKGROUND,
471 'ic_dropleft_focus': LINK_SELECTED_BACKGROUND,
472 'ic_dropright_focus': LINK_SELECTED_BACKGROUND,
473 'ic_globe': LANG_HEADER_BACKGROUND,
474 'ic_search_focus': LINK_SELECTED_BACKGROUND,
475 'ic_settings_focus': LINK_SELECTED_BACKGROUND,
476 'ic_power_focus': LINK_SELECTED_BACKGROUND,
477 }
478
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800479 def __init__(self, board, formats, board_config, output):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800480 """Inits converter.
481
482 Args:
483 board: Board name.
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800484 formats: A dictionary of string formats.
485 board_config: A dictionary of board configurations.
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800486 output: Output directory.
487 """
488 self.board = board
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800489 self.formats = formats
490 self.config = board_config
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800491 self.set_dirs(output)
492 self.set_screen()
493 self.set_replace_map()
494 self.set_locales()
495 self.text_max_colors = self.config[TEXT_COLORS_KEY]
496
497 def set_dirs(self, output):
498 """Sets board output directory and stage directory.
499
500 Args:
501 output: Output directory.
502 """
503 self.output_dir = os.path.join(output, self.board)
504 self.output_ro_dir = os.path.join(self.output_dir, 'locale', 'ro')
505 self.output_rw_dir = os.path.join(self.output_dir, 'locale', 'rw')
506 self.stage_dir = os.path.join(output, '.stage')
507 self.temp_dir = os.path.join(self.stage_dir, 'tmp')
508
509 def set_screen(self):
510 """Sets screen width and height."""
511 self.screen_width, self.screen_height = self.config[SCREEN_KEY]
512
513 self.stretch = (1, 1)
514 if self.config[PANEL_KEY]:
515 # Calculate 'stretch'. It's used to shrink images horizontally so that
516 # resulting images will look proportional to the original image on the
517 # stretched display. If the display is not stretched, meaning aspect
518 # ratio is same as the screen where images were rendered (1366x766),
519 # no shrinking is performed.
520 panel_width, panel_height = self.config[PANEL_KEY]
521 self.stretch = (self.screen_width * panel_height,
522 self.screen_height * panel_width)
523
524 if self.stretch[0] > self.stretch[1]:
525 raise BuildImageError('Panel aspect ratio (%f) is smaller than screen '
526 'aspect ratio (%f). It indicates screen will be '
527 'shrunk horizontally. It is currently unsupported.'
528 % (panel_width / panel_height,
529 self.screen_width / self.screen_height))
530
531 # Set up square drawing area
532 self.canvas_px = min(self.screen_width, self.screen_height)
533
534 def set_replace_map(self):
535 """Sets a map replacing images.
536
537 For each (key, value), image 'key' will be replaced by image 'value'.
538 """
539 replace_map = self.DEFAULT_REPLACE_MAP.copy()
540
541 if os.getenv('DETACHABLE') == '1':
542 replace_map.update({
543 'nav-key_enter': 'nav-button_power',
544 'nav-key_up': 'nav-button_volume_up',
545 'nav-key_down': 'nav-button_volume_down',
546 'navigate0': 'navigate0_tablet',
547 'navigate1': 'navigate1_tablet',
548 'broken_desc': 'broken_desc_detach',
549 })
550
551 physical_presence = os.getenv('PHYSICAL_PRESENCE')
552 if physical_presence == 'recovery':
553 replace_map['rec_to_dev_desc1'] = 'rec_to_dev_desc1_phyrec'
554 replace_map['broken_desc'] = 'broken_desc_phyrec'
555 elif physical_presence == 'power':
556 replace_map['rec_to_dev_desc1'] = 'rec_to_dev_desc1_power'
557 elif physical_presence != 'keyboard':
558 raise BuildImageError('Invalid physical presence setting %s for board %s'
559 % (physical_presence, self.board))
560
561 if not self.config[SDCARD_KEY]:
562 replace_map.update({
563 'rec_sel_desc1': 'rec_sel_desc1_no_sd',
564 'rec_sel_desc1_no_phone': 'rec_sel_desc1_no_phone_no_sd',
565 'rec_disk_step1_desc0': 'rec_disk_step1_desc0_no_sd',
566 })
567
568 self.replace_map = replace_map
569
570 def set_locales(self):
571 """Sets a list of locales for which localized images are converted."""
572 # LOCALES environment variable can overwrite boards.yaml
573 env_locales = os.getenv('LOCALES')
574 rtl_locales = set(self.config[RTL_KEY])
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800575 if env_locales:
576 locales = env_locales.split()
577 else:
578 locales = self.config[LOCALES_KEY]
579 # Check rtl_locales are contained in locales.
580 unknown_rtl_locales = rtl_locales - set(locales)
581 if unknown_rtl_locales:
582 raise BuildImageError('Unknown locales %s in %s' %
583 (list(unknown_rtl_locales), RTL_KEY))
Yu-Ping Wuabb9afb2020-10-27 17:15:22 +0800584 self.locales = [LocaleInfo(code, code in rtl_locales)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800585 for code in locales]
586
587 def calculate_dimension(self, original, scale, num_lines):
588 """Calculates scaled width and height.
589
590 This imitates the function of Depthcharge with the same name.
591
592 Args:
593 original: (width, height) of the original image.
594 scale: (x, y) scale parameter relative to the canvas size using
595 SCALE_BASE as a base.
596 num_lines: multiplication factor for the y-dimension.
597
598 Returns:
599 (width, height) of the scaled image.
600 """
601 dim_width, dim_height = (0, 0)
602 scale_x, scale_y = scale
603 org_width, org_height = original
604
605 if scale_x == 0 and scale_y == 0:
606 raise BuildImageError('Invalid scale parameter: %s' % (scale))
607 if scale_x > 0:
608 dim_width = int(self.canvas_px * scale_x / self.SCALE_BASE)
609 if scale_y > 0:
610 dim_height = int(self.canvas_px * scale_y / self.SCALE_BASE) * num_lines
611 if scale_x == 0:
612 dim_width = org_width * dim_height // org_height
613 if scale_y == 0:
614 dim_height = org_height * dim_width // org_width
615
616 dim_width = int(dim_width * self.stretch[0] / self.stretch[1])
617
618 return dim_width, dim_height
619
620 def _get_svg_height(self, svg_file):
621 tree = ElementTree.parse(svg_file)
622 height = tree.getroot().attrib['height']
623 m = re.match('([0-9]+)pt', height)
624 if not m:
625 raise BuildImageError('Cannot get height from %s' % svg_file)
626 return int(m.group(1))
627
628 def get_num_lines(self, file, one_line_dir):
629 """Gets the number of lines of text in `file`."""
630 name, _ = os.path.splitext(os.path.basename(file))
631 svg_name = name + '.svg'
632 multi_line_file = os.path.join(os.path.dirname(file), svg_name)
633 one_line_file = os.path.join(one_line_dir, svg_name)
634 # The number of lines id determined by comparing the height of
635 # `multi_line_file` with `one_line_file`, where the latter is generated
636 # without the '--width' option passed to pango-view.
637 height = self._get_svg_height(multi_line_file)
638 line_height = self._get_svg_height(one_line_file)
639 return int(round(height / line_height))
640
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800641 def convert_svg_to_png(self, svg_file, png_file, height, num_lines,
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800642 background):
643 """Converts .svg file to .png file."""
644 background_hex = ''.join(format(x, '02x') for x in background)
645 # If the width/height of the SVG file is specified in points, the
646 # rsvg-convert command with default 90DPI will potentially cause the pixels
647 # at the right/bottom border of the output image to be transparent (or
648 # filled with the specified background color). This seems like an
649 # rsvg-convert issue regarding image scaling. Therefore, use 72DPI here
650 # to avoid the scaling.
651 command = ['rsvg-convert',
652 '--background-color', "'#%s'" % background_hex,
653 '--dpi-x', '72',
654 '--dpi-y', '72',
655 '-o', png_file]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800656 if height:
657 height_px = int(self.canvas_px * height / self.SCALE_BASE) * num_lines
658 command.extend(['--height', '%d' % height_px])
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800659 command.append(svg_file)
660 subprocess.check_call(' '.join(command), shell=True)
661
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800662 def convert_to_bitmap(self, input_file, height, num_lines, background, output,
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800663 max_colors):
664 """Converts an image file `input_file` to a BMP file `output`."""
665 image = Image.open(input_file)
666
667 # Process alpha channel and transparency.
668 if image.mode == 'RGBA':
669 target = Image.new('RGB', image.size, background)
670 image.load() # required for image.split()
671 mask = image.split()[-1]
672 target.paste(image, mask=mask)
673 elif (image.mode == 'P') and ('transparency' in image.info):
674 exit('Sorry, PNG with RGBA palette is not supported.')
675 elif image.mode != 'RGB':
676 target = image.convert('RGB')
677 else:
678 target = image
679
680 # Process scaling
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800681 if height:
682 new_size = self.calculate_dimension(image.size, (0, height), num_lines)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800683 if new_size[0] == 0 or new_size[1] == 0:
684 print('Scaling', input_file)
685 print('Warning: width or height is 0 after resizing: '
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800686 'height=%d size=%s stretch=%s new_size=%s' %
687 (height, image.size, self.stretch, new_size))
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800688 return
689 target = target.resize(new_size, Image.BICUBIC)
690
691 # Export and downsample color space.
692 target.convert('P', dither=None, colors=max_colors, palette=Image.ADAPTIVE
693 ).save(output)
694
695 with open(output, 'rb+') as f:
696 f.seek(BMP_HEADER_OFFSET_NUM_LINES)
697 f.write(bytearray([num_lines]))
698
Yu-Ping Wued95df32020-11-04 17:08:15 +0800699 def convert(self, files, output_dir, heights, max_widths, max_colors,
700 one_line_dir=None):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800701 """Converts file(s) to bitmap format."""
702 if not files:
703 raise BuildImageError('Unable to find file(s) to convert')
704
705 for file in files:
706 name, ext = os.path.splitext(os.path.basename(file))
707 output = os.path.join(output_dir, name + self.DEFAULT_OUTPUT_EXT)
708
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800709 if name in self.replace_map:
710 name = self.replace_map[name]
711 if not name:
712 continue
713 print('Replace: %s => %s' % (file, name))
714 file = os.path.join(os.path.dirname(file), name + ext)
715
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800716 background = self.BACKGROUND_COLORS.get(name, self.DEFAULT_BACKGROUND)
717 height = heights[name]
Yu-Ping Wued95df32020-11-04 17:08:15 +0800718 max_width = max_widths[name]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800719
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800720 # Determine num_lines in order to scale the image
Yu-Ping Wued95df32020-11-04 17:08:15 +0800721 if one_line_dir and max_width:
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800722 num_lines = self.get_num_lines(file, one_line_dir)
723 else:
724 num_lines = 1
725
726 if ext == '.svg':
727 png_file = os.path.join(self.temp_dir, name + '.png')
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800728 self.convert_svg_to_png(file, png_file, height, num_lines, background)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800729 file = png_file
730
731 self.convert_to_bitmap(
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800732 file, height, num_lines, background, output, max_colors)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800733
734 def convert_assets(self):
735 """Converts images in assets folder."""
736 files = []
737 files.extend(glob.glob(os.path.join(self.ASSET_DIR, SVG_FILES)))
738 files.extend(glob.glob(os.path.join(self.ASSET_DIR, PNG_FILES)))
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800739 heights = defaultdict(lambda: self.DEFAULT_ASSET_HEIGHT)
740 heights.update(self.ASSET_HEIGHTS)
Yu-Ping Wued95df32020-11-04 17:08:15 +0800741 max_widths = defaultdict(lambda: None)
742 self.convert(files, self.output_dir, heights, max_widths,
743 self.ASSET_MAX_COLORS)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800744
745 def convert_generic_strings(self):
746 """Converts generic (locale-independent) strings."""
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800747 names = self.formats[KEY_GENERIC_FILES]
748 styles = self.formats[KEY_STYLES]
749 heights = {}
Yu-Ping Wued95df32020-11-04 17:08:15 +0800750 max_widths = {}
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800751 for name, category in names.items():
752 style = get_config_with_defaults(styles, category)
753 heights[name] = style[KEY_HEIGHT]
Yu-Ping Wued95df32020-11-04 17:08:15 +0800754 max_widths[name] = style[KEY_MAX_WIDTH]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800755
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800756 files = glob.glob(os.path.join(self.stage_dir, SVG_FILES))
Yu-Ping Wued95df32020-11-04 17:08:15 +0800757 self.convert(files, self.output_dir, heights, max_widths,
758 self.text_max_colors)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800759
760 def convert_localized_strings(self):
761 """Converts localized strings."""
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800762 names = self.formats[KEY_LOCALIZED_FILES].copy()
763 if DIAGNOSTIC_UI:
764 names.update(self.formats[DIAGNOSTIC_FILES])
765 styles = self.formats[KEY_STYLES]
766 heights = {}
Yu-Ping Wued95df32020-11-04 17:08:15 +0800767 max_widths = {}
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800768 for name, category in names.items():
769 style = get_config_with_defaults(styles, category)
770 heights[name] = style[KEY_HEIGHT]
Yu-Ping Wued95df32020-11-04 17:08:15 +0800771 max_widths[name] = style[KEY_MAX_WIDTH]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800772
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800773 # Using stderr to report progress synchronously
774 print(' processing:', end='', file=sys.stderr, flush=True)
775 for locale_info in self.locales:
776 locale = locale_info.code
777 ro_locale_dir = os.path.join(self.output_ro_dir, locale)
778 stage_locale_dir = os.path.join(STAGE_LOCALE_DIR, locale)
Yu-Ping Wuabb9afb2020-10-27 17:15:22 +0800779 print(' ' + locale, end='', file=sys.stderr, flush=True)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800780 os.makedirs(ro_locale_dir)
781 self.convert(
782 glob.glob(os.path.join(stage_locale_dir, SVG_FILES)),
Yu-Ping Wued95df32020-11-04 17:08:15 +0800783 ro_locale_dir, heights, max_widths, self.text_max_colors,
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800784 one_line_dir=os.path.join(stage_locale_dir, ONE_LINE_DIR))
785 print(file=sys.stderr)
786
787 def move_language_images(self):
788 """Renames language bitmaps and move to self.output_dir.
789
790 The directory self.output_dir contains locale-independent images, and is
791 used for creating vbgfx.bin by archive_images.py.
792 """
793 for locale_info in self.locales:
794 locale = locale_info.code
795 ro_locale_dir = os.path.join(self.output_ro_dir, locale)
796 old_file = os.path.join(ro_locale_dir, 'language.bmp')
797 new_file = os.path.join(self.output_dir, 'language_%s.bmp' % locale)
798 if os.path.exists(new_file):
799 raise BuildImageError('File already exists: %s' % new_file)
800 shutil.move(old_file, new_file)
801
802 def convert_fonts(self):
803 """Converts font images"""
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800804 heights = defaultdict(lambda: self.DEFAULT_FONT_HEIGHT)
Yu-Ping Wued95df32020-11-04 17:08:15 +0800805 max_widths = defaultdict(lambda: None)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800806 files = glob.glob(os.path.join(STAGE_FONT_DIR, SVG_FILES))
807 font_output_dir = os.path.join(self.output_dir, 'font')
808 os.makedirs(font_output_dir)
Yu-Ping Wued95df32020-11-04 17:08:15 +0800809 self.convert(files, font_output_dir, heights, max_widths,
810 self.text_max_colors)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800811
812 def copy_images_to_rw(self):
813 """Copies localized images specified in boards.yaml for RW override."""
814 if not self.config[RW_OVERRIDE_KEY]:
815 print(' No localized images are specified for RW, skipping')
816 return
817
818 for locale_info in self.locales:
819 locale = locale_info.code
820 rw_locale_dir = os.path.join(self.output_ro_dir, locale)
821 ro_locale_dir = os.path.join(self.output_rw_dir, locale)
822 os.makedirs(rw_locale_dir)
823
824 for name in self.config[RW_OVERRIDE_KEY]:
825 ro_src = os.path.join(ro_locale_dir, name + self.DEFAULT_OUTPUT_EXT)
826 rw_dst = os.path.join(rw_locale_dir, name + self.DEFAULT_OUTPUT_EXT)
827 shutil.copyfile(ro_src, rw_dst)
828
829 def create_locale_list(self):
830 """Creates locale list as a CSV file.
831
832 Each line in the file is of format "code,rtl", where
833 - "code": language code of the locale
834 - "rtl": "1" for right-to-left language, "0" otherwise
835 """
836 with open(os.path.join(self.output_dir, 'locales'), 'w') as f:
837 for locale_info in self.locales:
838 f.write('{},{}\n'.format(locale_info.code,
839 int(locale_info.rtl)))
840
841 def build(self):
842 """Builds all images required by a board."""
843 # Clean up output directory
844 if os.path.exists(self.output_dir):
845 shutil.rmtree(self.output_dir)
846 os.makedirs(self.output_dir)
847
848 if not os.path.exists(self.stage_dir):
849 raise BuildImageError('Missing stage folder. Run make in strings dir.')
850
851 # Clean up temp directory
852 if os.path.exists(self.temp_dir):
853 shutil.rmtree(self.temp_dir)
854 os.makedirs(self.temp_dir)
855
856 print('Converting asset images...')
857 self.convert_assets()
858
859 print('Converting generic strings...')
860 self.convert_generic_strings()
861
862 print('Converting localized strings...')
863 self.convert_localized_strings()
864
865 print('Moving language images to locale-independent directory...')
866 self.move_language_images()
867
868 print('Creating locale list file...')
869 self.create_locale_list()
870
871 print('Converting fonts...')
872 self.convert_fonts()
873
874 print('Copying specified images to RW packing directory...')
875 self.copy_images_to_rw()
876
877
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800878def build_images(board, formats):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800879 """Builds images for `board`."""
880 configs = load_boards_config(BOARDS_CONFIG_FILE)
881 print('Building for ' + board)
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800882 converter = Converter(board, formats, configs[board], OUTPUT_DIR)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800883 converter.build()
884
885
886def main():
887 """Builds bitmaps for firmware screens."""
888 parser = argparse.ArgumentParser()
889 parser.add_argument('board', help='Target board')
890 args = parser.parse_args()
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800891
892 with open(FORMAT_FILE, encoding='utf-8') as f:
893 formats = yaml.load(f)
894 build_strings(formats)
895 build_images(args.board, formats)
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800896
897
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800898if __name__ == '__main__':
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800899 main()