代码之家  ›  专栏  ›  技术社区  ›  Bill

如何确定已安装字体的O/S文件名?

  •  2
  • Bill  · 技术社区  · 16 年前

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

    CourBI.ttf ?

    1 回复  |  直到 16 年前
        1
  •  5
  •   Daniel LeCheminant    16 年前

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

    Name = "Arial (TrueType)"
    Data = "arial.ttf"
    

    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() 找到最好的匹配。