use*_*416 8 silverlight fonts silverlight-4.0
在silverlight 4中,我需要知道机器中的所有字体名称.使用....
...
var typefaces = System.Windows.Media.Fonts.SystemTypefaces;
foreach (System.Windows.Media.Typeface face in typefaces)
{
System.Windows.Media.GlyphTypeface a;
face.TryGetGlyphTypeface(out a);
FontSource fs = new FontSource(a);
var b = a.FontFileName;
Run Code Online (Sandbox Code Playgroud)
...
我只能得到FontFileName但实际上我们需要字体名来显示它....
怎么能得到这样的信息?
谢谢大家!
WPF 具有执行此操作的属性,但 Silverlight 没有。
\n\n如果您在调试器中查看 System.Windows.Media.Typeface 对象,除了 2 个版本号和 FontUri(读取文件名)之外,字体不包含任何内容。
\n\n您可以通过在 WPF 下运行代码来生成查找字典,以提取所有文件名和匹配的字体名,但您需要在安装了要覆盖的每种字体的计算机上执行此操作。
\n\n下面的 WPF 代码提取这样一个表(该表包含所有语言的字体名称,因此您可能需要向其中添加一个过滤器,例如通过“en-us”):
\n\n foreach (var font in System.Windows.Media.Fonts.SystemTypefaces)\n {\n System.Windows.Media.GlyphTypeface glyphTypeface;\n font.TryGetGlyphTypeface(out glyphTypeface);\n var dictionary = font.FaceNames;\n foreach (var language in dictionary.Keys)\n {\n Debug.WriteLine(string.Format("\\"{0}\\", \\"{1}\\", \\"{2}\\"", glyphTypeface.FontUri.Segments[glyphTypeface.FontUri.Segments.Count()-1], language, dictionary[language]));\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n\n部分输出如下所示,可以轻松格式化为表格或在 Silverlight 中作为字典加载:
\n\n"ARIAL.TTF", "ca-es", "Normal"\n"ARIAL.TTF", "cs-cz", "oby\xc4\x8dejn\xc3\xa9"\n"ARIAL.TTF", "da-dk", "normal"\n"ARIAL.TTF", "de-de", "Standard"\n"ARIAL.TTF", "el-gr", "\xce\x9a\xce\xb1\xce\xbd\xce\xbf\xce\xbd\xce\xb9\xce\xba\xce\xac"\n"ARIAL.TTF", "en-us", "Regular"\n"ARIAL.TTF", "es-es", "Normal"\n"ARIAL.TTF", "es-mx", "Normal"\n"ARIAL.TTF", "eu-es", "Arrunta"\n"ARIAL.TTF", "fi-fi", "Normaali"\n"ARIAL.TTF", "fr-ca", "Normal"\n"ARIAL.TTF", "fr-fr", "Normal"\n"ARIAL.TTF", "hu-hu", "Norm\xc3\xa1l"\n"ARIAL.TTF", "it-it", "Normale"\n"ARIAL.TTF", "nb-no", "Normal"\n"ARIAL.TTF", "nl-nl", "Standaard"\n"ARIAL.TTF", "pl-pl", "Normalny"\n"ARIAL.TTF", "pt-br", "Normal"\n"ARIAL.TTF", "pt-pt", "Normal"\n"ARIAL.TTF", "ru-ru", "\xd0\x9e\xd0\xb1\xd1\x8b\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb9"\n"ARIAL.TTF", "sk-sk", "Norm\xc3\xa1lne"\n"ARIAL.TTF", "sl-si", "Navadno"\n"ARIAL.TTF", "sv-se", "Normal"\n"ARIAL.TTF", "tr-tr", "Normal"\n"ARIAL.TTF", "vi-vn", "th\xc6\xb0\xe1\xbb\x9dng"\n"ARIALN.TTF", "en-us", "Narrow"\n"ARIALI.TTF", "ca-es", "Cursiva"\n"ARIALI.TTF", "cs-cz", "kurz\xc3\xadva"\n"ARIALI.TTF", "da-dk", "kursiv"\n"ARIALI.TTF", "de-de", "Kursiv"\n"ARIALI.TTF", "el-gr", "\xce\xa0\xce\xbb\xce\xac\xce\xb3\xce\xb9\xce\xb1"\n"ARIALI.TTF", "en-us", "Italic"\n"ARIALI.TTF", "es-es", "Cursiva"\n"ARIALI.TTF", "es-mx", "Cursiva"\n"ARIALI.TTF", "eu-es", "Etzana"\n"ARIALI.TTF", "fi-fi", "Kursivoitu"\n"ARIALI.TTF", "fr-ca", "Italique"\n"ARIALI.TTF", "fr-fr", "Italique"\n"ARIALI.TTF", "hu-hu", "D\xc5\x91lt"\n"ARIALI.TTF", "it-it", "Corsivo"\n"ARIALI.TTF", "nb-no", "Kursiv"\n"ARIALI.TTF", "nl-nl", "Cursief"\n"ARIALI.TTF", "pl-pl", "Kursywa"\n"ARIALI.TTF", "pt-br", "It\xc3\xa1lico"\n"ARIALI.TTF", "pt-pt", "It\xc3\xa1lico"\n"ARIALI.TTF", "ru-ru", "\xd0\x9a\xd1\x83\xd1\x80\xd1\x81\xd0\xb8\xd0\xb2"\n"ARIALI.TTF", "sk-sk", "Kurz\xc3\xadva"\n"ARIALI.TTF", "sl-si", "Po\xc5\xa1evno"\n"ARIALI.TTF", "sv-se", "Kursiv"\n"ARIALI.TTF", "tr-tr", "\xc4\xb0talik"\n"ARIALI.TTF", "vi-vn", "nghi\xc3\xaang"\n"ARIALNI.TTF", "en-us", "Narrow"\n"ARIALBD.TTF", "ca-es", "Negreta"\n"ARIALBD.TTF", "cs-cz", "tu\xc4\x8dn\xc3\xa9"\n"ARIALBD.TTF", "da-dk", "fed"\n"ARIALBD.TTF", "de-de", "Fett"\n"ARIALBD.TTF", "el-gr", "\xce\x88\xce\xbd\xcf\x84\xce\xbf\xce\xbd\xce\xb1"\n"ARIALBD.TTF", "en-us", "Bold"\n"ARIALBD.TTF", "es-es", "Negrita"\n"ARIALBD.TTF", "es-mx", "Negrita"\n"ARIALBD.TTF", "eu-es", "Lodia"\n"ARIALBD.TTF", "fi-fi", "Lihavoitu"\nRun Code Online (Sandbox Code Playgroud)\n