mirror of
https://github.com/nicoverbruggen/kobo-font-fix.git
synced 2026-04-02 15:30:09 +02:00
Add --remove-prefix
This commit is contained in:
14
README.md
14
README.md
@@ -52,9 +52,17 @@ 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.
|
The `--name` parameter is used to change the name of the font family.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./kobofix.py --prefix KF --name="Fonty" --line-percent 20 *.ttf
|
./kobofix.py --prefix KF --name="Fonty" --line-percent 20 *.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.
|
||||||
|
|
||||||
|
To process all fonts with the "Kobo Fix" preset, simply run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./kobofix.py --prefix KF --remove-prefix="NV" --line-percent 20 *.ttf
|
||||||
|
```
|
||||||
|
|
||||||
### Generating NV fonts
|
### Generating NV fonts
|
||||||
|
|
||||||
|
|||||||
26
kobofix.py
26
kobofix.py
@@ -562,7 +562,8 @@ class FontProcessor:
|
|||||||
kern: bool,
|
kern: bool,
|
||||||
remove_gpos: bool,
|
remove_gpos: bool,
|
||||||
font_path: str,
|
font_path: str,
|
||||||
new_name: Optional[str] = None
|
new_name: Optional[str] = None,
|
||||||
|
remove_prefix: Optional[str] = None
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
Process a single font file.
|
Process a single font file.
|
||||||
@@ -577,7 +578,17 @@ class FontProcessor:
|
|||||||
logger.error(f" Failed to open font: {e}")
|
logger.error(f" Failed to open font: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
metadata = self._get_font_metadata(font, font_path, new_name)
|
# Determine the effective font name, checking for `--remove-prefix` first
|
||||||
|
effective_name = new_name
|
||||||
|
if new_name is None:
|
||||||
|
# If no --name argument is provided, get the font's best family name
|
||||||
|
current_family_name = font["name"].getBestFamilyName()
|
||||||
|
# If --remove-prefix is used and the name starts with the specified prefix, remove it
|
||||||
|
if remove_prefix and current_family_name.startswith(remove_prefix + " "):
|
||||||
|
effective_name = current_family_name[len(remove_prefix + " "):]
|
||||||
|
logger.info(f" --remove-prefix enabled: using '{effective_name}' as the new family name.")
|
||||||
|
|
||||||
|
metadata = self._get_font_metadata(font, font_path, effective_name)
|
||||||
if not metadata:
|
if not metadata:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -682,11 +693,8 @@ Examples:
|
|||||||
For improved legacy support, you can remove the GPOS table (not recommended):
|
For improved legacy support, you can remove the GPOS table (not recommended):
|
||||||
%(prog)s --prefix KF --name="Fonty" --line-percent 20 --remove-gpos *.ttf
|
%(prog)s --prefix KF --name="Fonty" --line-percent 20 --remove-gpos *.ttf
|
||||||
|
|
||||||
If you only want to prefix the font and rename it:
|
To remove a specific prefix, like "NV", before applying a new one:
|
||||||
%(prog)s --prefix NV --name="Fonty" --line-percent 0 --skip-kobo-kern *.ttf
|
%(prog)s --prefix KF --remove-prefix="NV" *.ttf
|
||||||
|
|
||||||
If you only want to prefix the font, rename it and apply line-height:
|
|
||||||
%(prog)s --prefix NV --name="Fonty" --line-percent 20 --skip-kobo-kern *.ttf
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -704,6 +712,9 @@ Examples:
|
|||||||
help="Remove the GPOS table after converting kerning to a 'kern' table. Does not work if `--skip-kobo-kern` is set.")
|
help="Remove the GPOS table after converting kerning to a 'kern' table. Does not work if `--skip-kobo-kern` is set.")
|
||||||
parser.add_argument("--verbose", action="store_true",
|
parser.add_argument("--verbose", action="store_true",
|
||||||
help="Enable verbose output.")
|
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\")")
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -741,6 +752,7 @@ Examples:
|
|||||||
args.remove_gpos,
|
args.remove_gpos,
|
||||||
font_path,
|
font_path,
|
||||||
args.name,
|
args.name,
|
||||||
|
args.remove_prefix,
|
||||||
):
|
):
|
||||||
success_count += 1
|
success_count += 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user