Last active
February 22, 2021 17:40
-
-
Save connordavenport/23cc3ddd7b9234a453a78faf166e9406 to your computer and use it in GitHub Desktop.
find type1 fonts in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import sys | |
import fontTools.t1Lib | |
''' | |
usage: | |
cd into directory you want to look through | |
fun following command | |
python find-type1-fonts.py | |
if font is type1, it will print the first line of the data | |
e.g. "%!FontType1-1.1: SourceSerifVariable-Roman 1.0" | |
''' | |
def main(): | |
# if len(sys.argv) < 2: | |
# print("Please supply (atleast) one sfnt.") | |
# sys.exit(1) | |
cwd = os.getcwd() | |
for subdir, dirs, files in os.walk(cwd): | |
for file in files: | |
fontfile = os.path.join(subdir, file) | |
if os.path.splitext(fontfile) == ".ufo": | |
pass | |
else: | |
try: | |
font = fontTools.t1Lib.T1Font(fontfile) | |
print(font.getData().partition('\n')[0]) | |
except fontTools.t1Lib.T1Error as e: | |
pass | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment