如何使用FontFace API加载后备字体格式 [英] How to load fallback font formats with FontFace API
问题描述
使用FontFace时 API (不是@fontface )是否有一种便捷的方式来传递多种不同的字体格式,例如在@fontface中提供多个来源?
When using the FontFace API (not @fontface) is there a convenient way to pass multiple different font formats, like with providing multiple sources in @fontface?
或者,是否有一种方便的方法来检查使用FontFace API的浏览器可以接受的格式,所以我可以提供几种中最理想的一种?
Or alternatively, is there a convenient way to check what formats the browser using the FontFace API will accept, so I can provide the most ideal of several?
推荐答案
从"CSS字体加载" 规范指出,FontFace API的值与相应的@font-face
描述符相同.这意味着您可以简单地将@font-face
定义中使用的任何后备字符串用作字体数据源. 这是WebKit处理它的方式,无论如何:
From what the current draft of the CSS Font Loading spec says, the FontFace API takes the same values as the corresponding @font-face
descriptors. It means you can simply pass as the font data source whatever fallback string you’d use in your @font-face
definition. It’s how WebKit handles it, anyway:
let fontFace = new FontFace("MyWebFont", "url('MyWebFont.woff2') format('woff2'), url('MyWebFont.woff') format('woff')");
这篇关于如何使用FontFace API加载后备字体格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!