[英]How to determine the O/S filename of an installed font?
We use a third-party PDF Generator library which requires that you specify the TrueType or Type1 file name when using a font other than the 14 or so that are part of the default PDF standard. 我们使用第三方PDF Generator库,当使用默认PDF标准的14左右字体以外的其他字体时,要求您指定TrueType或Type1文件名。
So if I want to use Bitstream Arrus Bold
I have to know to reference arrusb.ttf
. 因此,如果我想使用
Bitstream Arrus Bold
,则必须知道引用arrusb.ttf
。
Short of enumerating all of the files in the font folder and creating a disposable PrivateFontCollection to extract the relationships, is there a way to obtain the underlying font name from font information, ie given Courier New, Bold, Italic derive CourBI.ttf
? 除了枚举字体文件夹中的所有文件并创建用于处理关系的一次性PrivateFontCollection之外,还有没有办法从字体信息中获取基础字体名称,即给定Courier New,Bold,Italic派生
CourBI.ttf
?
I've already looked at the InstalledFontCollection and there's nothing. 我已经看过InstalledFontCollection,什么也没有。
If you don't mind poking around in the registry, take a look at 如果您不介意在注册表中四处浏览,请查看
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts
It has pairs like 它有像
Name = "Arial (TrueType)"
Data = "arial.ttf"
You can do this the necessary queries like this: 您可以这样执行必要的查询:
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;
}
A call to GetFontFile("Arial (TrueType)")
returns "arial.ttf"
调用
GetFontFile("Arial (TrueType)")
返回"arial.ttf"
You could of course modify the code to append the (TrueType)
portion to the fontName
, or to look through everything returned by fontsKey.GetValueNames()
to find the best match. 您当然可以修改代码,将
(TrueType)
部分附加到fontName
,或浏览fontsKey.GetValueNames()
返回的所有内容以找到最佳匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.