我正在尝试加载一个自定义字体(ttf文件),并使用Graphics对象绘制成一个图像。这段代码在本地运行良好:
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上动态加载字体吗?
发布于 2012-11-30 01:02:46
string path = context.Server.MapPath("~/App_Data/Futura LT Bold.ttf");
fonts.AddFontFile(path);从.ttf名称可以看出这抛出异常的原因。请注意文件名中的"Bold“。这使得创建一个FontStyle = Regular字体实例的几率非常低。但很有可能FontStyle = Bold会起作用。
一个字体通常有多个.ttf文件,每个FontStyle对应一个。假设您有其他文件,那么您也必须添加这些文件。
https://stackoverflow.com/questions/13627943
复制相似问题