I'm using a custom font which loads fine locally, but whn I upload it to my web server, a default fallback is used. No exception is thrown though, which I fine bizarre.

Here's what I'm using to load the font in Application_Start in global.asax:

try {
        // Code that runs on application startup
        var fontNames = Directory.GetFiles(HostingEnvironment.MapPath("~/fonts/labels/"));
        var pfc = AppCache.GetCachedFonts(); // static class, returns PFC from the HttpContext's cache
        fontNames.ForEach(f =>{
                                  try {
                                      pfc.AddFontFile(f);
                                  } catch(Exception ex) {
                                      Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                                  }
        });
    } catch (Exception ex) {
        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
    }

Elmah logs nothing though. Out of maybe 15 fonts I'm using, around half just fail silently. I'm not sure what to check.

有帮助吗?

解决方案

This was caused by trying to use an unsupported variant of a font. Eg: Bold when the TTF only includes regular.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top