From 4fc298fc2ea25598cd458e6e6ae5ebc85fbb65b3 Mon Sep 17 00:00:00 2001 From: TakWolf Date: Wed, 10 Jul 2024 10:45:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BE=9D=E8=B5=96=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=B8=8B=E6=96=87=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 2 +- tools/services/font_service.py | 27 +++------------------------ 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/requirements.txt b/requirements.txt index 19d7843..6b7b70c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tools/services/font_service.py b/tools/services/font_service.py index c6ff4f5..bb17328 100644 --- a/tools/services/font_service.py +++ b/tools/services/font_service.py @@ -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': @@ -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 @@ -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 @@ -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),