9

It seems like an easy question, how can I get the actual name of font from command line.

Here is an example. The font filename is segoesc.ttf. However, the actual name of font that shows up in the Font Menu is Segoe Script.

enter image description here

What I have tried:

  1. There is a python script out there, that can get the font name. But I prefer not to have Python dependency.

  2. Right clicking on Fontfile and go to Properties > Details, gives me the list of properties. I tried to use wmic but it does not show Title property.

wmic datafile "c:\Windows\fonts\segoesc.ttf" get Title

Thanks.

2
  • Possibly related: How to list installed font families?
    – nekketsuuu
    Commented Jan 14, 2020 at 12:59
  • invalid query. any idea how i would also get the company, author, copyright, legal trademark, etc fields of metadata from a font file on windows?
    – oldboy
    Commented Jan 22, 2020 at 6:37

4 Answers 4

12

In PowerShell:

(New-Object -TypeName Windows.Media.GlyphTypeface -ArgumentList 'C:\Windows\Fonts\segoesc.ttf').Win32FamilyNames.Values

Returns Segoe Script

Credit to Samuel Leslie and PSWinGlue.

1
  • 6
    Remember to load the assembly first: Add-Type -AssemblyName PresentationCore.
    – arielCo
    Commented Dec 16, 2020 at 13:54
6

Try this small C program compiled with Microsoft Visual C++:

#include <stdlib.h>
#include <stdio.h>

#define QFR_DESCRIPTION 1

/* Link with GDI32 library */
int GetFontResourceInfoW(
    wchar_t* lpszFilename,
    unsigned long* cbBuffer,
    void* lpBuffer,
    unsigned long dwQueryType);

int wmain(int wargc, wchar_t** wargv) {
    int res = 0, size = 0;

    if (wargc == 2) {
        res = GetFontResourceInfoW(wargv[1], &size, NULL, QFR_DESCRIPTION);
        wchar_t* buff = malloc(size);
        res = GetFontResourceInfoW(wargv[1], &size, buff, QFR_DESCRIPTION);
        if (res)
            wprintf(L"Description: %ls\n", buff);
        free(buff);
    }

    return 0;
}
  • Command Line example: ProgramName.exe C:\path\to\font.ttf

Further Readings:

1

Every (script) language which is able to handle COM objects (J-/vbscript/PowerShell) can get extended file attributes with Shell.Application

This PowerShell script lists Extended Atrributes typical for font files

$path        = 'A:\segoescb.ttf'
$folder      = Split-Path $path
$file        = Split-Path $path -Leaf

$shell       = New-Object -COMObject Shell.Application
$shellfolder = $shell.Namespace($folder)
$shellfile   = $shellfolder.ParseName($file)

## get (localized) description and value of 
##   specified extended attributes numbers
## (0,2,21,165,166,195) 

(0,1,2,3,4,5,6,9,10,19,21,25,33,34,58,62,165,166,167,170,191,192,193,195,197,203,255)| 
Foreach-Object { 
    '{0,3} {1,-30} = {2}' -f $_,
            $shellfolder.GetDetailsOf($null, $_), 
            $shellfolder.GetDetailsOf($shellfile, $_) 
}

sample (German) output:

  0 Name                           = segoescb.ttf
  1 Größe                          = 567 KB
  2 Elementtyp                     = IrfanView TTF File
  3 Änderungsdatum                 = 2018-04-12 01:34
  4 Erstelldatum                   = 2019-05-07 15:46
  5 Letzter Zugriff                = 2019-05-07 15:46
  6 Attribute                      = AC
  9 Erkannter Typ                  = Nicht angegeben
 10 Besitzer                       = xxxxxxxx\LotPings
 19 Bewertung                      = Nicht bewertet
 21 Titel                          = Segoe Script Bold
 25 Copyright                      = © 2016 Microsoft Corporation. All Rights Reserved.
 33 Firma                          = Microsoft Corporation
 34 Dateibeschreibung              =
 58 Gesamtgröße                    = 0,99 GB
 62 Computer                       = xxxxxxxx (dieser PC)
165 Dateierweiterung               = .ttf
166 Dateiname                      = segoescb.ttf
167 Dateiversion                   = 5.02
170 Freier Speicherplatz           = 998 MB
191 Ordnername                     = A:\
192 Ordnerpfad                     = A:\
193 Ordner                         = A:\
195 Pfad                           = A:\segoescb.ttf
197 Typ                            = IrfanView TTF File
203 Verknüpfungsstatus             = Nicht aufgelöst
255 Verwendeter Speicherplatz      = ‎2%

So the absolute minimum would be 0 or 166 and 21.

4
  • how do i get the individual extended attributes of a font file with a one-liner powershell statement?
    – oldboy
    Commented Jan 22, 2020 at 6:40
  • can it be done in a one-line statement?
    – oldboy
    Commented Jan 22, 2020 at 7:00
  • Believe it or not, none of the extended file attributes are used for "Font name" in that font UI. Often "Title" (21) is the same "Font name", but not always.
    – Jason
    Commented Feb 5, 2020 at 18:17
  • @oldboy: look at Jason's answer and the documentation for GlyphTypeface.
    – arielCo
    Commented Dec 16, 2020 at 13:58
0

The following method retrieves all installed fonts and creates separate glyphTypeface data based on their file names. Afterward, you can use the file names to locate the relevant data and extract the desired fields (not limited to Win32FamilyNames).

Add-Type -AssemblyName PresentationCore
$glyphTypefaceMap = @{}
foreach ($regPath in @(
    # You can find your font in these two locations if it is already installed.
    'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', # Local Machine
    'HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' # Current User
)) {
    $fontList = Get-ItemProperty $regPath
    foreach ($_ in ($fontList | Get-Member -MemberType NoteProperty)) {
        $propertyName = $_.Name
        if (!($propertyName.Contains("TrueType"))) {
            continue
        }
        $value = $fontList.$propertyName
        $fontPath = ""
        if (Test-Path $value) {
            $fontPath = $value
        } else {
            $fontPath = Join-Path $env:SystemRoot fonts/$value
        }

        if (!(Test-Path $fontPath)) {
            Write-Verbose "path not exits: $value" # Test-Path "C:\...\RobotoFlex[GRAD,wght].ttf" will get false even exists.
            continue
        }

        $glyphTypeface = New-Object -TypeName Windows.Media.GlyphTypeface -ArgumentList $fontPath
        # Wait-Debugger
        $name = (Get-Item ($glyphTypeface.FontUri.LocalPath)).Name # xxx.ttf
        $glyphTypefaceMap[$name] = $glyphTypeface
    }
}
# Now you can use the font file name to locate the data you need 
# and select the desired fields from the font.
# For example,
$glyphTypefaceMap["Arial.ttf"]
$glyphTypefaceMap["Arial.ttf"].Win32FamilyNames

enter image description here

$glyphTypefaceMap.GetEnumerator() | foreach { "$($_.Value.FontUri.LocalPath) $($_.Value.Win32FamilyNames)"}
<#
output:

C:\WINDOWS\fonts\msjhbd.ttc [en-US, Microsoft JhengHei] [zh-HK, 微軟正黑體] [zh-TW, 微軟正黑體]
C:\WINDOWS\fonts\mingliu.ttc [en-US, MingLiU] [zh-HK, 細明體] [zh-TW, 細明體]
...
#>
2
  • Thank you. Will try it out Commented Jun 13, 2023 at 13:36
  • 1
    I have turned this script into a command, which you can refer to in this project.
    – Carson
    Commented Jun 14, 2023 at 2:14

You must log in to answer this question.

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