Mono PrivateFontCollection.AddFontFile 错误的解决方法

Workaround for the Mono PrivateFontCollection.AddFontFile bug(Mono PrivateFontCollection.AddFontFile 错误的解决方法)
本文介绍了Mono PrivateFontCollection.AddFontFile 错误的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Mono.net 中调用 PrivateFontCollection.AddFontFile 方法时,它总是返回一个标准字体系列.这个错误已经在几个网站上报告过,但据我所知,没有办法解决它.该错误本身尚未在 Mono 库中修复.有什么解决办法吗?

When I call the PrivateFontCollection.AddFontFile method in Mono.net It always returns a standard font-family. This bug has already been reported on several websites, but as far as I know without a way to solve it. The bug itself isn't fixed in the Mono-libraries yet. Is there any workaround for it?

作为对追随者回答的回应,我将发布代码:

As a reaction on henchman's answer I will post the code:

PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile("myFontFamily.ttf");
myFontFamily = pfc.Families[0x00];
Font myFont = new Font(myFontFamily,14.0f);

我知道这段代码在 Microsoft.Net 框架上可以正常工作,但是在 Mono 上执行时,它只是给出了一个名为 myFontFamily.ttf 的标准字体系列(我认为它是 Arial)

I know this code will work fine on the Microsoft.Net framework, but when executing on Mono, it just gives a standard font-family (I think it is Arial) with the name of myFontFamily.ttf

推荐答案

从谷歌找到这篇文章.如果有什么安慰的话,我在 AddMemoryFont 上遇到了同样的问题(在 Windows 上工作正常,mono 给了我一个通用字体.)如果有什么安慰的话,它看起来是 Mono 的问题,而不是你的代码.

Found this post from google. If it's any consolation, I'm experiencing the same issue with AddMemoryFont (works fine on Windows, mono gives me a generic font.) If it's any consolation, it looks like it's a problem with Mono, and not your code.

深入挖掘源代码,System.Windows.Drawing.PrivateFontCollection 主要只是 GDIPlus.GdipPrivateAddFontFile 的包装,它本身就是 fontconfig 的 FcConfigAppFontAddFile 的包装.它似乎没有抛出任何错误的原因是 GDIplus 不检查 fontconfig 的返回值,所以看起来 fontconfig 出于某种原因无法读取字体,但 GDIplus 不知道它,所以 PrivateFontCollection 也没有.

Digging through the source, System.Windows.Drawing.PrivateFontCollection is mostly just a wrapper around GDIPlus.GdipPrivateAddFontFile, which itself is a wrapper around fontconfig's FcConfigAppFontAddFile. The reason it doesn't appear to throw any errors is that GDIplus doesn't check for a return value from fontconfig, so it seems like fontconfig isn't able to read the font for whatever reason, but GDIplus doesn't know about it, so neither does PrivateFontCollection.

这篇关于Mono PrivateFontCollection.AddFontFile 错误的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)