Google/Typekit Webfont-Loader 不检测非 ASCII 字体

发布于 2024-11-27 07:33:38 字数 1377 浏览 1 评论 0原文

我正在使用 Google 网页字体加载程序,但我无法获取fontactive 回调起作用。字体正在页面上呈现,但由于某种原因回调未触发。 (相反,它会等待 5 秒,然后触发 fontinactive 回调。)我怀疑问题在于我如何向函数声明这两个变量。

编辑:问题可能与字体有关,而不是与我声明变量的方式有关。字体加载器成功检测到何时加载包含常规字母字符的“STIXGeneral”字体系列。

fontactive 回调的文档位于此处。我尚未找到任何使用 fontactive 回调的示例。

我在下面发布了我的代码副本。


来自 Javascript:

WebFont.load({
    custom: {
        families: [ 'STIXSizeOneSym' ],
        urls: ['resources/stix-fonts/STIX-fonts.css']
    },
    fontactive: function(stixsizeonesym, n4) { alert("1") },
    fontinactive: function(stixsizeonesym, n4) { alert("2") },
    inactive: function() { alert("10") }
});


来自 STIX-fonts.css:

@font-face {
    font-family: 'STIXSizeOneSym';
    src: url('STIXSizOneSymBol-webfont.eot');
    src: url('STIXSizOneSymBol-webfont.eot?#iefix') format('embedded-opentype'),
          url('STIXSizOneSymBol.otf') format('opentype'),
          url('STIXSizOneSymBol-webfont.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
    }

I'm using the Google webfont loader, but I can't get the fontactive callback to work. The font is rendering on the page, but for some reason the callback isn't firing. (Instead it waits for 5 seconds and then the fontinactive callback fires.) I suspect the problem is in how I'm declaring the two variables to the function.

Edit: The problem may have to do with the font, not how I'm declaring the variable. The font-loader sucessfully detects when the "STIXGeneral" font family loads, which contains regular letter characters.

Documentation of the fontactive callback is here. I haven't been able to find any examples of using the fontactive callback.

I've posted a copy of my code below.

From Javascript:

WebFont.load({
    custom: {
        families: [ 'STIXSizeOneSym' ],
        urls: ['resources/stix-fonts/STIX-fonts.css']
    },
    fontactive: function(stixsizeonesym, n4) { alert("1") },
    fontinactive: function(stixsizeonesym, n4) { alert("2") },
    inactive: function() { alert("10") }
});

From STIX-fonts.css:

@font-face {
    font-family: 'STIXSizeOneSym';
    src: url('STIXSizOneSymBol-webfont.eot');
    src: url('STIXSizOneSymBol-webfont.eot?#iefix') format('embedded-opentype'),
          url('STIXSizOneSymBol.otf') format('opentype'),
          url('STIXSizOneSymBol-webfont.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花落人断肠 2024-12-04 07:33:38

我是 webfontloader 的开发人员之一。我们当前使用 ASCII 字符串来检测字体是否已加载。因此,如果您的字体不包含字符“BESbswy”,则 webfontloader 将无法检测到它。我们正在努力添加对可配置测试字符串的支持(这样您就可以包含字体支持的 Unicode 范围中的一些字符。)我已经在 webfontloader 存储库上为此提出了一个问题 (https://github.com/typekit/webfontloader/issues/104)。

作为临时解决方案,您可以编译自己版本的 webfontloader,将字体中的字符添加到测试字符串中。如果您需要帮助,请告诉我。

I'm one of the developers of the webfontloader. We are currently using an ASCII string to detect whether or not a font has loaded. So if your font does not include the characters "BESbswy" the webfontloader won't be able to detect it. We're working on adding support for configurable test strings (so you can include some characters from the Unicode range your font supports.) I've opened an issue for this on the webfontloader repository (https://github.com/typekit/webfontloader/issues/104).

As a temporary solution you can compile your own version of the webfontloader that adds characters from your font to the test string. Let me know if you need help with that.

苏佲洛 2024-12-04 07:33:38

我尝试在从 Google 抢先体验下载的中文字体“cwTeXHei”上使用该加载程序。

我花了一个下午,终于使用以下代码使fontactive正常工作:

WebFontConfig = {
  custom: {
    families: ['ChineseCustomFont'],
    testStrings: {
      'ChineseCustomFont': '\uE003\uE005'
    },
  },
  timeout: 8000
};
(function() {
  var wf = document.createElement('script');
  wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
    '://ajax.googleapis.com/ajax/libs/webfont/1.5.3/webfont.js';
  wf.type = 'text/javascript';
  wf.async = 'true';
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(wf, s);
})();

注意事项

  1. 使用webfont loader > 1.5.0支持“testStrings”
  2. 使用'\uE003\uE005'作为“testStrings” ”,我尝试了 '\u9ED1' 但不起作用,我还没有弄清楚为什么要
  3. 更改超时,因为中文字体文件很大,默认为 5000

希望它也能帮助别人!

I try to use the loader on a Chinese Font "cwTeXHei" downloaded from Google Early Access.

I spent an afternoon and finally make the fontactive works using the follow codes:

WebFontConfig = {
  custom: {
    families: ['ChineseCustomFont'],
    testStrings: {
      'ChineseCustomFont': '\uE003\uE005'
    },
  },
  timeout: 8000
};
(function() {
  var wf = document.createElement('script');
  wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
    '://ajax.googleapis.com/ajax/libs/webfont/1.5.3/webfont.js';
  wf.type = 'text/javascript';
  wf.async = 'true';
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(wf, s);
})();

Points to noted:

  1. Use webfont loader >1.5.0 for support of "testStrings"
  2. Use '\uE003\uE005' as "testStrings", I tried '\u9ED1' but not works and I haven't figure out why
  3. change timeout since chinese font files are large, default is 5000

Hope it helps someone too!

浅唱ヾ落雨殇 2024-12-04 07:33:38

遇到同样的问题,目前还没有找到解决办法。它只影响少数字体,即 Bree 或 Playfair。我怀疑这与 webkit 逐步下载字体有关。似乎“fontinactive”立即被解雇。我最终得到了一些复杂的 Javascript 东西,以一定间隔检查隐藏容器的尺寸:/

Have the same prob and did not find any solution yet. It affects only a few fonts, i.e. Bree, or Playfair. My suspicion is that it has something to do with webkit progressively downloading fonts. It seems "fontinactive" is fired immediately. I ended up with some complicated Javascript stuff, checking the dimensions of a hidden container in an interval :/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文