diff --git a/Translations/font_tables.py b/Translations/font_tables.py index 94c3b210..a0b64253 100755 --- a/Translations/font_tables.py +++ b/Translations/font_tables.py @@ -989,6 +989,14 @@ NAME_CYRILLIC: Final = "cyrillic" NAME_CJK: Final = "cjk" NAME_GREEK: Final = "greek" +ALL_FONTS = [ + NAME_ASCII_BASIC, + NAME_LATIN_EXTENDED, + NAME_CYRILLIC, + NAME_GREEK, + NAME_CJK, # CJK must come last +] + def get_font_maps_for_name( font_name: str, diff --git a/Translations/make_translation.py b/Translations/make_translation.py index 466679dd..351664ce 100755 --- a/Translations/make_translation.py +++ b/Translations/make_translation.py @@ -356,16 +356,11 @@ class FontMapsPerFont: sym_lists: Dict[str, List[str]] -def get_font_map_per_font(text_list: List[str], fonts: List[str]) -> FontMapsPerFont: +def get_font_map_per_font(text_list: List[str]) -> FontMapsPerFont: pending_sym_set = set(text_list) if len(pending_sym_set) != len(text_list): raise ValueError("`text_list` contains duplicated symbols") - if fonts[0] != font_tables.NAME_ASCII_BASIC: - raise ValueError( - f'First item in `fonts` must be "{font_tables.NAME_ASCII_BASIC}"' - ) - total_symbol_count = len(text_list) # \x00 is for NULL termination and \x01 is for newline, so the maximum # number of symbols allowed is as follow (see also the comments in @@ -381,7 +376,7 @@ def get_font_map_per_font(text_list: List[str], fonts: List[str]) -> FontMapsPer font12_maps: Dict[str, Dict[str, bytes]] = {} font06_maps: Dict[str, Dict[str, Optional[bytes]]] = {} sym_lists: Dict[str, List[str]] = {} - for font in fonts: + for font in font_tables.ALL_FONTS: font12_maps[font] = {} font12_map = font12_maps[font] font06_maps[font] = {} @@ -389,12 +384,6 @@ def get_font_map_per_font(text_list: List[str], fonts: List[str]) -> FontMapsPer sym_lists[font] = [] sym_list = sym_lists[font] - if len(pending_sym_set) == 0: - logging.warning( - f"Font {font} not used because all symbols already have font bitmaps" - ) - continue - if font == font_tables.NAME_CJK: is_cjk = True else: @@ -422,10 +411,8 @@ def get_font_map_per_font(text_list: List[str], fonts: List[str]) -> FontMapsPer sym_list.append(sym) pending_sym_set.remove(sym) - if len(sym_list) == 0: - logging.warning(f"Font {font} not used by any symbols on the list") if len(pending_sym_set) > 0: - raise KeyError(f"Symbols not found in specified fonts: {pending_sym_set}") + raise KeyError(f"Symbols not found in our fonts: {pending_sym_set}") return FontMapsPerFont(font12_maps, font06_maps, sym_lists) @@ -453,16 +440,16 @@ def get_forced_first_symbols() -> List[str]: def get_sym_list_and_font_map( - text_list: List[str], fonts: List[str] + text_list: List[str], ) -> Tuple[List[str], Dict[str, List[str]], FontMap]: - font_maps = get_font_map_per_font(text_list, fonts) + font_maps = get_font_map_per_font(text_list) font12_maps = font_maps.font12_maps font06_maps = font_maps.font06_maps # Build the full font maps font12_map = {} font06_map = {} - for font in fonts: + for font in font_tables.ALL_FONTS: font12_map.update(font12_maps[font]) font06_map.update(font06_maps[font]) @@ -588,7 +575,6 @@ def prepare_language(lang: dict, defs: dict, build_version: str) -> LanguageData # Iterate over all of the text to build up the symbols & counts text_list, _ = get_letter_counts(defs, lang, build_version) # From the letter counts, need to make a symbol translator & write out the font - fonts = lang["fonts"] forced_first_symbols = get_forced_first_symbols() @@ -597,7 +583,7 @@ def prepare_language(lang: dict, defs: dict, build_version: str) -> LanguageData x for x in text_list if x not in forced_first_symbols ] - sym_list, sym_lists_by_font, font_map = get_sym_list_and_font_map(text_list, fonts) + sym_list, sym_lists_by_font, font_map = get_sym_list_and_font_map(text_list) return LanguageData( [lang], defs, build_version, sym_list, sym_lists_by_font, font_map ) @@ -611,13 +597,6 @@ def prepare_languages( forced_first_symbols = get_forced_first_symbols() - all_fonts = [ - font_tables.NAME_ASCII_BASIC, - font_tables.NAME_LATIN_EXTENDED, - font_tables.NAME_CYRILLIC, - font_tables.NAME_CJK, - ] - # Build the full font maps font12_map = {} font06_map = {} @@ -625,12 +604,11 @@ def prepare_languages( total_sym_counts: Dict[str, Dict[str, int]] = {} for lang in langs: text_list, sym_counts = get_letter_counts(defs, lang, build_version) - fonts = lang["fonts"] text_list = forced_first_symbols + [ x for x in text_list if x not in forced_first_symbols ] - font_maps = get_font_map_per_font(text_list, fonts) - for font in fonts: + font_maps = get_font_map_per_font(text_list) + for font in font_tables.ALL_FONTS: font12_map.update(font_maps.font12_maps[font]) font06_map.update(font_maps.font06_maps[font]) for font, font_sym_list in font_maps.sym_lists.items(): @@ -643,7 +621,7 @@ def prepare_languages( sym_lists_by_font: Dict[str, List[str]] = {} combined_sym_list = [] - for font in all_fonts: + for font in font_tables.ALL_FONTS: if font not in total_sym_counts: continue # swap to Big -> little sort order @@ -874,6 +852,9 @@ def write_languages( "const FontSectionDataInfo FontSectionDataInfos[] = {\n" ) for font, current_sym_list in sym_lists_by_font.items(): + print(font, current_sym_list) + if len(current_sym_list) == 0: + continue current_sym_start = combined_sym_list.index(current_sym_list[0]) + 2 font_uncompressed = bytearray() for sym in current_sym_list: