获取 .ttf 文件的字体名称 [英] Get font name of .ttf file

查看:60
本文介绍了获取 .ttf 文件的字体名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个 .ttf(True Type Font)文件.您可以通过单击将其安装在 Windows 上.字体的真实名称不是 .tff 之前的文本(可以说 SuperFont.ttf => 所以名称不是SuperFont"——它可能是,但大部分不是).我想阅读 .tff(不知何故?)并获取字体的名称(不安装字体).有什么想法吗?

Lets say there is a .ttf (True Type Font) file. You can install it on windows with a click. The real name of the font is not the text that is before the .tff (lets say SuperFont.ttf => so the name is not "SuperFont" - it could be, but mostly not). I would like to read the .tff (somehow?) and get the name (without installing the font) of the font. Any ideas?

推荐答案

您需要将字体添加到私有集合 (PrivateFontCollection),然后请求 FontFamily 实例并获取其 Name 属性.

You'll need to add the font to a private collection (PrivateFontCollection), then request the FontFamily instance and get its Name property.

像这样:

PrivateFontCollection fontCol = new PrivateFontCollection();
fontCol.AddFontFile(@"PATH TO FONT");
Console.WriteLine(fontCol.Families[0].Name);

您将需要命名空间:

using System.Drawing;
using System.Drawing.Text;

MSDN:PrivateFontCollectionFontFamily

这篇关于获取 .ttf 文件的字体名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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