Goal: Get the font name from the source itself: TTF file
Good specifications source found here
Updated to include parsing TTC font files
Did not want to have to install a font to get the information. Wanted to know how to do this, so did some research & played around.
Some caveats first...
- This has not been extremely vetted. Only tested on a few hundred font files ;)
- Does not give you any other font information; parsing font files is kinda intense
- Will only return a font name if it has been included as a Microsoft format; common but not 100%
- May need some more playing, but it suits my needs & thought I'd share it
I'm including two sample versions: 1) for files using VB file's Open; modify to use APIs for unicode paths/file names and 2) for arrays, should you have the font available that way
The functions provided offer an option to return the font name in the language you want, if it it exists in that language within the source file. The language requested is passed by LCID value, i.e., 1033 for English. The default is English if no LCID is passed or if the font name is not provided in the language requested.
Each version can be used to get the font names from both TrueType font files and TTC (font collection) files. The TTC files can contain 1 to several different fonts. When parsing a TTC file, the function should be called twice: once to get the 1st font name found and the total number of fonts in the file. And again, if the other font names are wanted, for each additional font, example, changing the path & file you want:
Good specifications source found here
Updated to include parsing TTC font files
Did not want to have to install a font to get the information. Wanted to know how to do this, so did some research & played around.
Some caveats first...
- This has not been extremely vetted. Only tested on a few hundred font files ;)
- Does not give you any other font information; parsing font files is kinda intense
- Will only return a font name if it has been included as a Microsoft format; common but not 100%
- May need some more playing, but it suits my needs & thought I'd share it
I'm including two sample versions: 1) for files using VB file's Open; modify to use APIs for unicode paths/file names and 2) for arrays, should you have the font available that way
The functions provided offer an option to return the font name in the language you want, if it it exists in that language within the source file. The language requested is passed by LCID value, i.e., 1033 for English. The default is English if no LCID is passed or if the font name is not provided in the language requested.
Each version can be used to get the font names from both TrueType font files and TTC (font collection) files. The TTC files can contain 1 to several different fonts. When parsing a TTC file, the function should be called twice: once to get the 1st font name found and the total number of fonts in the file. And again, if the other font names are wanted, for each additional font, example, changing the path & file you want:
Code:
Dim sFontName As String, sFile As String, Index As Long, f As Long
sFile = "c:\windows\fonts\cambria.ttc"
sFontName = pvParseFontNameFromFile(sFile, Index)
Debug.Print sFile
Debug.Print vbTab; "Font: "; sFontName; " Nr Fonts: "; Index
For Index = 1 To Index - 1
sFontName = pvParseFontNameFromFile(sFile, Index)
If Index = 0 Then Exit For
Debug.Print vbTab; "Additional Font: "; sFontName
Next