Update README, skip OTF

This commit is contained in:
2025-08-21 16:04:00 +02:00
parent 8b1d345b60
commit aeb4fd621b
2 changed files with 55 additions and 25 deletions

View File

@@ -1,8 +1,8 @@
# KoboFix Font Processor # Kobo Font Fix
## Overview ## Overview
`kobofix.py` is a Python script designed to process TTF and OTF fonts for Kobo e-readers. `kobofix.py` is a Python script designed to process TTF fonts for Kobo e-readers.
It generates a renamed font, fixes PANOSE information based on the filename, adjusts the baseline with the `font-line` utility, and adds a legacy `kern` table which allows the `kepub` engine for improved rendering of kerned pairs. It generates a renamed font, fixes PANOSE information based on the filename, adjusts the baseline with the `font-line` utility, and adds a legacy `kern` table which allows the `kepub` engine for improved rendering of kerned pairs.
@@ -37,14 +37,31 @@ source ~/.zshrc
``` ```
3. The script will: 3. The script will:
* Validate filenames. * Validate the file names (must end with `-Regular`, `-Bold`, `-Italic` or `-BoldItalic` so they're valid for Kobo devices).
* Process each font (e.g. "Lora" becomes "KF Lora"). * Process each font (e.g. "Lora" becomes "KF Lora").
* Apply kerning, rename, PANOSE adjustments, and baseline shift. * Apply kerning, rename, PANOSE adjustments, and baseline shift.
* Save output as `KF_<original_filename>`. * Save output as `KF_<original_filename>`.
Example: ### Generating KF fonts
This applies the KF prefix, applies 20 percent line spacing and adds a Kobo `kern` table. Ideal if you have an existing TrueType font and you want it on your Kobo device. The `--name` parameter is used to change the name of the font family.
```bash
./kobofix.py --prefix KF --name="Fonty" --line-percent 20 *.ttf
```
### Generating NV fonts
Tight spacing, with a custom font family name, as is required via the OFL license:
```bash
./kobofix.py --prefix NV --name="Fonty" --line-percent 20 --skip-kobo-kern *.ttf
``` ```
Original: Lora-BoldItalic.ttf
Processed: KF_Lora-BoldItalic.ttf Relaxed spacing, with a custom font family name, as is required via the OFL license:
```bash
./kobofix.py --prefix NV --name="Fonty" --line-percent 50 --skip-kobo-kern *.ttf
``` ```
You can play around with `--line-percent` to see what works for you.

View File

@@ -2,7 +2,7 @@
""" """
Font processing utility for Kobo e-readers. Font processing utility for Kobo e-readers.
This script processes TrueType/OpenType fonts to improve compatibility with This script processes TrueType fonts to improve compatibility with
Kobo e-readers by: Kobo e-readers by:
- Adding a custom prefix to font names - Adding a custom prefix to font names
- Extracting GPOS kerning data and creating legacy 'kern' tables - Extracting GPOS kerning data and creating legacy 'kern' tables
@@ -29,8 +29,10 @@ from fontTools.ttLib.tables._k_e_r_n import KernTable_format_0
# Constants # Constants
DEFAULT_PREFIX = "KF" DEFAULT_PREFIX = "KF"
DEFAULT_LINE_PERCENT = 20 DEFAULT_LINE_PERCENT = 20
DEFAULT_KOBO_KERN = True
VALID_SUFFIXES = ("-Regular", "-Bold", "-Italic", "-BoldItalic") VALID_SUFFIXES = ("-Regular", "-Bold", "-Italic", "-BoldItalic")
SUPPORTED_EXTENSIONS = (".ttf", ".otf") SUPPORTED_EXTENSIONS = (".ttf")
# Configure logging # Configure logging
logging.basicConfig(level=logging.INFO, format='%(message)s') logging.basicConfig(level=logging.INFO, format='%(message)s')
@@ -40,16 +42,18 @@ logger = logging.getLogger(__name__)
class FontProcessor: class FontProcessor:
"""Main font processing class.""" """Main font processing class."""
def __init__(self, prefix: str = DEFAULT_PREFIX, line_percent: int = DEFAULT_LINE_PERCENT): def __init__(self, prefix: str = DEFAULT_PREFIX, line_percent: int = DEFAULT_LINE_PERCENT, kobo_kern_fix: bool = DEFAULT_KOBO_KERN):
""" """
Initialize the font processor. Initialize the font processor.
Args: Args:
prefix: Prefix to add to font names prefix: Prefix to add to font names
line_percent: Percentage for baseline adjustment line_percent: Percentage for baseline adjustment
kobo_kern_fix: Apply `kern` table fix for Kobo devices
""" """
self.prefix = prefix self.prefix = prefix
self.line_percent = line_percent self.line_percent = line_percent
self.kobo_kern_fix = kobo_kern_fix
# ============================================================ # ============================================================
# Kerning extraction methods # Kerning extraction methods
@@ -417,7 +421,7 @@ class FontProcessor:
# Main processing method # Main processing method
# ============================================================ # ============================================================
def process_font(self, font_path: str, new_name: Optional[str] = None) -> bool: def process_font(self, kern: bool, font_path: str, new_name: Optional[str] = None) -> bool:
""" """
Process a single font file. Process a single font file.
@@ -445,17 +449,21 @@ class FontProcessor:
# Fix PANOSE # Fix PANOSE
self.check_and_fix_panose(font, font_path) self.check_and_fix_panose(font, font_path)
# Handle kerning if kern:
kern_pairs = self.extract_kern_pairs(font) # Handle kerning
if kern_pairs: kern_pairs = self.extract_kern_pairs(font)
written = self.add_legacy_kern(font, kern_pairs) if kern_pairs:
logger.info( written = self.add_legacy_kern(font, kern_pairs)
f" Kerning: extracted {len(kern_pairs)} pairs; " logger.info(
f"wrote {written} to legacy 'kern' table" f" Kerning: extracted {len(kern_pairs)} pairs; "
) f"wrote {written} to legacy 'kern' table"
)
else:
logger.info(" Kerning: no GPOS kerning found")
else: else:
logger.info(" Kerning: no GPOS kerning found") # Skip kerning step
logger.info(" Skipping `kern` step")
# Generate output filename # Generate output filename
output_path = self._generate_output_path(font_path, new_name) output_path = self._generate_output_path(font_path, new_name)
@@ -538,16 +546,15 @@ def main():
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=""" epilog="""
Examples: Examples:
%(prog)s font-Regular.ttf font-Bold.ttf %(prog)s --name="Fonty" --line-percent 20 *.ttf
%(prog)s --name "My Font" *.ttf %(prog)s --prefix NV --name="Fonty" --line-percent 20 --skip-kobo-kern *.ttf
%(prog)s --prefix KOBO --line-percent 25 font.ttf
""" """
) )
parser.add_argument( parser.add_argument(
"fonts", "fonts",
nargs="+", nargs="+",
help="Font files to process (*.ttf, *.otf)" help="Font files to process (*.ttf)"
) )
parser.add_argument( parser.add_argument(
"--name", "--name",
@@ -566,6 +573,11 @@ Examples:
default=DEFAULT_LINE_PERCENT, default=DEFAULT_LINE_PERCENT,
help=f"Line spacing adjustment percentage (default: {DEFAULT_LINE_PERCENT})" help=f"Line spacing adjustment percentage (default: {DEFAULT_LINE_PERCENT})"
) )
parser.add_argument(
"--skip-kobo-kern",
action="store_true",
help="Skip the creation of the legacy 'kern' table from GPOS data."
)
parser.add_argument( parser.add_argument(
"--verbose", "--verbose",
action="store_true", action="store_true",
@@ -601,12 +613,13 @@ Examples:
# Process fonts # Process fonts
processor = FontProcessor( processor = FontProcessor(
prefix=args.prefix, prefix=args.prefix,
line_percent=args.line_percent line_percent=args.line_percent,
) )
success_count = 0 success_count = 0
for font_path in valid_files: for font_path in valid_files:
if processor.process_font( if processor.process_font(
not args.skip_kobo_kern,
font_path, font_path,
args.name, args.name,
): ):