获取.TTF文件的字体名称字体、名称、文件、TTF

2023-09-02 21:37:00 作者:闭月羞花羞迩妈

让我们说有一个.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:PrivateFontCollection, 的FontFamily