Add an option to remove TrueType hints

You can invoke it by adding `--remove-hints` as an argument.

This may improve the appearance of certain fonts on Kobo devices with
high resolution displays. Might make a difference for 300 DPI and up,
at 12 pt font sizes and above.

For the upcoming update to the  KF collection of fonts, this flag will
likely be used for all fonts or at the very least for a selection of
fonts that benefit from TrueType hints being absent.
This commit is contained in:
2025-10-07 21:16:24 +02:00
parent da8b3631ea
commit 1ed3677d8e
2 changed files with 39 additions and 7 deletions

View File

@@ -87,7 +87,7 @@ This applies the KF prefix, applies 20 percent line spacing and adds a Kobo `ker
The `--name` parameter is used to change the name of the font family.
```bash
./kobofix.py --prefix KF --name="Fonty" --line-percent 20 *.ttf
./kobofix.py --prefix KF --name="Fonty" --line-percent 20 --remove-hints *.ttf
```
To process fonts from my [ebook-fonts](https://github.com/nicoverbruggen/ebook-fonts) collection which are prefixed with "NV", you can replace the prefix and make adjustments in bulk.

View File

@@ -607,6 +607,7 @@ class FontProcessor:
font_path: str,
new_name: Optional[str] = None,
remove_prefix: Optional[str] = None,
remove_hints: bool = False,
) -> bool:
"""
Process a single font file.
@@ -676,6 +677,34 @@ class FontProcessor:
del font["GPOS"]
logger.info(" Removed GPOS table from the font.")
# Remove TrueType hints if requested
if remove_hints:
hints_removed = False
# Remove fpgm (Font Program) table
if "fpgm" in font:
del font["fpgm"]
hints_removed = True
# Remove prep (Control Value Program) table
if "prep" in font:
del font["prep"]
hints_removed = True
# Remove cvt (Control Value Table)
if "cvt " in font:
del font["cvt "]
hints_removed = True
# Remove hints from glyf table using the built-in removeHinting method
if "glyf" in font:
for glyph_name in font.getGlyphOrder():
glyph = font["glyf"][glyph_name]
if hasattr(glyph, 'removeHinting'):
glyph.removeHinting()
hints_removed = True
if hints_removed:
logger.info(" Removed TrueType hints from the font.")
else:
logger.info(" No TrueType hints found to remove.")
output_path = self._generate_output_path(font_path, metadata)
font.save(output_path)
logger.info(f" Saved: {output_path}")
@@ -780,6 +809,8 @@ Examples:
help="Enable verbose output.")
parser.add_argument("--remove-prefix", type=str,
help="Remove a leading prefix from font names before applying the new prefix. Only works if `--name` is not used. (e.g., --remove-prefix=\"NV\")")
parser.add_argument("--remove-hints", action="store_true",
help="Remove TrueType hints from the font. This may improve render quality on some devices and reduce file size.")
args = parser.parse_args()
@@ -819,6 +850,7 @@ Examples:
font_path,
args.name,
args.remove_prefix,
args.remove_hints,
):
success_count += 1