Fontforge can't get TTF names via Scripting

Primary tabs

5 posts / 0 new
Last post
Martin Andersen's picture
Joined: 9 Apr 2011 - 7:54am
Fontforge can't get TTF names via Scripting

I'm trying to convert a collection of Windows Postscript files to OTF on OSX. For that, I decided to go with Fontforge because I can batch-process them with scripts in the terminal. I know little bash-scripting and no Python, but have been able to modify a script on the Fontforge site to do this:
However, as it is, I need to modify a lot of the files by hand to get the Style to display as I like it, like "Bold Italic" instead of "BoldItalic" with no spaces. So, I've looked into the documentation and tried to use the GetTTFName() and SetTTFName() functions to do this. I can get it to set the Style (subfamily) just fine, but I get an empty string when trying to read the existing style. Opening the font in the GUI, it displays the Style under the TTF section, so it is there. What I am experimenting with:

style = GetTTFName(0x409,2)
if (style!="") #use 'case' ?
if (style=="BoldItalic")
style="Bold Italic"
elseif (style=="BoldCondensed")
style="Bold Condensed"
elseif (style=="BoldCondItalic")
style="Bold Italic Condensed")
elseif (style=="SemiBoldItalic")
style="SemiBold Italic"
elseif (style=="BlackItalic")
style="Black Italic"
elseif (style=="ExtraBoldItalic")
style="ExtraBold Italic"
elseif (style=="MediumItalic")
style="Medium Italic"
elseif (style=="LightItalic")
style="Light Italic"
elseif (style=="HeavyItalic")
style="Heavy Italic"
Generate($argv[i]:r + format)

I'm aware there would be cleaner ways of doing it, like using Case, if Bash supports it, or converting it to Python, but for now I'm keeping it simple. Ideally, the script would look for a capital letter in the Style string and add a space before it where it isn't the first letter.
In any case, the above doesn't work, as GetTTFName() always returns an empty string. The parameters for the Set and GetTTFName() function is referring to is

Does anyone here know enough Bash scripting, in particularly with Fontforge, to see the problem?

Martin Andersen's picture
Joined: 9 Apr 2011 - 7:54am

ok, I established that Fontforge uses its own form of scripting language, described here:
but that still doesn't explain why GetTTFName(0x409,2) returns an empty string, when it clearly has the TTF subfamily set when you open it up. Fontforge also does Python scripting. but I know virtually nothing of it, and it would be too difficult and timeconsuming to learn it just for this.
I guess there is nothing for it but to open up each newly-generated font and fixing it by hand.

Khaled Hosny's picture
Joined: 29 Aug 2007 - 4:57am

Postscript fonts don't have a names table, even for TTF names FontForge seems to return empty strings for TTF names corresponding to PostScript names (i.e. what you see in the PS Names tab), instead you can use the builtin variables:


Style is usually what is after the hyphen in $fontname, you can then used SetTTFname() to set the new values as you like.

Michel Boyer's picture
Joined: 2 Jun 2007 - 1:01pm

You can get the English (US) "TTF Names" as seen by FontForge with the following bash script that calls fontforge on a python script (here FontForge is used as a Python interpreter):

#!/usr/bin/env fontforge -lang=py

import fontforge,sys[1])
nametbl= fnt.sfnt_names
for N in nametbl:
  if (N[0] == 'English (US)'):
    print "%-20s %s" % (N[1]+":", N[2])


Adam Twardoch's picture
Joined: 3 Dec 2002 - 7:36pm


if you're on Mac OS X, you could just as easily use makeotf from the Adobe FDK for OpenType package. It's a console application, and you can specify the "name" table entries in the feature definition file or the project file.