我们使用第三方 PDF 生成器库,该库要求您在使用默认 PDF 标准中的 14 种左右字体以外的字体时指定 TrueType 或 Type1 文件名。
因此,如果我想使用 Bitstream Arrus Bold
,我必须知道引用 arrusb.ttf
。
除了枚举字体文件夹中的所有文件并创建一次性 PrivateFontCollection 来提取关系之外,有没有办法从字体信息中获取底层字体名称,即给定 Courier New、Bold、Italic 派生 CourBI.ttf
?
我已经查看了 InstalledFontCollection,但什么也没有。
最佳答案
如果您不介意在注册表中查看,请查看
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts
它有像
这样的对Name = "Arial (TrueType)"
Data = "arial.ttf"
您可以像这样执行必要的查询:
static RegistryKey fontsKey =
Registry.LocalMachine.OpenSubKey(
@"Software\Microsoft\Windows NT\CurrentVersion\Fonts");
static public string GetFontFile(string fontName)
{
return fontsKey.GetValue(fontName, string.Empty) as string;
}
调用 GetFontFile("Arial (TrueType)")
返回 "arial.ttf"
您当然可以修改代码以将 (TrueType)
部分附加到 fontName
,或者查看 fontsKey.GetValueNames() 返回的所有内容
找到最佳匹配。
关于c# - 如何确定已安装字体的操作系统文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/637124/