Skip to content

Commit

Permalink
代码整理
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Dec 17, 2024
1 parent 04523cf commit b52ec1a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 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 All @@ -108,7 +111,6 @@ def _get_glyph_pool(self, width_mode: WidthMode) -> dict[Path, Glyph]:
return glyph_pool

def _create_builder(self, width_mode: WidthMode, language_flavor: LanguageFlavor, is_collection: bool) -> FontBuilder:
glyph_pool = self._get_glyph_pool(width_mode)
layout_param = self.font_config.layout_params[width_mode]

builder = FontBuilder()
Expand Down Expand Up @@ -141,6 +143,7 @@ def _create_builder(self, width_mode: WidthMode, language_flavor: LanguageFlavor
builder.character_mapping.update(character_mapping)

glyph_sequence = self._get_glyph_sequence(width_mode, None if is_collection else language_flavor)
glyph_pool = self._get_glyph_pool(width_mode)
for glyph_file in glyph_sequence:
if glyph_file.file_path in glyph_pool:
glyph = glyph_pool[glyph_file.file_path]
Expand Down

0 comments on commit b52ec1a

Please sign in to comment.