【发布时间】:2018-11-01 21:53:25
【问题描述】:
我有一组 OpenType 字体文件,它们都是同一家族的不同风格:
- “FreigSanLFProBol.otf”(FreightSansLFPro 粗体)
- “FreigSanLFProBoo.otf” (FreightSansLFPro 常规)
- "FreigSanLFProBooIta.otf" (FreightSansLFPro 斜体)
为了通过 PowerShell 安装这些字体并将它们正确添加到注册表,我需要知道它们的友好样式名称。
当我通过 Windows 资源管理器安装“FreigSanLFProBol.otf”时,注册表项包含以下数据:
{
name: "FreightSansLFPro Bold (TrueType)",
type: REG_SZ,
data: "FreigSanLFProBol.otf"
}
问题是我不知道如何从字体文件本身以编程方式识别“名称”键中的值。
使用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”的结果 - 这与将其作为“FreightSansLFPro Bold”的 reg 键值不同。 (不要介意 reg 键仍然将类型列为“TrueType 字体”,即使它是 OpenType 字体)。
它从哪里获得“粗体”,我如何以编程方式从字体文件中获取该特定值/名称?
【问题讨论】:
标签: powershell fonts powershell-4.0