使用….
…
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;
…
我只能得到Fontfilename,但实际上我们需要字体名来显示它….
怎么能得到这样的信息?
谢谢大家!
解决方法 为Silverlight生成查找表:WPF具有执行此 *** 作的属性,但Silverlight没有.
如果查看调试器中的System.windows.Media.Typeface对象,则字体不包含除2个版本号和FontUri(读取文件名)之外的任何内容.
您可以通过在WPF下运行代码来生成查找字典,以提取所有文件名和匹配的字体名,但是您需要在安装了要覆盖的每种字体的计算机上执行此 *** 作.
下面的WPF代码提取了这样一个表(这个表包含所有语言的字体名称,所以你可能想要为它添加一个过滤器,例如“en-us”):
foreach (var Font in System.windows.Media.Fonts.SystemTypefaces) { System.windows.Media.GlyphTypeface glyphTypeface; Font.TryGetGlyphTypeface(out glyphTypeface); var dictionary = Font.Facenames; foreach (var language in dictionary.Keys) { DeBUG.Writeline(string.Format("\"{0}\",\"{1}\",\"{2}\"",glyphTypeface.FontUri.Segments[glyphTypeface.FontUri.Segments.Count()-1],language,dictionary[language])); } }
部分输出如下所示,可以轻松地格式化为表格或在Silverlight中作为字典加载:
"ARIAL.TTF","ca-es","normal""ARIAL.TTF","cs-cz","obyčejné""ARIAL.TTF","da-dk","normal""ARIAL.TTF","de-de","Standard""ARIAL.TTF","el-gr","Κανονικά""ARIAL.TTF","en-us","Regular""ARIAL.TTF","es-es","es-mx","eu-es","Arrunta""ARIAL.TTF","fi-fi","normaali""ARIAL.TTF","fr-ca","fr-fr","hu-hu","normál""ARIAL.TTF","it-it","normale""ARIAL.TTF","nb-no","nl-nl","Standaard""ARIAL.TTF","pl-pl","normalny""ARIAL.TTF","pt-br","pt-pt","ru-ru","Обычный""ARIAL.TTF","sk-sk","normálne""ARIAL.TTF","sl-si","Navadno""ARIAL.TTF","sv-se","tr-tr","vi-vn","thường""ARIALN.TTF","Narrow""ARIAli.TTF","Cursiva""ARIAli.TTF","kurzíva""ARIAli.TTF","kursiv""ARIAli.TTF","Kursiv""ARIAli.TTF","Πλάγια""ARIAli.TTF","Italic""ARIAli.TTF","Etzana""ARIAli.TTF","Kursivoitu""ARIAli.TTF","Italique""ARIAli.TTF","Dőlt""ARIAli.TTF","Corsivo""ARIAli.TTF","CursIEf""ARIAli.TTF","Kursywa""ARIAli.TTF","Itálico""ARIAli.TTF","Курсив""ARIAli.TTF","Kurzíva""ARIAli.TTF","Poševno""ARIAli.TTF","İtalik""ARIAli.TTF","nghiêng""ARIALNI.TTF","Narrow""ARIALBD.TTF","Negreta""ARIALBD.TTF","tučné""ARIALBD.TTF","fed""ARIALBD.TTF","Fett""ARIALBD.TTF","Έντονα""ARIALBD.TTF","Bold""ARIALBD.TTF","Negrita""ARIALBD.TTF","Lodia""ARIALBD.TTF","lihavoitu"总结
以上是内存溢出为你收集整理的如何知道silverlight中的本地字体名称全部内容,希望文章能够帮你解决如何知道silverlight中的本地字体名称所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)