Skip to content

Commit 6a362d4

Browse files
committed
Reduce word spacing by 5% for non-Mono fonts
1 parent 9508503 commit 6a362d4

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

scripts/fix_fonts.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,22 @@ def fix_spacing_metadata(font: TTFont, font_path: Path) -> bool:
885885
return changed
886886

887887

888+
def reduce_word_spacing(font: TTFont) -> bool:
889+
"""Reduce word spacing by 5% for non-mono (proportional) fonts."""
890+
if "post" in font and font["post"].isFixedPitch:
891+
return False
892+
893+
hmtx = font["hmtx"]
894+
space_width, space_lsb = hmtx["space"]
895+
new_width = round(space_width * 0.95)
896+
if new_width == space_width:
897+
return False
898+
899+
hmtx["space"] = (new_width, space_lsb)
900+
logger.info(f" ✓ Reduced word spacing: {space_width}{new_width} ({new_width - space_width})")
901+
return True
902+
903+
888904
def fix_license_entries(font: TTFont) -> bool:
889905
"""Force OFL license description and URL to the exact expected strings."""
890906
name_table = font["name"]
@@ -1008,6 +1024,9 @@ def post_process_font(font_path: Path, output_path: Optional[Path] = None) -> bo
10081024
if fix_spacing_metadata(font, font_path):
10091025
fixes_applied.append("spacing_metadata")
10101026

1027+
if reduce_word_spacing(font):
1028+
fixes_applied.append("reduced_word_spacing")
1029+
10111030
extra_fix_map = [
10121031
(fix_license_entries, "license_entries"),
10131032
(fix_style_bits, "style_bits"),

0 commit comments

Comments
 (0)