C#获取字体版本号

时间:2013-12-03 16:52:11

标签: c# windows fonts true-type-fonts

如何在C#中获取字体的实际版本号?在我的情况下,我需要知道是否安装了版本6.06的Segoe UI Symbol字体。

2 个答案:

答案 0 :(得分:1)

无法在C#中查看字体文件的版本,您只能按名称检查已安装的字体,所以......

我会得到正确文件的名称和哈希值,并将其与目标系统进行比较:

using System.IO;
using System.Security.Cryptography;

...

const string fontFileName = "seguisym.ttf";
const string fontHash = "/O7kUQinASYq8BG6dSY4YXkXQcbCeZQOmAcaWQqPP60OcgbGpXR5+yNug0pceicfHpjxV+6sdmy1j8Np2VIbOQ==";

static bool FontIsInstalled()
{
    string fontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), fontFileName);
    if (!File.Exists(fontPath)) return false;
    using (SHA512Managed sha = new SHA512Managed())
    {
        return fontHash.Equals(Convert.ToBase64String(sha.ComputeHash(File.ReadAllBytes(fontPath))));
    }
}

答案 1 :(得分:1)

我不知道它是否是最近推出的,但到现在为止,可以通过TryGetGlyphTypeface()获取特定字体的字体版本。

Segoe UI示例:

var segoe = new FontFamily("Segoe UI");
var typeface = new Typeface(segoe, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
var isGlyphTypeface = typeface.TryGetGlyphTypeface(out var glyph);
if(isGlyphTypeface)
{
  Console.WriteLine(glyph.Version);
}
相关问题