[OpenFontFormat] Update name.py to allow input from fonts.sh

This commit is contained in:
germax26 2024-07-28 14:29:32 +10:00
parent acacae70ff
commit a007a28cc1
Signed by: germax26
SSH Key Fingerprint: SHA256:N3w+8798IMWBt7SYH8G1C0iJlIa2HIIcRCXwILT5FvM
2 changed files with 14 additions and 20 deletions

View File

@ -5994,6 +5994,6 @@ def parse_open_font_file(f: BinaryIO) -> OpenFontFile:
return OpenFontFile(character_to_glyph_mapping, font_header, horizontal_header, horizontal_metrics, maximum_profile, naming_table, OS2_and_Windows_specific_metrics, PostScript_information, outlines, scalar_vector_graphics, digital_signature, horizontal_device_metrics, kerning, linear_threshold_data, PCL5_data, vertical_device_metrics, vertical_metrics_header, vertical_metrics, colour_table, colour_palette_table, advanced_features, font_variations)
def open_font(file_path: str) -> OpenFontFile: # as in `open (verb) font (noun)`, not OpenFont
def open_font_file(file_path: str) -> OpenFontFile: # as in `open (verb) font file (noun)`, not OpenFontFile
with open(file_path, 'rb') as f:
return parse_open_font_file(f)

32
OpenFontFormat/name.py Normal file → Executable file
View File

@ -1,6 +1,8 @@
#!/usr/bin/env python3
import os
import sys
from OpenFont import FontSpecificNameID, NameID, NameTable_Format_0, OpenFontFile, PredefinedNameID, TrueTypeOutlines, open_font
from OpenFont import FontSpecificNameID, NameID, NameTable_Format_0, OpenFontFile, PredefinedNameID, TrueTypeOutlines, open_font_file
def search_names(font: OpenFontFile, nameID: NameID) -> str:
assert isinstance(font.naming_table, NameTable_Format_0)
@ -23,24 +25,16 @@ def print_font(font: OpenFontFile):
num_instances = font.font_variations.font_variations.instanceCount
print(f"\tAxes: [{', '.join(axis_names)}] ({num_instances} instances)")
path = "examples/"
if os.path.isfile(path):
def do_font(file: str):
try:
font = open_font(path)
font = open_font_file(file)
print_font(font)
except AssertionError as err:
print("Failed:", path)
print(f"Failed: {file}")
raise err
print_font(font)
else:
for root, dirs, files in os.walk(path):
for file in files:
_, ext = os.path.splitext(file)
match ext:
case '.ttf':
file_path = os.path.join(root, file)
try:
font = open_font(file_path)
except AssertionError as err:
print("Failed:", file_path)
raise err
print_font(font)
assert not sys.stdin.isatty()
for line in sys.stdin:
file = line.rstrip('\n')
do_font(file)