如何知道silverlight中的本地字体名称
在 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;
...
我只能获取FontFileName,但实际上我们需要字体名来显示它......
如何获得这样的信息?
谢谢大家!
in silverlight 4 I need to know all the font names in my machines.
Using....
...
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;
...
I only can get FontFileName but actually we'd need the fontname for showing it....
How can get such info?
thanks you all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为 Silverlight 生成查找表:
WPF 具有执行此操作的属性,但 Silverlight 没有。
如果您在调试器中查看 System.Windows.Media.Typeface 对象,除了 2 个版本号和 FontUri(读取文件名)之外,字体不包含任何内容。
您可以通过在 WPF 下运行代码来生成查找字典,以提取所有文件名和匹配的字体名,但您需要在安装了要覆盖的每种字体的计算机上执行此操作。
下面的 WPF 代码提取这样一个表(该表包含所有语言的字体名称,因此您可能需要向其中添加一个过滤器,例如通过“en-us”):
部分输出如下所示,可以很容易地在 Silverlight 中格式化为表或作为字典加载:
Generate a lookup table for Silverlight:
WPF has the properties to do this, but Silverlight does not.
If you look at the System.Windows.Media.Typeface objects in the debugger the fonts do not contain anything except 2 version numbers and the FontUri (read filename).
You could generate a lookup dictionary by running code under WPF to extract all the filenames and matching fontnames, but you need to do that on a machine with every font installed that you want to cover.
The WPF code below extracts such a table (this one contains the font names in all languages, so you will probably want to add a filter to it e.g. by "en-us"):
Part of the output is shown below and could be easily formatted into a table or loaded as a dictionary in Silverlight:
查看此答案。
我最终使用了
Fonts.SystemFontFamilies
在 SERVER(PresentationCore dll 中)上,通过服务调用将结果(来自Source
属性)发送到 Silverlight 应用程序。不完美,但我能找到的最好的。See this answer.
I ended up using
Fonts.SystemFontFamilies
on the SERVER (in the PresentationCore dll), sending the result (from theSource
property) via a service call to the Silverlight app. Not perfect, but the best I could find.我还尝试使用 System.Windows.Media.Fonts.SystemTypefaces 但正如您提到的它只提供字体文件名。在网上进行了大量阅读和研究后,我决定使用 P/Invoke 来解决这个问题。如果您可以像我一样选择以 OOB(浏览器外)方式运行应用程序并提高信任度,那么以下 P/Invoke 解决方案将会非常有效。感谢 www.pinvoke.net 提供的所有方法/结构定义。
使用该类非常简单。下面是一个示例 XAML 标记
在 XAML 页面的代码后面,添加以下内容
I also tried to use
System.Windows.Media.Fonts.SystemTypefaces
but as you mentioned it only gives the font file name. After doing a lot of reading and research on the web, I decided to use P/Invoke to solve this. If you have the choice of running your application as OOB (Out of Browser) with elevated trust as I had, the following P/Invoke solution will work great. Thanks to www.pinvoke.net for all of the method/structure definitions.Using the class is very simple. Below is a sample XAML markup
In the code behind of the XAML page, add the following