12

I have a TTF font installed on my Mac that I have added to an X-Code development project. For the life of me, I can not get it to work with my application but I think it's because I'm using the wrong font name.

Using Font Book, or any other tool, how can I get the Postscript font name from the font meta-data?

I have a hunch that the Postscript name might be different from the Font name, but I need to verify.

17

Open the Font Book application. (It should be in your Applications folder.)

Select the font you need the Postscript Name for.

Select Show Font Info from the Preview Menu. ( Or use +i).

screenshot:fontbook font info

7

Your assumption is correct. iOS requires that you identify a font based on its Postscript name (or Fullname), which is not always the same as the font's actual Filename.

You can get the PostScript name using FontBook (as shown on the accepted answer here), but there are other ways.

From directly inside XCode, you can extract the PostScript Name from the project's installed fonts via UIFont. Simply run this to print the PostScript names of your installed project fonts :

In Objective-C (source):

for (NSString *fontFamilyName in [UIFont familyNames]) {
    for (NSString *fontName in [UIFont fontNamesForFamilyName:fontFamilyName]) {
        NSLog(@"Family: %@ Font: %@", fontFamilyName, fontName);
    }
}

Or Swift 3.0 (source)

for familyName in UIFont.familyNames {
    for fontName in UIFont.fontNames(forFamilyName: familyName ) {
        print("\(familyName) : \(fontName)")
    }
}

Or from the terminal, from inside the directory where you have your font files, you can run this script to print all the PostScript names of the fonts inside the current directory (uses the fc-scan utility from fontconfig which is probaly already installed) (source):

for file in "$arg"*.{ttf,otf}; do fc-scan --format "%{postscriptname}\n" $file; done

Here is a screenshot of the above command running on my ~/Library/Fonts directory:

enter image description here

The script above will run through all the .ttf and .otf files in the current directory, then print out the PostScript Name for each font which you can use to reference the font file in XCode or elsewhere.

If you want to get fancy with some additional information (PostScriptName, Filename) and some color coding, you can run this alternative script:

for file in "$arg"*.{ttf,otf}; do 
    postscriptname=$(fc-scan --format "%{postscriptname}\n" $file);
    printf "\033[36m PostScript Name:\033[0m %s \e[90m(%s)\033[0m\n" "$postscriptname" "$file";
done

enter image description here

This is a bit faster than copy-pasting code inside of your AppDelegate.m file to print out the names every time you want to add a new font file, which is the popular method, and it's also faster than opening the Font in FontBook to inspect the PostScript Name.

USEFUL TIP: If you alias the above script in your terminal so that all you need to do is type a single command to get all the PostScript font names for all the files in the current directory, then you will save time in your development workflow and have this handy script ready to use when you need it.

Hope this helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .