我想加载自定义字体(ttf文件)并用Graphics对象绘制到图像中。此代码运行在本地罚款:PrivateFontCollection在Appharbor上失败
PrivateFontCollection fonts = new PrivateFontCollection();
string path = context.Server.MapPath("~/App_Data/Futura LT Bold.ttf");
if (!System.IO.File.Exists(path))
{
throw new InvalidOperationException("Font file is not deployed: " + path);
}
fonts.AddFontFile(path);
然而,当上appharbor运行,调用AddFontFile失败,出现异常:
System.ArgumentException: Font 'Futura LT Book' does not support style 'Regular'.
at System.Drawing.Font.CreateNativeFont()
at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font..ctor(FontFamily family, Single emSize)
at LumenboxWeb.Controllers.GalleryController.FontTest() in d:\temp\h5oqslma.udd\input\src\LumenboxWeb\Controllers\GalleryController.cs:line 59
at lambda_method(Closure , ControllerBase , Object[])
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
我已经尝试了不同的字体,以及他们所有的工作在当地,但没有工作在appharbor上。
是否可以在appharbor上动态加载字体?
那么,有一个名为FontTest()的方法,测试失败。更改测试或避免该字体。 –
FontTest不是单元测试。我只是使用该控制器操作来重现此问题。我需要在生产代码中执行此操作。 –