1

I am trying to obtain the the font file name when the only information I have is the font's 'postscript' name. (Emphasis: the font's name is postscript and not the font).
For example I have the following postscript name: TimesNewRomanPSMT.
The real name that is saved in the registry is: Times New Roman (TrueType).
Is there any way of obtaining that name from the given postscript name?

I saw a similar post here which was left unaswered: C# get font from postscript name

I am coding this in C++ so I am not restricted by the coding language. Currently I am coding this for Windows, but it should be compatible, or at least have alternative code for MacOS

Community
  • 1
  • 1
radato
  • 840
  • 9
  • 27
  • What is the source of the "Postscript name"? How can you be sure that it is related to an installed font? – luser droog Mar 19 '14 at 18:27
  • I will explain. I get this name when I use Adobe's After Effects SDK. I get this name when I traverse over text which I know for sure is 'Times New Roman (True Type)' but Adobe says that the font name that they expose is a post script name for that font, and it is 'TimesNewRomanPSMT'. Going over many forums, I found the related question cited above, which had the same dilemma. – radato Mar 20 '14 at 09:17
  • The source for the ps name is when I use Adobe AfterEffects SDK. I traverse over a text object (called a 'text layer') and the font received from the sdk is 'TimesNewRomanPSMT'. Adobe proclaim in their documentation that this is the ps name for that font. The font being: 'Times New Roman (True Type)' – radato Mar 20 '14 at 09:24
  • First thing I'd try is unix-style tools like `fc-list | grep `. `fc-list` is part of `fontconfig`. – luser droog Mar 22 '14 at 05:07
  • I tried your suggestion and executed this on a font called Norasi: fc-list Norasi | grep Norasi and the result was not really interesting: /usr/share/fonts/truetype/tlwg/Norasi-BoldOblique.ttf: Norasi:style=BoldOblique /usr/share/fonts/truetype/tlwg/Norasi-Bold.ttf: Norasi:style=Bold /usr/share/fonts/truetype/tlwg/Norasi.ttf: Norasi:style=Regular /usr/share/fonts/truetype/tlwg/Norasi-Oblique.ttf: Norasi:style=Oblique /usr/share/fonts/truetype/tlwg/Norasi-Italic.ttf: Norasi:style=Italic /usr/share/fonts/truetype/tlwg/Norasi-BoldItalic.ttf: Norasi:style=BoldItalic – radato Mar 23 '14 at 11:03
  • Isn't the name right there between the first two `:`s on each line? – luser droog Mar 31 '14 at 23:51
  • I have the exact same issue, sad to see it has gone unanswered for 3 years... I'm working on collecting fonts from After Effects as well. – Spencer Nov 27 '17 at 04:22

2 Answers2

0

I have C++ code to get fontname from a given fontfile examining headers ... which however has failed for some fonts I tested (say works 90%). I think the easiest way is to open with a hex editor the font file and search the font name in there. If you are worried about the registry you can re-register the font name like the example below:

reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Arial Bold" /t REG_SZ /d arialbd.ttf

nickchalkida
  • 111
  • 3
0

I had a similar issue, but for Photoshop. So I wrote the code below. It outputs a CSV of all the fonts installed in your system with their filename, Windows name and Postscript name.

You need to have Photoshop and Python installed to run it. Before running it, also keep a Photoshop window open so it can grab the list of fonts from there.

Shortname function was from here - 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")):
        # list.append(file)
        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
thebigb
  • 21
  • 2