Skip to content

Commit

Permalink
调整 DesignContext 属性
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Dec 18, 2024
1 parent 83cf16d commit 0251f17
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tools/services/font_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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 = {}
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 0251f17

Please sign in to comment.