mirror of
https://github.com/nicoverbruggen/kobo-font-fix.git
synced 2026-04-01 06:50:09 +02:00
Refactor CLI flags into modal options and add presets
This is a big commit that fixes a variety of issues and prevents fonts
from growing far too large without any benefits. Previously, converted
fonts would use multiple subtables for the `kern` table, but sadly those
are usually not read by renderers, so we now don't save al kern pairs,
but we prioritize.
The full list of changes can be found below.
---
Replace individual boolean flags with modal --kern and --hint options:
- --hint {skip,additive,overwrite,strip}: controls hinting behavior,
including new ttfautohint support (additive/overwrite modes)
- --kern {add-legacy-kern,legacy-kern-only,skip}: replaces the old
--skip-kobo-kern and --remove-gpos flags
- --preset {nv,kf}: bundled configurations for common workflows
Add upfront dependency checking (`ttfautohint`, `font-line`) so missing
tools are caught before any processing begins.
Fix GPOS Extension lookup (type 9) support: kern pairs were silently
missed in fonts that wrap PairPos subtables in Extension lookups.
Rework legacy kern table writing to respect format 0 size constraints.
The subtable length field is uint16, limiting a single subtable to
10,920 pairs. Since most renderers (including Kobo) only read the first
subtable, we write exactly one and prioritize pairs by Unicode range.
=> Basic Latin > Latin-1 Supplement > Latin Extended > rest
This way, the most commonly encountered kerning pairs are preserved
when truncation is needed (and it usually is, for quality fonts).
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# ttfconv.py
|
||||
|
||||
# This script converts OTF fonts to TTF fonts using the font-tools library.
|
||||
# It processes a list of font files provided as command-line arguments.
|
||||
|
||||
# The font-tools library must be installed: `pip install fonttools`.
|
||||
|
||||
from fontTools.ttLib import TTFont
|
||||
import os
|
||||
import sys
|
||||
|
||||
def convert_font(input_file_path):
|
||||
"""
|
||||
Converts a font file to a TTF font file.
|
||||
This function currently assumes the input is OTF and the output is TTF.
|
||||
|
||||
Args:
|
||||
input_file_path (str): The path to the input font file.
|
||||
"""
|
||||
if not os.path.exists(input_file_path):
|
||||
print(f"❌ Error: The file '{input_file_path}' was not found.")
|
||||
return
|
||||
|
||||
try:
|
||||
output_file_path = os.path.splitext(input_file_path)[0] + ".ttf"
|
||||
font = TTFont(input_file_path)
|
||||
font.save(output_file_path)
|
||||
|
||||
print(f"✅ Converted: {os.path.basename(input_file_path)} -> {os.path.basename(output_file_path)}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ An error occurred during conversion of '{os.path.basename(input_file_path)}': {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python font_converter.py <font_file1> <font_file2> ...")
|
||||
print("Example: python font_converter.py MyFont.otf AnotherFont.otf")
|
||||
print("You can also use a wildcard: python font_converter.py *.otf")
|
||||
else:
|
||||
for file_path in sys.argv[1:]:
|
||||
if file_path.lower().endswith(".otf"):
|
||||
convert_font(file_path)
|
||||
else:
|
||||
print(f"⚠️ Skipping '{file_path}': This script only converts OTF to TTF.")
|
||||
print(f"To convert other formats, please provide the correct extension.")
|
||||
|
||||
print("\nProcessing complete.")
|
||||
Reference in New Issue
Block a user