1

我正在使用以下代码将字体加载到内存中,以便使用 GDI+ 生成图像:

var fontCollection = new PrivateFontCollection();
fontCollection.AddFontFile(Server.MapPath("~/fonts/abraham-webfont.ttf"));
fontCollection.Families.Count(); // => This line tells me, that the collection has 0 items.

没有异常,但是在AddFontFile方法运行后 fontCollection Families 属性为空,没有任何异常。

我已验证路径有效(File.Exists返回true):

Response.Write(System.IO.File.Exists(Server.MapPath("~/fonts/abraham-webfont.ttf"))); // # => Renders "True"

当我打开文件时,TTF 文件似乎工作正常,所以它不是无效的 TTF 文件: https://dl.dropboxusercontent.com/u/4899329/2016-10-12_22-44-52.png

有什么建议么?

4

1 回答 1

1

Hans Passant 的回答解决了这个问题:

PrivateFontCollection 臭名昭著。今天很常见的一种故障模式是字体实际上是带有 TrueType 轮廓的 OpenType 字体。GDI+ 只支持“纯”的。鞋子合脚,网上说 Abraham 是一种 OpenType 字体。在 WPF 中工作,而不是在 Winforms 中。

于 2016-10-13T12:37:33.203 回答