From 0251f172f3601de7e52d8d2dfa935b8fc1eef925 Mon Sep 17 00:00:00 2001 From: TakWolf Date: Tue, 17 Dec 2024 14:23:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=20DesignContext=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/services/font_service.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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