[OpenFontFormat] Update name.py to allow input from fonts.sh
This commit is contained in:
parent
acacae70ff
commit
a007a28cc1
@ -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)
|
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:
|
with open(file_path, 'rb') as f:
|
||||||
return parse_open_font_file(f)
|
return parse_open_font_file(f)
|
||||||
|
30
OpenFontFormat/name.py
Normal file → Executable file
30
OpenFontFormat/name.py
Normal file → Executable file
@ -1,6 +1,8 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
import os
|
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:
|
def search_names(font: OpenFontFile, nameID: NameID) -> str:
|
||||||
assert isinstance(font.naming_table, NameTable_Format_0)
|
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
|
num_instances = font.font_variations.font_variations.instanceCount
|
||||||
print(f"\tAxes: [{', '.join(axis_names)}] ({num_instances} instances)")
|
print(f"\tAxes: [{', '.join(axis_names)}] ({num_instances} instances)")
|
||||||
|
|
||||||
path = "examples/"
|
|
||||||
if os.path.isfile(path):
|
def do_font(file: str):
|
||||||
try:
|
try:
|
||||||
font = open_font(path)
|
font = open_font_file(file)
|
||||||
except AssertionError as err:
|
|
||||||
print("Failed:", path)
|
|
||||||
raise err
|
|
||||||
print_font(font)
|
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:
|
except AssertionError as err:
|
||||||
print("Failed:", file_path)
|
print(f"Failed: {file}")
|
||||||
raise err
|
raise err
|
||||||
print_font(font)
|
|
||||||
|
assert not sys.stdin.isatty()
|
||||||
|
for line in sys.stdin:
|
||||||
|
file = line.rstrip('\n')
|
||||||
|
do_font(file)
|
Loading…
Reference in New Issue
Block a user