2

I have a pile of old graphics projects I'm consolidating, and they all saved their fonts. So I have many versions of many common fonts. I'd like to rename the files with the actual font name and version, or possibly other font metadata - some are old enough to have 8.3 filenames.Note that the fonts are NOT installed - they're on external hard drives.

My preference in answers is a single filename as a parameter for:

  1. a single-line invocation of an internal Windows command suitable for cmd.exe batch files
  2. a free external EXE with a single-line invoking command suitable for batch files
  3. a script (VB, Python, PowerShell, whatever) that can be invoked like (2) once saved.
  4. crossing the line of undesirable although possible - a giant table of app properties for all installed files plus a font manager (installer-uninstaller). This I can already do, eventually and problematically.

I've seen software that does pieces of the job, but found no workable answers with repeated searches. Nirsoft will list everything at once for your whole system, but not for uninstalled fonts. WMIC reports (deprecated) and returns nothing. The test code from get-actual-font-name-of-ttf-file-from-command-line returns errors like New-Object : Exception calling ".ctor" with "1" argument(s): "Object reference not set to an instance of an object."

Giacomo1968
  • 58,727
KFW
  • 21

2 Answers2

0

There is no answer for my purposes, as it's not possible to automate.

I tried the True-Type suggestions. Both wmic and powershell threw errors, rather than bad data or good data, but that's neither here nor there - as likely as not my unfamiliarity with their syntax.

I used the C code to find the data in a sample of the files with a hex editor, verifying it with NirSoft's PropertySystemView.

Technically, the approach (reading the TTF tables) works, but older fonts aren't consistent or well-formed enough to use the data without manual intervention.

Multiple names exist in different locations, a useless, incorrect, or missing name may be found in the 'canonical' position, and the same goes for version numbers. Newer fonts have better populated headers, but 1990s fonts not so much so.

If someone else needs this job done in the future, the C code at Get actual Font name of TTF file from Command Line combined with the TrueType (and OpenType, these days) font table spec appears to be the best approach. But the gap between "read a name and read a number" and "read enough names and enough numbers and make the right decisions to produce a reasonable output" was too large for me to bridge.

KFW
  • 21
0

ExifTool can extract the font name and rename the file for you for .ttf/.ttc fonts.

As you say, fonts may not be consistent in where the name is located, as well as having variations in the file. For example, a font on my Windows system

C:\>exiftool -G1 -a -s -*fontname* C:\Windows\Fonts\SitkaZ.ttc
[Font1]         FontName                        : Sitka Small Bold Italic
[Font1]         PostScriptFontName              : SitkaSmall-BoldItalic
[Font1]         FontName-en-US                  : Sitka Small Bold Italic
[Font1]         PostScriptFontName-en-US        : SitkaSmall-BoldItalic
[Font2]         FontName                        : Sitka Text Bold Italic
[Font2]         PostScriptFontName              : SitkaText-BoldItalic
[Font2]         FontName-en-US                  : Sitka Text Bold Italic
[Font2]         PostScriptFontName-en-US        : SitkaText-BoldItalic
[Font3]         FontName                        : Sitka Subheading Bold Italic
[Font3]         PostScriptFontName              : SitkaSubheading-BoldItalic
[Font3]         FontName-en-US                  : Sitka Subheading Bold Italic
[Font3]         PostScriptFontName-en-US        : SitkaSubheading-BoldItalic
[Font4]         FontName                        : Sitka Heading Bold Italic
[Font4]         PostScriptFontName              : SitkaHeading-BoldItalic
[Font4]         FontName-en-US                  : Sitka Heading Bold Italic
[Font4]         PostScriptFontName-en-US        : SitkaHeading-BoldItalic
[Font5]         FontName                        : Sitka Display Bold Italic
[Font5]         PostScriptFontName              : SitkaDisplay-BoldItalic
[Font5]         FontName-en-US                  : Sitka Display Bold Italic
[Font5]         PostScriptFontName-en-US        : SitkaDisplay-BoldItalic
[Font6]         FontName                        : Sitka Banner Bold Italic
[Font6]         PostScriptFontName              : SitkaBanner-BoldItalic
[Font6]         FontName-en-US                  : Sitka Banner Bold Italic
[Font6]         PostScriptFontName-en-US        : SitkaBanner-BoldItalic

They can also be inconsistent with the names

C:\>exiftool -G1 -a -s -e C:\Windows\Fonts\18cents.ttf  -*fontname* 
[Font]          FontName                        : New
[Font]          PostScriptFontName              : New
[Font]          FontName-en-US                  : 18thCentury
[Font]          PostScriptFontName-en-US        : 18thCentury

An additional thing is that the name tags can be specific to certain languages. For example, you can have FontName-fi, FontName-de-DE, or PostScriptFontName-es-MX.

Because of all of these variations, it would be very difficult to create a perfect exiftool command. But this would be a basic example of a command, assuming -en-US as the default language

exiftool -ext ttf -ext ttc "-FileName=!Manual rename %f.%e" "-FileName<PostScriptFontName-en-US.%e" "-FileName<FontName-en-US.%e" "-FileName<PostScriptFontName.%e" "-FileName<FontName.%e" /path/to/files/

This command gives priority renaming from back to front of the command depending upon the tags in the file, i.e. "-filename<FontName.%e" will be used if FontName exists, otherwise PostScriptFontName, then FontName-en-US, etc. If none of the tags exists, then it will prepend !Manual rename to the front of the filename for manual processing. See Note #1 under the -TAG[+-^]=[VALUE] option.

The -ext (-extension) option is used to limit processing to .ttf/.ttc files. The -r (-recurse) option can be added to recurse into subdirectories.

You can do a test run by using Testname instead of FileName.
exiftool -ext ttf -ext ttc "-Testname=!Manual rename %f.%e" "-Testname<PostScriptFontName-en-US.%e" "-Testname<FontName-en-US.%e" "-Testname<PostScriptFontName.%e" "-Testname<FontName.%e" /path/to/files/

StarGeek
  • 1,644