Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .otc support, fix invalid .ttc/.otc handling and update readme.md to match the new features. #9

Merged
merged 5 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# font-rename

rename fonts & unpack ttc
Renames fonts to their internal name and unpacks .ttc/.otc files.

```bash
pipx install font-rename
font-rename ~/fonts/aaa.ttc
pip install font-rename
font-rename insert/directory/file/path/here
```
21 changes: 20 additions & 1 deletion font_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,37 @@ def rename_font(filepath: Path):


def unpack_ttc(filepath: Path):
collection = TTCollection(str(filepath.resolve()))
try:
collection = TTCollection(str(filepath.resolve()))
except:
print(f"Failed to parse {filepath}, ignore")
return
for font in collection.fonts:
ttf_path = filepath.parent / f"{get_font_name(font)}.ttf"
font.save(ttf_path)
print(f"{filepath} -> {ttf_path}")
filepath.unlink()


def unpack_otc(filepath: Path):
try:
collection = TTCollection(str(filepath.resolve()))
except:
print(f"Failed to parse {filepath}, ignore")
return
for font in collection.fonts:
ttf_path = filepath.parent / f"{get_font_name(font)}.otf"
font.save(ttf_path)
print(f"{filepath} -> {ttf_path}")
filepath.unlink()


def handle_file(filepath: Path):
suffix = filepath.suffix.lower()
if suffix == ".ttc":
unpack_ttc(filepath)
if suffix == ".otc":
unpack_otc(filepath)
whtsky marked this conversation as resolved.
Show resolved Hide resolved
else:
rename_font(filepath)

Expand Down