From 139b14dbf62df3131f042ad258a69da3d44716e6 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sat, 14 Mar 2026 12:10:08 +0100 Subject: [PATCH] Tweak autohinting --- README.md | 21 +++++++++++++++++++++ build.py | 16 +++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2018134..1bbf738 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ flatpak install flathub org.fontforge.FontForge ### macOS preparation +#### System Python + On macOS, if you're using the built-in version of Python (via Xcode), you may need to first add a folder to your `PATH` to make `font-line` available, like: ```bash @@ -54,8 +56,27 @@ pip3 install fonttools font-line source ~/.zshrc ``` +#### Homebrew Python + +If you're using `brew install python`, pip requires a virtual environment: + +```bash +brew install fontforge ttfautohint +python3 -m venv .venv +source .venv/bin/activate +pip install fonttools +``` + ## Building +**Note**: If you're using `venv`, you will need to activate it first: + +``` +source .venv/bin/activate +``` + +If you are just using the system Python, you can skip that step and simply run: + ``` python3 build.py ``` diff --git a/build.py b/build.py index baaaf1a..c779103 100755 --- a/build.py +++ b/build.py @@ -87,6 +87,20 @@ LINE_HEIGHT = 1.0 SELECTION_HEIGHT = 1.3 ASCENDER_RATIO = 0.8 +# Step 4: ttfautohint options (hinting for Kobo's FreeType renderer) +# - Kobo uses FreeType grayscale, so the 1st char of --stem-width-mode +# (gray) is the one that matters. n=natural, q=quantized, s=strong. +# - Remaining two chars are for GDI and DirectWrite (not used on Kobo). +# - Other options are left at ttfautohint defaults; uncomment to override. +AUTOHINT_OPTS = [ + "--no-info", + "--stem-width-mode=nss", + # "--hinting-range-min=8", + # "--hinting-range-max=50", + # "--hinting-limit=200", + "--increase-x-height=0", +] + # Step 3: Naming and style metadata (used by the rename step) STYLE_MAP = { "Regular": ("Regular", "Book", 400), @@ -642,7 +656,7 @@ def autohint_ttf(ttf_path): tmp_path = ttf_path + ".autohint.tmp" result = subprocess.run( - ["ttfautohint", "--no-info", ttf_path, tmp_path], + ["ttfautohint"] + AUTOHINT_OPTS + [ttf_path, tmp_path], capture_output=True, text=True, ) if result.returncode != 0: