Skip to content

Commit

Permalink
升级依赖,并修复上下文加载
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Jul 10, 2024
1 parent 8660a48 commit 4fc298f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pixel-font-builder==0.0.27
pixel-font-knife==0.0.3
pixel-font-knife==0.0.4
fonttools==4.53.1
unidata-blocks==0.0.13
character-encoding-utils==0.0.8
Expand Down
27 changes: 3 additions & 24 deletions tools/services/font_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
from tools.configs.font import FontConfig


def _get_glyph_name(glyph_file: GlyphFile) -> str:
if glyph_file.code_point == -1:
name = '.notdef'
else:
name = f'{glyph_file.code_point:04X}'
if len(glyph_file.flavors) > 0:
name = f'{name}-{glyph_file.flavors[0]}'
return name


class DesignContext:
@staticmethod
def load(font_config: FontConfig) -> 'DesignContext':
Expand Down Expand Up @@ -91,12 +81,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 = {}
for code_point, flavor_group in self.glyph_files[width_mode].items():
if code_point < 0:
continue
glyph_file = flavor_group.get_file(language_flavor, fallback_default=True)
character_mapping[code_point] = _get_glyph_name(glyph_file)
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 @@ -105,13 +90,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 = []
flavor_group_sequence = sorted(self.glyph_files[width_mode].values(), key=lambda x: x.code_point)
for flavor in configs.language_flavors if language_flavor is None else [language_flavor]:
for flavor_group in flavor_group_sequence:
glyph_file = flavor_group.get_file(flavor, fallback_default=True)
if glyph_file not in glyph_sequence:
glyph_sequence.append(glyph_file)
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 Expand Up @@ -164,7 +143,7 @@ def _create_builder(self, width_mode: WidthMode, language_flavor: LanguageFlavor
horizontal_origin_y = math.floor((layout_param.ascent + layout_param.descent - glyph_file.height) / 2)
vertical_origin_y = (self.font_size - glyph_file.height) // 2 - 1
glyph = Glyph(
name=_get_glyph_name(glyph_file),
name=glyph_file.glyph_name,
advance_width=glyph_file.width,
advance_height=self.font_size,
horizontal_origin=(0, horizontal_origin_y),
Expand Down

0 comments on commit 4fc298f

Please sign in to comment.