在 PowerShell 中确定 OpenType 字体的确切名称

Determine exact name of an OpenType font in PowerShell

我有一组 OpenType 字体文件,它们都是同一家族的不同风格:

为了通过 PowerShell 安装这些字体并将它们正确添加到注册表中,我需要知道它们的友好样式名称。

当我通过 Windows Explorer 安装 "FreigSanLFProBol.otf" 时,注册表项包含以下数据:

{
  name: "FreightSansLFPro Bold (TrueType)",
  type: REG_SZ,
  data: "FreigSanLFProBol.otf"
}

问题是我不知道如何以编程方式从字体文件本身识别 "name" 键中的值。

使用 中提供的信息,我能够完成大部分工作:

$path = "C:\Windows\Fonts\FreigSanLFProBol.otf"
Add-Type -AssemblyName System.Drawing
$fontCollection = New-Object System.Drawing.Text.PrivateFontCollection
$fontCollection.AddFontFile($(Get-Item $path).fullname)
$fontCollection.Families[-1].Name

这给了我 "FreightSansLFPro" 的结果——这与给它 "FreightSansLFPro Bold" 的注册表键值不同。 (尽管它是 OpenType 字体,但注册键仍然将类型列为 "TrueType Font" 的事实没关系)。

它从哪里获取 "Bold",我如何以编程方式从字体文件中获取特定的 value/name?

$folder = "C:\Windows\fonts\"

$objShell = New-Object -ComObject Shell.Application 


$fileList = @() 
$attrList = @{} 
$details = ( "Title",
              "Font style",
              "Show/hide", 
              "Designed for",
              "Category",
              "Designer/foundry" ,
               "Font Embeddability",
               "Font type",
               "Family",
               "Date created",
               "Date modified",
               "Collection",
               "Font file names",
               "Font version"
                 ) 

 #figure out what the possible metadata is
$objFolder = $objShell.namespace($folder) 
for ($attr = 0 ; $attr  -le 500; $attr++) 
{ 
    $attrName = $objFolder.getDetailsOf($objFolder.items, $attr) 
    if ( $attrName -and ( -not $attrList.Contains($attrName) )) 
    {  
        $attrList.add( $attrName, $attr )  
    } 
} 

 #$attrList

 #loop through all the fonts, and process
     $objFolder = $objShell.namespace($folder) 
    foreach($file in $objFolder.items()) 
    { 
        foreach( $attr in $details) 
        { 

            $attrValue = $objFolder.getDetailsOf($file, $attrList[$attr]) 
            if ( $attrValue )  
            {  
                Add-Member -InputObject $file -MemberType NoteProperty -Name $attr -value $attrValue 
            }  
        } 
        $fileList += $file 
        write-verbose "Prcessing file number $($fileList.Count)"
    } 


$fileList | select $details |  out-gridview

来源:https://powershell.org/forums/topic/listing-font-details/