Этот код выводит CSV всех шрифтов, установленных в вашей системе, с именами файлов, именами Windows и Postscript.
Для запуска необходимо установить Photoshop и Python. Перед запуском также оставьте окно Photoshop открытым, чтобы оно могло оттуда получить список шрифтов.
Функция короткого имени была отсюда - https://gist.github.com/pklaus/dce37521579513c574d0
# This program lists all installed fonts on the computer with their font file name, Windows name and Postscript name.
import os
from fontTools import ttLib
from win32com.client import GetActiveObject
import pandas as pd
FONT_SPECIFIER_NAME_ID = 4
FONT_SPECIFIER_FAMILY_ID = 1
list = []
app = GetActiveObject("Photoshop.Application") # Get instance of open Photoshop window
df = pd.DataFrame(columns=['Font File Name', 'Windows Name', 'Postscript Name'])
def shortName(font):
"""Get the short name from the font's names table"""
name = ""
family = ""
for record in font['name'].names:
if b'\x00' in record.string:
name_str = record.string.decode('utf-16-be')
else:
name_str = record.string.decode('utf-8')
if record.nameID == FONT_SPECIFIER_NAME_ID and not name:
name = name_str
elif record.nameID == FONT_SPECIFIER_FAMILY_ID and not family:
family = name_str
if name and family: break
return name, family
def getPostScriptName(winName):
for i in range(0, len(app.fonts)):
if(app.fonts[i].name == winName):
return app.fonts[i].postScriptName
x = 0
for file in os.listdir(r'C:\Windows\Fonts'):
if (file.endswith(".ttf") or file.endswith(".otf")):
try:
fontfile = file
file = "C:\\Windows\\Fonts\\" + file
tt = ttLib.TTFont(file)
psName = getPostScriptName(shortName(tt)[0])
print(fontfile, shortName(tt)[0], psName)
df.at[x, 'Font File Name'] = fontfile
df.at[x, 'Windows Name'] = shortName(tt)[0]
df.at[x, 'Postscript Name'] = psName
x = x + 1
df.to_csv("installed-fonts.csv",index=False)
except Exception as e:
print (e)
continue