I have a collection of OpenType font files which are all different styles of the same family:
- "FreigSanLFProBol.otf" (FreightSansLFPro Bold)
- "FreigSanLFProBoo.otf" (FreightSansLFPro Regular)
- "FreigSanLFProBooIta.otf" (FreightSansLFPro Italic)
In order to install these fonts via PowerShell and properly add them to the registry, I need to know their friendly style name.
When I install "FreigSanLFProBol.otf" via Windows Explorer, the registry key contains this data:
{
name: "FreightSansLFPro Bold (TrueType)",
type: REG_SZ,
data: "FreigSanLFProBol.otf"
}
The problem is I have no idea how to programmatically identify the value in the "name" key from the font file itself.
Using the information available in Name of font by powershell, I was able to get most of the way there:
$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
That gives me the result of "FreightSansLFPro" - which is different than the reg key value which gives it as "FreightSansLFPro Bold". (Never mind the fact that the reg key still lists the type as "TrueType Font" even though it's an OpenType Font).
Where does it get "Bold" from, and how do I get that specific value/name from the font file programmatically?