如何确定已安装字体的O/S文件名? [英] How to determine the O/S filename of an installed font?

查看:93
本文介绍了如何确定已安装字体的O/S文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用第三方PDF生成器库,当使用默认PDF标准的14左右字体以外的其他字体时,要求您指定TrueType或Type1文件名.

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.

所以如果我想使用Bitstream Arrus Bold,我必须知道引用arrusb.ttf.

So if I want to use Bitstream Arrus Bold I have to know to reference arrusb.ttf.

枚举字体文件夹中的所有文件并创建用于处理关系的一次性PrivateFontCollection的简短操作,是否有一种方法可以从字体信息中获取基础字体名称,即给定Courier New,Bold,Italic派生CourBI.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, i.e. given Courier New, Bold, Italic derive CourBI.ttf?

我已经看过InstalledFontCollection,什么也没有.

I've already looked at the InstalledFontCollection and there's nothing.

推荐答案

如果您不介意注册表中的内容,请查看

If you don't mind poking around in the registry, take a look at

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts

它具有类似

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;
}

GetFontFile("Arial (TrueType)")的调用返回"arial.ttf"

您当然可以修改代码,将(TrueType)部分附加到fontName,或者浏览fontsKey.GetValueNames()返回的所有内容以找到最佳匹配.

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.

这篇关于如何确定已安装字体的O/S文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆