【问题标题】:How to fix "downloadable font: rejected by sanitizer"如何修复“可下载字体:被消毒剂拒绝”
【发布时间】:2021-09-22 20:54:30
【问题描述】:

我想在我的网页中使用一种字体,但在加载页面时我在 Firefox 中收到这些错误消息:

downloadable font: rejected by sanitizer (font-family: "Yekan" style:normal weight:normal stretch:normal src index:1) source: .../css/Yekan.woff2  custom.css:1:12
downloadable font: incorrect file size in WOFF header (font-family: "Yekan" style:normal weight:normal stretch:normal src index:2) source: .../css/Yekan.woff  custom.css:1:12
downloadable font: rejected by sanitizer (font-family: "Yekan" style:normal weight:normal stretch:normal src index:2) source: .../css/Yekan.woff  custom.css:1:12
downloadable font: FFTM: invalid table offset (font-family: "Yekan" style:normal weight:normal stretch:normal src index:3) source: .../css/Yekan.ttf  custom.css:1:12
downloadable font: rejected by sanitizer (font-family: "Yekan" style:normal weight:normal stretch:normal src index:3) source: .../css/Yekan.ttf  custom.css:1:12
downloadable font: CFF : table overruns end of file (font-family: "Yekan" style:normal weight:normal stretch:normal src index:4) source: .../css/Yekan.otf  custom.css:1:12
downloadable font: rejected by sanitizer (font-family: "Yekan" style:normal weight:normal stretch:normal src index:4) source: .../css/Yekan.otf

我的 custom.css 文件:

@font-face {
    font-family: 'Yekan';
    src: url('./Yekan.eot');
    src: url('./Yekan.eot?#iefix') format("embedded-opentype"),
    url('./Yekan.woff2') format('woff2'),
    url('./Yekan.woff') format('woff'),
    url('./Yekan.ttf') format('truetype'),
    url('./Yekan.otf') format('opentype'),
    url('.//Yekan.svg#Yekan') format('svg');
    font-weight: normal;
    font-style: normal;
}

我的 style.css(我使用字体的地方):

body
{
   font-family: "Yekan";
}
  • 我搜索了很多,没有找到解决这个问题的方法。
  • 我以前用过这个字体,没问题。
  • 我检查了 meme 类型,它是正确的(例如 Yekan.ttf 的 meme 类型是 application/x-font-ttf)。

【问题讨论】:

  • 字体是invalid or corrupted吗?
  • 如何检查?我已阅读该页面并使用生成器结果相同,而且 about:config 中也没有名为 gfx.downloadable_fonts.sanitize 的选项。正如我所说,在我认为字体文件不是问题之前,我使用过这种字体。
  • 这是一个旧论坛帖子,他们肯定改变了 Firefox 中的大部分底层代码。但是之前在 OpenOffice 等软件中出现错误的字体已经给我带来了问题。也许你可以找到一个在线字体验证器来确定。
  • 错误很明显:字体的标题数据和实际文件大小是不同的值,这意味着它被错误地转换为 woff2。重新下载字体(或者如果你构建了它,重新构建它)。另外,现在是 2019 年:到底为什么要加载多年来不存在的字体格式,以及为什么要加载 ttf/otf? Use woff2, with woff as fallback. That covers every still support browser including Internet Explorer
  • 我加载了所有格式以测试它们是否有效,但我确信字体没有问题,因为我多次将它上传到服务器,并且数百个站点正在使用该字体而没有任何问题.字体的github页面:github.com/ParsMizban/Yekan-Font

标签: html css fonts


【解决方案1】:

我发现了问题,我使用 Filezilla 将字体上传到服务器,它设置为 ASCII 传输模式,切换到二进制并重新上传字体后问题解决了。

【讨论】:

    【解决方案2】:

    我最近在服务器上遇到了 npm 包bootstrap-icons 1.5.0 版本的图标字体的问题。我正在使用图标类并在 SCSS 中用自己的类名包装它们。

    我的解决方案是重新定义引导字体系列并将字体文件复制并重命名为项目。所以它在styles.scss 中看起来像这样:

    @font-face {
      font-family: "bootstrap-icons-redef";
      src: url("../assets/fonts/bootstrap-icons-redef.woff2") format("woff2"),
      url("../assets/fonts/bootstrap-icons-redef.woff") format("woff");
    }
    

    此解决方案的一个小缺点是我必须在每次更新时检查node_modules/bootstrap-icons/font/bootstrap-icons.css,以确保我的重新定义仍与上面的文件同步。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-22
      • 2018-06-03
      • 1970-01-01
      • 2019-09-18
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      相关资源
      最近更新 更多