maple-font/source/py/utils.py

46 lines
1.2 KiB
Python

import platform
import subprocess
from fontTools.ttLib import TTFont
# run command
def run(cli: str | list[str], extra_args: list[str] = []):
subprocess.run((cli.split(" ") if isinstance(cli, str) else cli) + extra_args)
def set_font_name(font: TTFont, name: str, id: int):
font["name"].setName(name, nameID=id, platformID=1, platEncID=0, langID=0x0)
font["name"].setName(name, nameID=id, platformID=3, platEncID=1, langID=0x409)
def get_font_name(font: TTFont, id: int) -> str:
return (
font["name"]
.getName(nameID=id, platformID=3, platEncID=1, langID=0x409)
.__str__()
)
def del_font_name(font: TTFont, id: int):
font["name"].removeNames(nameID=id)
def joinPaths(*args: list[str]) -> str:
return "/".join(args)
def get_font_forge_bin():
WIN_FONTFORGE_PATH = "C:/Program Files (x86)/FontForgeBuilds/bin/fontforge.exe"
MAC_FONTFORGE_PATH = (
"/Applications/FontForge.app/Contents/Resources/opt/local/bin/fontforge"
)
LINUX_FONTFORGE_PATH = "/usr/bin/fontforge"
system_name = platform.uname()[0]
if "Darwin" in system_name:
return MAC_FONTFORGE_PATH
elif "Windows" in system_name:
return WIN_FONTFORGE_PATH
else:
return LINUX_FONTFORGE_PATH