blob: 087f3796a9082d4b8bf028a609156fb5546b5449 [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
Yu-Ping Wue445e042020-11-19 15:53:42 +080010import fractions
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080011import glob
Jes Klinke1687a992020-06-16 13:47:17 -070012import json
Hung-Te Lin04addcc2015-03-23 18:43:30 +080013import multiprocessing
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080014import os
15import re
Jes Klinke1687a992020-06-16 13:47:17 -070016import shutil
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080017import signal
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080018import subprocess
19import sys
Jes Klinke1687a992020-06-16 13:47:17 -070020import tempfile
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080021from xml.etree import ElementTree
Hung-Te Lin04addcc2015-03-23 18:43:30 +080022
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080023import yaml
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080024from PIL import Image
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080025
26SCRIPT_BASE = os.path.dirname(os.path.abspath(__file__))
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080027
28STRINGS_GRD_FILE = 'firmware_strings.grd'
29STRINGS_JSON_FILE_TMPL = '{}.json'
30FORMAT_FILE = 'format.yaml'
31BOARDS_CONFIG_FILE = 'boards.yaml'
32
33TXT_TO_PNG_SVG = os.path.join(SCRIPT_BASE, 'text_to_png_svg')
34STRINGS_DIR = os.path.join(SCRIPT_BASE, 'strings')
35LOCALE_DIR = os.path.join(STRINGS_DIR, 'locale')
36OUTPUT_DIR = os.getenv('OUTPUT', os.path.join(SCRIPT_BASE, 'build'))
37STAGE_DIR = os.path.join(OUTPUT_DIR, '.stage')
38STAGE_LOCALE_DIR = os.path.join(STAGE_DIR, 'locale')
39STAGE_FONT_DIR = os.path.join(STAGE_DIR, 'font')
40
41ONE_LINE_DIR = 'one_line'
42SVG_FILES = '*.svg'
43PNG_FILES = '*.png'
44
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +080045DIAGNOSTIC_UI = os.getenv('DIAGNOSTIC_UI') == '1'
46
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080047# String format YAML key names.
Yu-Ping Wu177f12c2020-11-04 15:55:37 +080048KEY_DEFAULT = '_DEFAULT_'
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080049KEY_LOCALES = 'locales'
Yu-Ping Wu338f0832020-10-23 16:14:40 +080050KEY_GENERIC_FILES = 'generic_files'
51KEY_LOCALIZED_FILES = 'localized_files'
Yu-Ping Wu177f12c2020-11-04 15:55:37 +080052KEY_DIAGNOSTIC_FILES = 'diagnostic_files'
53KEY_SPRITE_FILES = 'sprite_files'
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080054KEY_STYLES = 'styles'
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +080055KEY_BGCOLOR = 'bgcolor'
56KEY_FGCOLOR = 'fgcolor'
57KEY_HEIGHT = 'height'
Yu-Ping Wued95df32020-11-04 17:08:15 +080058KEY_MAX_WIDTH = 'max_width'
Yu-Ping Wu177f12c2020-11-04 15:55:37 +080059KEY_FONTS = 'fonts'
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080060
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080061# Board config YAML key names.
62SCREEN_KEY = 'screen'
63PANEL_KEY = 'panel'
64SDCARD_KEY = 'sdcard'
65BAD_USB3_KEY = 'bad_usb3'
66LOCALES_KEY = 'locales'
67RTL_KEY = 'rtl'
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080068TEXT_COLORS_KEY = 'text_colors'
69RW_OVERRIDE_KEY = 'rw_override'
70
71BMP_HEADER_OFFSET_NUM_LINES = 6
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080072
Jes Klinke1687a992020-06-16 13:47:17 -070073# Regular expressions used to eliminate spurious spaces and newlines in
74# translation strings.
75NEWLINE_PATTERN = re.compile(r'([^\n])\n([^\n])')
76NEWLINE_REPLACEMENT = r'\1 \2'
77CRLF_PATTERN = re.compile(r'\r\n')
78MULTIBLANK_PATTERN = re.compile(r' *')
79
Yu-Ping Wu11027f02020-10-14 17:35:42 +080080GLYPH_FONT = 'Noto Sans Mono'
81
Yu-Ping Wuabb9afb2020-10-27 17:15:22 +080082LocaleInfo = namedtuple('LocaleInfo', ['code', 'rtl'])
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080083
Yu-Ping Wu6b282c52020-03-19 12:54:15 +080084
Hung-Te Lin707e2ef2013-08-06 10:20:04 +080085class DataError(Exception):
86 pass
87
88
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +080089class BuildImageError(Exception):
90 """The exception class for all errors generated during build image process."""
91
92
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +080093def get_config_with_defaults(configs, key):
94 """Gets config of `key` from `configs`.
95
96 If `key` is not present in `configs`, the default config will be returned.
97 Similarly, if some config values are missing for `key`, the default ones will
98 be used.
99 """
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800100 config = configs[KEY_DEFAULT].copy()
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800101 config.update(configs.get(key, {}))
102 return config
103
104
Yu-Ping Wued95df32020-11-04 17:08:15 +0800105def convert_text_to_png(locale, input_file, font, output_dir, height=None,
106 max_width=None, margin='0', bgcolor='#000000',
107 fgcolor='#ffffff', **options):
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800108 """Converts text files into PNG image files.
109
110 Args:
111 locale: Locale (language) to select implicit rendering options. None for
112 locale-independent strings.
113 input_file: Path of input text file.
114 font: Font spec.
Yu-Ping Wued95df32020-11-04 17:08:15 +0800115 height: Height.
116 max_width: Maximum width.
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800117 margin: CSS-style margin.
118 output_dir: Directory to generate image files.
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800119 bgcolor: Background color (#rrggbb).
120 fgcolor: Foreground color (#rrggbb).
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800121 **options: Other options to be added.
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800122 """
123 name, _ = os.path.splitext(os.path.basename(input_file))
124 command = [TXT_TO_PNG_SVG, '--outdir=%s' % output_dir]
125 if locale:
126 command.append('--lan=%s' % locale)
127 if font:
128 command.append("--font='%s'" % font)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800129 font_size = os.getenv('FONT_SIZE')
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800130 if font_size:
131 command.append('--point=%r' % font_size)
Yu-Ping Wued95df32020-11-04 17:08:15 +0800132 if max_width:
133 # Without the --width option set, the minimum height of the output SVG
134 # image is roughly 22px (for locale 'en'). With --width=WIDTH passed to
135 # pango-view, the width of the output seems to always be (WIDTH * 4 / 3),
136 # regardless of the font being used. Therefore, set the max_width in
137 # points as follows to prevent drawing from exceeding canvas boundary in
138 # depthcharge runtime.
139 max_width_pt = int(22 * max_width / height / (4 / 3))
140 command.append('--width=%d' % max_width_pt)
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800141 if margin:
142 command.append('--margin="%s"' % margin)
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800143 command.append('--bgcolor="%s"' % bgcolor)
144 command.append('--color="%s"' % fgcolor)
145
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800146 for k, v in options.items():
147 command.append('--%s="%s"' % (k, v))
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800148 command.append(input_file)
149
150 return subprocess.call(' '.join(command), shell=True,
151 stdout=subprocess.PIPE) == 0
152
153
154def convert_glyphs():
155 """Converts glyphs of ascii characters."""
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800156 os.makedirs(STAGE_FONT_DIR, exist_ok=True)
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800157 # Remove the extra whitespace at the top/bottom within the glyphs
158 margin = '-3 0 -1 0'
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800159 for c in range(ord(' '), ord('~') + 1):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800160 txt_file = os.path.join(STAGE_FONT_DIR, f'idx{c:03d}_{c:02x}.txt')
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800161 with open(txt_file, 'w', encoding='ascii') as f:
162 f.write(chr(c))
163 f.write('\n')
164 # TODO(b/163109632): Parallelize the conversion of glyphs
Yu-Ping Wued95df32020-11-04 17:08:15 +0800165 convert_text_to_png(None, txt_file, GLYPH_FONT, STAGE_FONT_DIR,
166 margin=margin)
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800167
168
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800169def _load_locale_json_file(locale, json_dir):
Jes Klinke1687a992020-06-16 13:47:17 -0700170 result = {}
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800171 filename = os.path.join(json_dir, STRINGS_JSON_FILE_TMPL.format(locale))
Yu-Ping Wud71b4452020-06-16 11:00:26 +0800172 with open(filename, encoding='utf-8-sig') as input_file:
Jes Klinke1687a992020-06-16 13:47:17 -0700173 for tag, msgdict in json.load(input_file).items():
174 msgtext = msgdict['message']
175 msgtext = re.sub(CRLF_PATTERN, '\n', msgtext)
176 msgtext = re.sub(NEWLINE_PATTERN, NEWLINE_REPLACEMENT, msgtext)
177 msgtext = re.sub(MULTIBLANK_PATTERN, ' ', msgtext)
178 # Strip any trailing whitespace. A trailing newline appears to make
179 # Pango report a larger layout size than what's actually visible.
180 msgtext = msgtext.strip()
181 result[tag] = msgtext
182 return result
183
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800184
185def parse_locale_json_file(locale, json_dir):
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800186 """Parses given firmware string json file.
Mathew King89d48c62019-02-15 10:08:39 -0700187
188 Args:
Yu-Ping Wu8f633b82020-09-22 14:27:57 +0800189 locale: The name of the locale, e.g. "da" or "pt-BR".
Jes Klinke1687a992020-06-16 13:47:17 -0700190 json_dir: Directory containing json output from grit.
Mathew King89d48c62019-02-15 10:08:39 -0700191
192 Returns:
193 A dictionary for mapping of "name to content" for files to be generated.
194 """
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800195 result = _load_locale_json_file(locale, json_dir)
196 original = _load_locale_json_file('en', json_dir)
197 for tag in original:
198 if tag not in result:
199 # Use original English text, in case translation is not yet available
200 print('WARNING: locale "%s", missing entry %s' % (locale, tag))
201 result[tag] = original[tag]
Mathew King89d48c62019-02-15 10:08:39 -0700202
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800203 return result
Mathew King89d48c62019-02-15 10:08:39 -0700204
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800205
206def parse_locale_input_files(locale, json_dir):
207 """Parses all firmware string files for the given locale.
208
209 Args:
210 locale: The name of the locale, e.g. "da" or "pt-BR".
211 json_dir: Directory containing json output from grit.
212
213 Returns:
214 A dictionary for mapping of "name to content" for files to be generated.
215 """
216 result = parse_locale_json_file(locale, json_dir)
217
218 # Walk locale directory to add pre-generated texts such as language names.
Yu-Ping Wu8f633b82020-09-22 14:27:57 +0800219 for input_file in glob.glob(os.path.join(LOCALE_DIR, locale, "*.txt")):
Mathew King89d48c62019-02-15 10:08:39 -0700220 name, _ = os.path.splitext(os.path.basename(input_file))
Yu-Ping Wud71b4452020-06-16 11:00:26 +0800221 with open(input_file, 'r', encoding='utf-8-sig') as f:
Mathew King89d48c62019-02-15 10:08:39 -0700222 result[name] = f.read().strip()
Shelley Chen2f616ac2017-05-22 13:19:40 -0700223
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800224 return result
225
226
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800227def build_text_files(inputs, files, output_dir):
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800228 """Builds text files from given input data.
229
230 Args:
231 inputs: Dictionary of contents for given file name.
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800232 files: List of files.
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800233 output_dir: Directory to generate text files.
234 """
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800235 for name in files:
236 file_name = os.path.join(output_dir, name + '.txt')
237 with open(file_name, 'w', encoding='utf-8-sig') as f:
238 f.write(inputs[name] + '\n')
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800239
240
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800241def convert_localized_strings(formats):
242 """Converts localized strings."""
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800243 # Make a copy of formats to avoid modifying it
244 formats = copy.deepcopy(formats)
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800245
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800246 env_locales = os.getenv('LOCALES')
247 if env_locales:
248 locales = env_locales.split()
249 else:
250 locales = formats[KEY_LOCALES]
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800251
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800252 files = formats[KEY_LOCALIZED_FILES]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800253 if DIAGNOSTIC_UI:
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800254 files.update(formats[KEY_DIAGNOSTIC_FILES])
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800255
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800256 styles = formats[KEY_STYLES]
257 fonts = formats[KEY_FONTS]
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800258 default_font = fonts[KEY_DEFAULT]
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800259
Yu-Ping Wu51940352020-09-17 08:48:55 +0800260 # Sources are one .grd file with identifiers chosen by engineers and
261 # corresponding English texts, as well as a set of .xlt files (one for each
262 # language other than US english) with a mapping from hash to translation.
263 # Because the keys in the xlt files are a hash of the English source text,
264 # rather than our identifiers, such as "btn_cancel", we use the "grit"
265 # command line tool to process the .grd and .xlt files, producing a set of
266 # .json files mapping our identifier to the translated string, one for every
267 # language including US English.
Jes Klinke1687a992020-06-16 13:47:17 -0700268
Yu-Ping Wu51940352020-09-17 08:48:55 +0800269 # Create a temporary directory to place the translation output from grit in.
270 json_dir = tempfile.mkdtemp()
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800271
Yu-Ping Wu51940352020-09-17 08:48:55 +0800272 # This invokes the grit build command to generate JSON files from the XTB
273 # files containing translations. The results are placed in `json_dir` as
274 # specified in firmware_strings.grd, i.e. one JSON file per locale.
275 subprocess.check_call([
276 'grit',
Yu-Ping Wu8f633b82020-09-22 14:27:57 +0800277 '-i', os.path.join(LOCALE_DIR, STRINGS_GRD_FILE),
Yu-Ping Wu51940352020-09-17 08:48:55 +0800278 'build',
279 '-o', os.path.join(json_dir)
280 ])
Jes Klinke1687a992020-06-16 13:47:17 -0700281
Yu-Ping Wuc90a22f2020-04-24 11:17:15 +0800282 # Ignore SIGINT in child processes
283 sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
Hung-Te Lin04addcc2015-03-23 18:43:30 +0800284 pool = multiprocessing.Pool(multiprocessing.cpu_count())
Yu-Ping Wuc90a22f2020-04-24 11:17:15 +0800285 signal.signal(signal.SIGINT, sigint_handler)
286
Hung-Te Lin04addcc2015-03-23 18:43:30 +0800287 results = []
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800288 for locale in locales:
Yu-Ping Wud71b4452020-06-16 11:00:26 +0800289 print(locale, end=' ', flush=True)
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800290 inputs = parse_locale_input_files(locale, json_dir)
291 output_dir = os.path.normpath(os.path.join(STAGE_DIR, 'locale', locale))
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800292 if not os.path.exists(output_dir):
293 os.makedirs(output_dir)
Matt Delco4c5580d2019-03-07 14:00:28 -0800294
Yu-Ping Wuae79af62020-09-23 16:48:06 +0800295 build_text_files(inputs, files, output_dir)
Shelley Chen2f616ac2017-05-22 13:19:40 -0700296
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800297 for name, category in files.items():
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800298 style = get_config_with_defaults(styles, category)
299 args = (
300 locale,
301 os.path.join(output_dir, '%s.txt' % name),
302 fonts.get(locale, default_font),
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800303 output_dir,
304 )
305 kwargs = {
Yu-Ping Wued95df32020-11-04 17:08:15 +0800306 'height': style[KEY_HEIGHT],
307 'max_width': style[KEY_MAX_WIDTH],
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800308 'bgcolor': style[KEY_BGCOLOR],
309 'fgcolor': style[KEY_FGCOLOR],
310 }
311 results.append(pool.apply_async(convert_text_to_png, args, kwargs))
Hung-Te Lin04addcc2015-03-23 18:43:30 +0800312 pool.close()
Jes Klinke1687a992020-06-16 13:47:17 -0700313 if json_dir is not None:
314 shutil.rmtree(json_dir)
Yu-Ping Wud71b4452020-06-16 11:00:26 +0800315 print()
Yu-Ping Wuc90a22f2020-04-24 11:17:15 +0800316
317 try:
318 success = [r.get() for r in results]
319 except KeyboardInterrupt:
320 pool.terminate()
321 pool.join()
322 exit('Aborted by user')
323 else:
324 pool.join()
325 if not all(success):
326 exit('Failed to render some locales')
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800327
328
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800329def build_strings(formats):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800330 """Builds text strings."""
Yu-Ping Wu11027f02020-10-14 17:35:42 +0800331 # Convert glyphs
332 print('Converting glyphs...')
333 convert_glyphs()
334
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800335 # Convert generic (locale-independent) strings
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800336 files = formats[KEY_GENERIC_FILES]
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800337 styles = formats[KEY_STYLES]
338 fonts = formats[KEY_FONTS]
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800339 default_font = fonts[KEY_DEFAULT]
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800340
341 for input_file in glob.glob(os.path.join(STRINGS_DIR, '*.txt')):
342 name, _ = os.path.splitext(os.path.basename(input_file))
Yu-Ping Wu338f0832020-10-23 16:14:40 +0800343 category = files[name]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800344 style = get_config_with_defaults(styles, category)
Yu-Ping Wued95df32020-11-04 17:08:15 +0800345 if not convert_text_to_png(None, input_file, default_font, STAGE_DIR,
346 height=style[KEY_HEIGHT],
347 max_width=style[KEY_MAX_WIDTH],
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800348 bgcolor=style[KEY_BGCOLOR],
349 fgcolor=style[KEY_FGCOLOR]):
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800350 exit('Failed to convert text %s' % input_file)
351
352 # Convert localized strings
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800353 convert_localized_strings(formats)
354
355
356def load_boards_config(filename):
357 """Loads the configuration of all boards from `filename`.
358
359 Args:
360 filename: File name of a YAML config file.
361
362 Returns:
363 A dictionary mapping each board name to its config.
364 """
365 with open(filename, 'rb') as file:
366 raw = yaml.load(file)
367
368 configs = {}
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800369 default = raw[KEY_DEFAULT]
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800370 if not default:
371 raise BuildImageError('Default configuration is not found')
372 for boards, params in raw.items():
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800373 if boards == KEY_DEFAULT:
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800374 continue
375 config = copy.deepcopy(default)
376 if params:
377 config.update(params)
378 for board in boards.replace(',', ' ').split():
379 configs[board] = config
380
381 return configs
382
383
384class Converter(object):
385 """Converter from assets, texts, URLs, and fonts to bitmap images.
386
387 Attributes:
388 ASSET_DIR (str): Directory of image assets.
389 DEFAULT_OUTPUT_EXT (str): Default output file extension.
390 DEFAULT_REPLACE_MAP (dict): Default mapping of file replacement. For
391 {'a': 'b'}, "a.*" will be converted to "b.*".
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800392 SCALE_BASE (int): The base for bitmap scales, same as UI_SCALE in
393 depthcharge. For example, if `SCALE_BASE` is 1000, then height = 200 means
394 20% of the screen height. Also see the 'styles' section in format.yaml.
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800395 DEFAULT_FONT_HEIGHT (tuple): Height of the font images.
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
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800422 SCALE_BASE = 1000
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800423 DEFAULT_FONT_HEIGHT = 20
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800424
425 # background colors
426 DEFAULT_BACKGROUND = (0x20, 0x21, 0x24)
427 LANG_HEADER_BACKGROUND = (0x16, 0x17, 0x19)
428 LINK_SELECTED_BACKGROUND = (0x2a, 0x2f, 0x39)
429 ASSET_MAX_COLORS = 128
430
431 BACKGROUND_COLORS = {
432 'ic_dropdown': LANG_HEADER_BACKGROUND,
433 'ic_dropleft_focus': LINK_SELECTED_BACKGROUND,
434 'ic_dropright_focus': LINK_SELECTED_BACKGROUND,
435 'ic_globe': LANG_HEADER_BACKGROUND,
436 'ic_search_focus': LINK_SELECTED_BACKGROUND,
437 'ic_settings_focus': LINK_SELECTED_BACKGROUND,
438 'ic_power_focus': LINK_SELECTED_BACKGROUND,
439 }
440
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800441 def __init__(self, board, formats, board_config, output):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800442 """Inits converter.
443
444 Args:
445 board: Board name.
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800446 formats: A dictionary of string formats.
447 board_config: A dictionary of board configurations.
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800448 output: Output directory.
449 """
450 self.board = board
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800451 self.formats = formats
452 self.config = board_config
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800453 self.set_dirs(output)
454 self.set_screen()
455 self.set_replace_map()
456 self.set_locales()
457 self.text_max_colors = self.config[TEXT_COLORS_KEY]
458
459 def set_dirs(self, output):
460 """Sets board output directory and stage directory.
461
462 Args:
463 output: Output directory.
464 """
465 self.output_dir = os.path.join(output, self.board)
466 self.output_ro_dir = os.path.join(self.output_dir, 'locale', 'ro')
467 self.output_rw_dir = os.path.join(self.output_dir, 'locale', 'rw')
468 self.stage_dir = os.path.join(output, '.stage')
469 self.temp_dir = os.path.join(self.stage_dir, 'tmp')
470
471 def set_screen(self):
472 """Sets screen width and height."""
473 self.screen_width, self.screen_height = self.config[SCREEN_KEY]
474
Yu-Ping Wue445e042020-11-19 15:53:42 +0800475 self.panel_stretch = fractions.Fraction(1)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800476 if self.config[PANEL_KEY]:
Yu-Ping Wue445e042020-11-19 15:53:42 +0800477 # Calculate `panel_stretch`. It's used to shrink images horizontally so
478 # that the resulting images will look proportional to the original image
479 # on the stretched display. If the display is not stretched, meaning the
480 # aspect ratio is same as the screen where images were rendered, no
481 # shrinking is performed.
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800482 panel_width, panel_height = self.config[PANEL_KEY]
Yu-Ping Wue445e042020-11-19 15:53:42 +0800483 self.panel_stretch = fractions.Fraction(self.screen_width * panel_height,
484 self.screen_height * panel_width)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800485
Yu-Ping Wue445e042020-11-19 15:53:42 +0800486 if self.panel_stretch > 1:
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800487 raise BuildImageError('Panel aspect ratio (%f) is smaller than screen '
488 'aspect ratio (%f). It indicates screen will be '
489 'shrunk horizontally. It is currently unsupported.'
490 % (panel_width / panel_height,
491 self.screen_width / self.screen_height))
492
493 # Set up square drawing area
494 self.canvas_px = min(self.screen_width, self.screen_height)
495
496 def set_replace_map(self):
497 """Sets a map replacing images.
498
499 For each (key, value), image 'key' will be replaced by image 'value'.
500 """
501 replace_map = self.DEFAULT_REPLACE_MAP.copy()
502
503 if os.getenv('DETACHABLE') == '1':
504 replace_map.update({
505 'nav-key_enter': 'nav-button_power',
506 'nav-key_up': 'nav-button_volume_up',
507 'nav-key_down': 'nav-button_volume_down',
508 'navigate0': 'navigate0_tablet',
509 'navigate1': 'navigate1_tablet',
510 'broken_desc': 'broken_desc_detach',
511 })
512
513 physical_presence = os.getenv('PHYSICAL_PRESENCE')
514 if physical_presence == 'recovery':
515 replace_map['rec_to_dev_desc1'] = 'rec_to_dev_desc1_phyrec'
516 replace_map['broken_desc'] = 'broken_desc_phyrec'
517 elif physical_presence == 'power':
518 replace_map['rec_to_dev_desc1'] = 'rec_to_dev_desc1_power'
519 elif physical_presence != 'keyboard':
520 raise BuildImageError('Invalid physical presence setting %s for board %s'
521 % (physical_presence, self.board))
522
523 if not self.config[SDCARD_KEY]:
524 replace_map.update({
525 'rec_sel_desc1': 'rec_sel_desc1_no_sd',
526 'rec_sel_desc1_no_phone': 'rec_sel_desc1_no_phone_no_sd',
527 'rec_disk_step1_desc0': 'rec_disk_step1_desc0_no_sd',
528 })
529
530 self.replace_map = replace_map
531
532 def set_locales(self):
533 """Sets a list of locales for which localized images are converted."""
534 # LOCALES environment variable can overwrite boards.yaml
535 env_locales = os.getenv('LOCALES')
536 rtl_locales = set(self.config[RTL_KEY])
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800537 if env_locales:
538 locales = env_locales.split()
539 else:
540 locales = self.config[LOCALES_KEY]
541 # Check rtl_locales are contained in locales.
542 unknown_rtl_locales = rtl_locales - set(locales)
543 if unknown_rtl_locales:
544 raise BuildImageError('Unknown locales %s in %s' %
545 (list(unknown_rtl_locales), RTL_KEY))
Yu-Ping Wuabb9afb2020-10-27 17:15:22 +0800546 self.locales = [LocaleInfo(code, code in rtl_locales)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800547 for code in locales]
548
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800549 def _get_svg_height(self, svg_file):
550 tree = ElementTree.parse(svg_file)
551 height = tree.getroot().attrib['height']
552 m = re.match('([0-9]+)pt', height)
553 if not m:
554 raise BuildImageError('Cannot get height from %s' % svg_file)
555 return int(m.group(1))
556
557 def get_num_lines(self, file, one_line_dir):
558 """Gets the number of lines of text in `file`."""
559 name, _ = os.path.splitext(os.path.basename(file))
560 svg_name = name + '.svg'
561 multi_line_file = os.path.join(os.path.dirname(file), svg_name)
562 one_line_file = os.path.join(one_line_dir, svg_name)
563 # The number of lines id determined by comparing the height of
564 # `multi_line_file` with `one_line_file`, where the latter is generated
565 # without the '--width' option passed to pango-view.
566 height = self._get_svg_height(multi_line_file)
567 line_height = self._get_svg_height(one_line_file)
568 return int(round(height / line_height))
569
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800570 def convert_svg_to_png(self, svg_file, png_file, height, num_lines,
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800571 background):
572 """Converts .svg file to .png file."""
573 background_hex = ''.join(format(x, '02x') for x in background)
574 # If the width/height of the SVG file is specified in points, the
575 # rsvg-convert command with default 90DPI will potentially cause the pixels
576 # at the right/bottom border of the output image to be transparent (or
577 # filled with the specified background color). This seems like an
578 # rsvg-convert issue regarding image scaling. Therefore, use 72DPI here
579 # to avoid the scaling.
580 command = ['rsvg-convert',
581 '--background-color', "'#%s'" % background_hex,
582 '--dpi-x', '72',
583 '--dpi-y', '72',
584 '-o', png_file]
Yu-Ping Wue445e042020-11-19 15:53:42 +0800585 height_px = int(self.canvas_px * height / self.SCALE_BASE) * num_lines
586 if height_px <= 0:
587 raise BuildImageError('Height of %r <= 0 (%dpx)' %
588 (os.path.basename(svg_file), height_px))
589 command.extend(['--height', '%d' % height_px])
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800590 command.append(svg_file)
591 subprocess.check_call(' '.join(command), shell=True)
592
Yu-Ping Wue445e042020-11-19 15:53:42 +0800593 def convert_to_bitmap(self, input_file, num_lines, background, output,
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800594 max_colors):
595 """Converts an image file `input_file` to a BMP file `output`."""
596 image = Image.open(input_file)
597
598 # Process alpha channel and transparency.
599 if image.mode == 'RGBA':
600 target = Image.new('RGB', image.size, background)
601 image.load() # required for image.split()
602 mask = image.split()[-1]
603 target.paste(image, mask=mask)
604 elif (image.mode == 'P') and ('transparency' in image.info):
605 exit('Sorry, PNG with RGBA palette is not supported.')
606 elif image.mode != 'RGB':
607 target = image.convert('RGB')
608 else:
609 target = image
610
Yu-Ping Wue445e042020-11-19 15:53:42 +0800611 # Stretch image horizontally for stretched display
612 if self.panel_stretch != 1:
613 new_width_px = int(image.size[0] * self.panel_stretch)
614 new_size = (new_width_px, image.size[1])
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800615 target = target.resize(new_size, Image.BICUBIC)
616
617 # Export and downsample color space.
618 target.convert('P', dither=None, colors=max_colors, palette=Image.ADAPTIVE
619 ).save(output)
620
621 with open(output, 'rb+') as f:
622 f.seek(BMP_HEADER_OFFSET_NUM_LINES)
623 f.write(bytearray([num_lines]))
624
Yu-Ping Wued95df32020-11-04 17:08:15 +0800625 def convert(self, files, output_dir, heights, max_widths, max_colors,
626 one_line_dir=None):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800627 """Converts file(s) to bitmap format."""
628 if not files:
629 raise BuildImageError('Unable to find file(s) to convert')
630
631 for file in files:
632 name, ext = os.path.splitext(os.path.basename(file))
633 output = os.path.join(output_dir, name + self.DEFAULT_OUTPUT_EXT)
634
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800635 if name in self.replace_map:
636 name = self.replace_map[name]
637 if not name:
638 continue
639 print('Replace: %s => %s' % (file, name))
640 file = os.path.join(os.path.dirname(file), name + ext)
641
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800642 background = self.BACKGROUND_COLORS.get(name, self.DEFAULT_BACKGROUND)
643 height = heights[name]
Yu-Ping Wued95df32020-11-04 17:08:15 +0800644 max_width = max_widths[name]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800645
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800646 # Determine num_lines in order to scale the image
Yu-Ping Wued95df32020-11-04 17:08:15 +0800647 if one_line_dir and max_width:
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800648 num_lines = self.get_num_lines(file, one_line_dir)
649 else:
650 num_lines = 1
651
652 if ext == '.svg':
653 png_file = os.path.join(self.temp_dir, name + '.png')
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800654 self.convert_svg_to_png(file, png_file, height, num_lines, background)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800655 file = png_file
656
Yu-Ping Wue445e042020-11-19 15:53:42 +0800657 self.convert_to_bitmap(file, num_lines, background, output, max_colors)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800658
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800659 def convert_sprite_images(self):
660 """Converts sprite images."""
661 names = self.formats[KEY_SPRITE_FILES]
662 styles = self.formats[KEY_STYLES]
663 # Check redundant images
664 for filename in glob.glob(os.path.join(self.ASSET_DIR, SVG_FILES)):
665 name, _ = os.path.splitext(os.path.basename(filename))
666 if name not in names:
667 raise BuildImageError('Sprite image %r not specified in %s' %
668 (filename, FORMAT_FILE))
669 # Convert images
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800670 files = []
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800671 heights = {}
672 for name, category in names.items():
673 style = get_config_with_defaults(styles, category)
674 files.append(os.path.join(self.ASSET_DIR, name + '.svg'))
675 heights[name] = style[KEY_HEIGHT]
Yu-Ping Wued95df32020-11-04 17:08:15 +0800676 max_widths = defaultdict(lambda: None)
677 self.convert(files, self.output_dir, heights, max_widths,
678 self.ASSET_MAX_COLORS)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800679
680 def convert_generic_strings(self):
681 """Converts generic (locale-independent) strings."""
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800682 names = self.formats[KEY_GENERIC_FILES]
683 styles = self.formats[KEY_STYLES]
684 heights = {}
Yu-Ping Wued95df32020-11-04 17:08:15 +0800685 max_widths = {}
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800686 for name, category in names.items():
687 style = get_config_with_defaults(styles, category)
688 heights[name] = style[KEY_HEIGHT]
Yu-Ping Wued95df32020-11-04 17:08:15 +0800689 max_widths[name] = style[KEY_MAX_WIDTH]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800690
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800691 files = glob.glob(os.path.join(self.stage_dir, SVG_FILES))
Yu-Ping Wued95df32020-11-04 17:08:15 +0800692 self.convert(files, self.output_dir, heights, max_widths,
693 self.text_max_colors)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800694
695 def convert_localized_strings(self):
696 """Converts localized strings."""
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800697 names = self.formats[KEY_LOCALIZED_FILES].copy()
698 if DIAGNOSTIC_UI:
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800699 names.update(self.formats[KEY_DIAGNOSTIC_FILES])
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800700 styles = self.formats[KEY_STYLES]
701 heights = {}
Yu-Ping Wued95df32020-11-04 17:08:15 +0800702 max_widths = {}
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800703 for name, category in names.items():
704 style = get_config_with_defaults(styles, category)
705 heights[name] = style[KEY_HEIGHT]
Yu-Ping Wued95df32020-11-04 17:08:15 +0800706 max_widths[name] = style[KEY_MAX_WIDTH]
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800707
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800708 # Using stderr to report progress synchronously
709 print(' processing:', end='', file=sys.stderr, flush=True)
710 for locale_info in self.locales:
711 locale = locale_info.code
712 ro_locale_dir = os.path.join(self.output_ro_dir, locale)
713 stage_locale_dir = os.path.join(STAGE_LOCALE_DIR, locale)
Yu-Ping Wuabb9afb2020-10-27 17:15:22 +0800714 print(' ' + locale, end='', file=sys.stderr, flush=True)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800715 os.makedirs(ro_locale_dir)
716 self.convert(
717 glob.glob(os.path.join(stage_locale_dir, SVG_FILES)),
Yu-Ping Wued95df32020-11-04 17:08:15 +0800718 ro_locale_dir, heights, max_widths, self.text_max_colors,
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800719 one_line_dir=os.path.join(stage_locale_dir, ONE_LINE_DIR))
720 print(file=sys.stderr)
721
722 def move_language_images(self):
723 """Renames language bitmaps and move to self.output_dir.
724
725 The directory self.output_dir contains locale-independent images, and is
726 used for creating vbgfx.bin by archive_images.py.
727 """
728 for locale_info in self.locales:
729 locale = locale_info.code
730 ro_locale_dir = os.path.join(self.output_ro_dir, locale)
731 old_file = os.path.join(ro_locale_dir, 'language.bmp')
732 new_file = os.path.join(self.output_dir, 'language_%s.bmp' % locale)
733 if os.path.exists(new_file):
734 raise BuildImageError('File already exists: %s' % new_file)
735 shutil.move(old_file, new_file)
736
737 def convert_fonts(self):
738 """Converts font images"""
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800739 heights = defaultdict(lambda: self.DEFAULT_FONT_HEIGHT)
Yu-Ping Wued95df32020-11-04 17:08:15 +0800740 max_widths = defaultdict(lambda: None)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800741 files = glob.glob(os.path.join(STAGE_FONT_DIR, SVG_FILES))
742 font_output_dir = os.path.join(self.output_dir, 'font')
743 os.makedirs(font_output_dir)
Yu-Ping Wued95df32020-11-04 17:08:15 +0800744 self.convert(files, font_output_dir, heights, max_widths,
745 self.text_max_colors)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800746
747 def copy_images_to_rw(self):
748 """Copies localized images specified in boards.yaml for RW override."""
749 if not self.config[RW_OVERRIDE_KEY]:
750 print(' No localized images are specified for RW, skipping')
751 return
752
753 for locale_info in self.locales:
754 locale = locale_info.code
755 rw_locale_dir = os.path.join(self.output_ro_dir, locale)
756 ro_locale_dir = os.path.join(self.output_rw_dir, locale)
757 os.makedirs(rw_locale_dir)
758
759 for name in self.config[RW_OVERRIDE_KEY]:
760 ro_src = os.path.join(ro_locale_dir, name + self.DEFAULT_OUTPUT_EXT)
761 rw_dst = os.path.join(rw_locale_dir, name + self.DEFAULT_OUTPUT_EXT)
762 shutil.copyfile(ro_src, rw_dst)
763
764 def create_locale_list(self):
765 """Creates locale list as a CSV file.
766
767 Each line in the file is of format "code,rtl", where
768 - "code": language code of the locale
769 - "rtl": "1" for right-to-left language, "0" otherwise
770 """
771 with open(os.path.join(self.output_dir, 'locales'), 'w') as f:
772 for locale_info in self.locales:
773 f.write('{},{}\n'.format(locale_info.code,
774 int(locale_info.rtl)))
775
776 def build(self):
777 """Builds all images required by a board."""
778 # Clean up output directory
779 if os.path.exists(self.output_dir):
780 shutil.rmtree(self.output_dir)
781 os.makedirs(self.output_dir)
782
783 if not os.path.exists(self.stage_dir):
784 raise BuildImageError('Missing stage folder. Run make in strings dir.')
785
786 # Clean up temp directory
787 if os.path.exists(self.temp_dir):
788 shutil.rmtree(self.temp_dir)
789 os.makedirs(self.temp_dir)
790
Yu-Ping Wu177f12c2020-11-04 15:55:37 +0800791 print('Converting sprite images...')
792 self.convert_sprite_images()
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800793
794 print('Converting generic strings...')
795 self.convert_generic_strings()
796
797 print('Converting localized strings...')
798 self.convert_localized_strings()
799
800 print('Moving language images to locale-independent directory...')
801 self.move_language_images()
802
803 print('Creating locale list file...')
804 self.create_locale_list()
805
806 print('Converting fonts...')
807 self.convert_fonts()
808
809 print('Copying specified images to RW packing directory...')
810 self.copy_images_to_rw()
811
812
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800813def build_images(board, formats):
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800814 """Builds images for `board`."""
815 configs = load_boards_config(BOARDS_CONFIG_FILE)
816 print('Building for ' + board)
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800817 converter = Converter(board, formats, configs[board], OUTPUT_DIR)
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800818 converter.build()
819
820
821def main():
822 """Builds bitmaps for firmware screens."""
823 parser = argparse.ArgumentParser()
824 parser.add_argument('board', help='Target board')
825 args = parser.parse_args()
Yu-Ping Wu8c8bfc72020-10-27 16:19:34 +0800826
827 with open(FORMAT_FILE, encoding='utf-8') as f:
828 formats = yaml.load(f)
829 build_strings(formats)
830 build_images(args.board, formats)
Yu-Ping Wu7f6639a2020-09-28 15:31:35 +0800831
832
Hung-Te Lin707e2ef2013-08-06 10:20:04 +0800833if __name__ == '__main__':
Yu-Ping Wu6e4d3892020-10-19 14:09:37 +0800834 main()