diff --git a/tools/services/font_service.py b/tools/services/font_service.py index a9aa96d..578255a 100644 --- a/tools/services/font_service.py +++ b/tools/services/font_service.py @@ -44,10 +44,11 @@ def load(font_config: FontConfig, mappings: list[dict[int, SourceFlavorGroup]]) glyph_files[width_mode] = dict(contexts['common']) glyph_files[width_mode].update(contexts[width_mode]) - return DesignContext(font_config, glyph_files) + return DesignContext(font_config, contexts, glyph_files) font_config: FontConfig - glyph_files: dict[WidthMode, dict[int, GlyphFlavorGroup]] + _contexts: dict[str, dict[int, GlyphFlavorGroup]] + _glyph_files: dict[WidthMode, dict[int, GlyphFlavorGroup]] _alphabet_cache: dict[str, set[str]] _character_mapping_cache: dict[str, dict[int, str]] _glyph_sequence_cache: dict[str, list[GlyphFile]] @@ -58,10 +59,12 @@ def load(font_config: FontConfig, mappings: list[dict[int, SourceFlavorGroup]]) def __init__( self, font_config: FontConfig, + contexts: dict[str, dict[int, GlyphFlavorGroup]], glyph_files: dict[WidthMode, dict[int, GlyphFlavorGroup]], ): self.font_config = font_config - self.glyph_files = glyph_files + self._contexts = contexts + self._glyph_files = glyph_files self._alphabet_cache = {} self._character_mapping_cache = {} self._glyph_sequence_cache = {} @@ -77,7 +80,7 @@ def get_alphabet(self, width_mode: WidthMode) -> set[str]: if width_mode in self._alphabet_cache: alphabet = self._alphabet_cache[width_mode] else: - alphabet = {chr(code_point) for code_point in self.glyph_files[width_mode] if code_point >= 0} + alphabet = {chr(code_point) for code_point in self._glyph_files[width_mode] if code_point >= 0} self._alphabet_cache[width_mode] = alphabet return alphabet @@ -86,7 +89,7 @@ def _get_character_mapping(self, width_mode: WidthMode, language_flavor: Languag if key in self._character_mapping_cache: character_mapping = self._character_mapping_cache[key] else: - character_mapping = glyph_file_util.get_character_mapping(self.glyph_files[width_mode], language_flavor) + character_mapping = glyph_file_util.get_character_mapping(self._glyph_files[width_mode], language_flavor) self._character_mapping_cache[key] = character_mapping return character_mapping @@ -95,7 +98,7 @@ def _get_glyph_sequence(self, width_mode: WidthMode, language_flavor: LanguageFl if key in self._glyph_sequence_cache: glyph_sequence = self._glyph_sequence_cache[key] else: - glyph_sequence = glyph_file_util.get_glyph_sequence(self.glyph_files[width_mode], configs.language_flavors if language_flavor is None else [language_flavor]) + glyph_sequence = glyph_file_util.get_glyph_sequence(self._glyph_files[width_mode], configs.language_flavors if language_flavor is None else [language_flavor]) self._glyph_sequence_cache[key] = glyph_sequence return glyph_sequence