获取.TTF文件的字体名称 [英] Get font name of .ttf file
问题描述
让我们说有一个.TTF(True Type字体)文件。您可以在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
实例,并获得其名称
属性。
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:<一href="http://msdn.microsoft.com/en-us/library/system.drawing.text.privatefontcollection.aspx">PrivateFontCollection, 的FontFamily
这篇关于获取.TTF文件的字体名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!