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

时间:2018-05-23 03:28:24

标签: powershell fonts powershell-v4.0

我有一组OpenType字体文件,它们是同一系列的所有不同风格:

  • “FreigSanLFProBol.otf”(FreightSansLFPro Bold)
  • “FreigSanLFProBoo.otf” (FreightSansLFPro常规)
  • “FreigSanLFProBooIta.otf” (FreightSansLFPro Italic)

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

当我通过Windows资源管理器安装“FreigSanLFProBol.otf”时,注册表项包含以下数据:

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

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

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

$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”的结果 - 这与reg键值不同,后者将其赋予“FreightSansLFPro Bold”。 (不要紧,reg键仍然将类型列为“TrueType字体”,即使它是OpenType字体)。

它从哪里获得“Bold”,以及如何以编程方式从字体文件中获取该特定值/名称?

0 个答案:

没有答案