Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
调整字体配置参数
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Aug 6, 2023
1 parent cbcdd07 commit df1cf8c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions assets/glyphs/sheikah-mini-smooth/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "Sheikah Mini Smooth"
alphabet_name = "Sheikah Language"

size = 8
line_height = 8
box_origin_y = 7
ascent = 7
descent = -1
x_height = 7
cap_height = 7
4 changes: 2 additions & 2 deletions assets/glyphs/sheikah-mini/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "Sheikah Mini"
alphabet_name = "Sheikah Language"

size = 8
line_height = 8
box_origin_y = 7
ascent = 7
descent = -1
x_height = 7
cap_height = 7
4 changes: 2 additions & 2 deletions assets/glyphs/sheikah/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "Sheikah"
alphabet_name = "Sheikah Language"

size = 15
line_height = 15
box_origin_y = 14
ascent = 14
descent = -1
x_height = 14
cap_height = 14
4 changes: 2 additions & 2 deletions configs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from configs.font_config import FontConfig

font_formats = ['otf', 'woff2', 'ttf', 'bdf']

font_configs = FontConfig.loads()
outputs_name_to_config = {font_config.outputs_name: font_config for font_config in font_configs}

font_formats = ['otf', 'woff2', 'ttf', 'bdf']
10 changes: 6 additions & 4 deletions configs/font_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ def __init__(self, config_data: dict):
self.description = FontConfig.DESCRIPTION_FORMAT.format(alphabet_name=alphabet_name)

self.size: int = config_data['size']
self.line_height: int = config_data['line_height']
self.ascent: int = config_data['ascent']
self.descent: int = config_data['descent']
assert (self.line_height - self.size) % 2 == 0, f"Font config '{self.name}': the difference between 'line_height' and 'size' must be a multiple of 2"
self.box_origin_y: int = config_data['box_origin_y']
self.ascent = self.box_origin_y + (self.line_height - self.size) // 2
self.descent = self.ascent - self.line_height
self.x_height: int = config_data['x_height']
self.cap_height: int = config_data['cap_height']

self.outputs_dir = os.path.join(path_define.outputs_dir, self.outputs_name)

@property
def line_height(self) -> int:
return self.ascent - self.descent
3 changes: 2 additions & 1 deletion services/font_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import math
import os

from pixel_font_builder import FontBuilder, Glyph, StyleName, SerifMode, WidthMode
Expand Down Expand Up @@ -86,7 +87,7 @@ def _create_builder(font_config: FontConfig, character_mapping: dict[int, str],

for glyph_name, glyph_file_path in glyph_file_paths.items():
glyph_data, glyph_width, glyph_height = glyph_util.load_glyph_data_from_png(glyph_file_path)
offset_y = font_config.box_origin_y + (glyph_height - font_config.size) // 2 - glyph_height
offset_y = math.floor((font_config.ascent + font_config.descent - glyph_height) / 2)
builder.add_glyph(Glyph(
name=glyph_name,
advance_width=glyph_width,
Expand Down

0 comments on commit df1cf8c

Please sign in to comment.