Results 1 to 25 of 25

Thread: [VB6] Parse Font Name from TTF File/Data

Threaded View

  1. #1

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    [VB6] Parse Font Name from TTF File/Data

    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:

    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
    Attached Files Attached Files
    Last edited by LaVolpe; May 23rd, 2017 at 05:55 PM. Reason: changed file routine to request read access only

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width