css 如何修复“可下载的字体:被sanitizer拒绝”

smdncfj3  于 5个月前  发布在  其他
关注(0)|答案(3)|浏览(60)

我想在我的网页中使用字体,但我在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)。
qhhrdooz

qhhrdooz1#

我已经找到了问题,我使用Filezilla上传字体到服务器,它被设置为ASCII传输模式,切换到二进制和重新上传字体后,问题解决了。

kknvjkwl

kknvjkwl2#

我最近在服务器上使用npm包bootstrap-icons版本1.5.0的图标字体时遇到了这个问题。我正在使用icons类并在SCSS中使用自己的类名 Package 它们。
对我来说,解决方案是重新定义引导字体系列,并将字体文件复制和重命名到项目中。因此,它在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,以确保我的重新定义仍然与上面的文件同步。

h6my8fg2

h6my8fg23#

在线转换字体文件并在下载时出现此错误的人,请尝试像我一样从另一个网站重新转换。
在我的情况下,我在线转换ttfwoff2,但在下载woff2文件时出现此错误。我从另一个转换器网站重新上传了我的woff2文件,错误现在消失了。

相关问题