【问题标题】:Chrome OS (incognito) and Linux Chrome webfont display issuesChrome 操作系统(隐身)和 Linux Chrome 网络字体显示问题
【发布时间】:2014-07-01 10:49:32
【问题描述】:

我在跨平台测试网络字体时遇到了一个奇怪的问题。我正在使用 Javascript navigator.appVersion 检查与 webkit 媒体查询耦合的 Windows Chrome font rendering issues(因为 Chrome 和 Safari 是 Webkit,如果在 Windows 上可以排除 Safari),并在此过程中产生了一个新问题。

我在隐身模式下进行测试,这是一种无需保存图像等即可快速查看页面的方法,但这对我来说是一个新方法。

我在if(navigator.appVersion.indexOf("Win")>-1 后面的 else 子句中的操作之前和之后都添加了控制台调试,所以我可以看到循环没有被中间的任何错误语法破坏,也没有引发错误。

我认为这可能是 Chrome 操作系统中的错误,但在 Linux Mint 上,字体不会在任何类型的 Chrome 窗口中加载。清除缓存、cookie 和映像文件对任一操作系统都没有影响。

截图:

对于如何调和这里的不一致之处,我有点不知所措,而且由于我的 Javascript 在某些情况下运行,我对哪里出了问题感到困惑。我不太愿意就此联系任何专家论坛,但如果我最好为某种 Chrome 开发组这样做,请告诉我。

如果有人想自己测试here's the page in the screenshots

我还尝试以隐身模式登录 GitHub 和我的 Google 帐户,以防我发现与权限相关的问题,但它没有改变任何东西,而且无论如何这仍然无法解释与 Windows 的不一致(在隐身模式下工作) /常规的)。这些文件存储在公共 GitHub 存储库中,即使在我的网站上没有字体呈现的情况下,我也绝对可以在浏览器中访问它们。

<script>
if (navigator.appVersion.indexOf("Win")>-1) {
    console.log("Win test")
    chromeQuery = document.createElement('style');
    chromeQuery.setAttribute('type','text/css');
    chromeQuery.innerHTML = "@media screen and (-webkit-min-device-pixel-ratio:0) { /* Chrome-specific SVG font */ @font-face{ font-family: \"SEGOEUIL\"; src: local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.svg') format(\"svg\"), local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.woff') format('woff'), local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.ttf') format('truetype'); font-weight: normal; } @font-face{ font-family: \"SEGOEUIL\"; src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.svg') format(\"svg\"), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.woff') format('woff'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.ttf') format('truetype'); font-weight: bold; font-style: normal; } @font-face{ font-family: \"SEGOEUIL\"; src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.svg') format(\"svg\"), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.woff') format('woff'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.ttf') format('truetype'); font-style: italic; } }";
    document.querySelector('head').appendChild(chromeQuery);
}
else {
    fontload = document.createElement('style');
    fontload.setAttribute('type','text/css');
    fontload.setAttribute('id','fontload')
    fontload.innerHTML = "@font-face{ font-family: \"SEGOEUIL\", \"Helvetica Neue\", Arial, sans-serif; src: local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.eot'); src: local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.eot?#iefix') format('embedded-opentype'), local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.woff') format('woff'), local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.ttf') format('truetype'), local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.svg') format('svg'); font-weight: normal; } @font-face{ font-family: \"SEGOEUIL\", \"Helvetica Neue\", Arial, sans-serif; src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.eot'); src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.eot?#iefix') format('embedded-opentype'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.woff') format('woff'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.ttf') format('truetype'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.svg') format('svg'); font-weight: bold; font-style: normal; } @font-face{ font-family: \"SEGOEUIL\", \"Helvetica Neue\", Arial, sans-serif; src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.eot'); src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.eot?#iefix') format('embedded-opentype'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.woff') format('woff'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.ttf') format('truetype'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.svg') format('svg'); font-style: italic; }";
    document.querySelector('head').appendChild(fontload);
    console.log('loaded')
}
</script>
<noscript><style id="fontload" type="text/css">

@font-face{ 
        font-family: "SEGOEUIL", "Helvetica Neue", Arial, sans-serif;
        src: local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.eot');
        src: local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.eot?#iefix') format('embedded-opentype'),
             local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.woff') format('woff'),
             local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.ttf') format('truetype'),
             local('Segoe UI Light'), url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/SEGOEUIL.svg') format('svg');
        font-weight: normal;
    }

    @font-face{ 
        font-family: "SEGOEUIL", "Helvetica Neue", Arial, sans-serif;
        src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.eot');
        src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.eot?#iefix') format('embedded-opentype'),
             url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.woff') format('woff'),
             url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.ttf') format('truetype'),
             url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuisb.svg') format('svg');
        font-weight: bold;
        font-style: normal;
    }

    @font-face{ 
        font-family: "SEGOEUIL", "Helvetica Neue", Arial, sans-serif;
        src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.eot');
        src: url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.eot?#iefix') format('embedded-opentype'),
             url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.woff') format('woff'),
             url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.ttf') format('truetype'),
             url('https://raw.githubusercontent.com/lmmx/websiteresources/master/fonts/weblysleekuili.svg') format('svg');
        font-style: italic;
    }

</style></noscript>

编辑我在资源面板中看不到任何字体,所以我看不到成功的样子——我可以看到似乎是 opentype 字体显示某种(延迟?)错误,这可能是相关的?

(Source Code Pro 没有使用,icon 字体不是文本)

【问题讨论】:

    标签: javascript css google-chrome webfonts google-chrome-os


    【解决方案1】:

    有几处看起来不对:

    1. 您注入的样式被&lt;noscript&gt; 标签包围,因此您的字体只有在禁用 JavaScript 时才会加载
    2. 您的@font-face 规则应该将您的自定义字体映射到一个系列。所以font-family: "SEGOEUIL"; 而不是font-family: "SEGOEUIL", "Helvetica Neue", Arial, sans-serif;
    3. 第一条规则尝试使用本地安装的 SEGOEUIL 版本,另一条规则始终从 githubusercontent.com 加载。因此,如果用户安装了不同的版本,字体的外观可能会发生变化。
    4. 为避免意外结果,请为所有三个声明设置 font-weightfont-style

    更改此选项可修复 Chrome 中的页面。

    【讨论】:

    • 你确定吗? 1. 故意的,作为后备,推荐here; 2. 是后备字体,即common practice; 3. 不使用本地安装的字体,单词 local 设置字体名称... 4. 不设置 font-weight 将样式应用于任何 font-weight。你确定这些建议...?
    • 抱歉,我可能已经获得了本地存储的字体版本,这解释了不一致之处。呸!显然我需要将其更改为smiley face symbol...干杯@RoelN ☺
    • 1.是的,对于 SVG 字体,但不适用于整个 @font-face 声明 2. 当您应用字体时建议使用字体堆栈,而不是在您声明带有@987654331的字体堆栈时@。 3. 确实如此,如您所见 :) 4. 这只是一个避免这种看似不稳定的 CSS 的建议。我没有安装 SERGOEUIL,它在我的 Chrome/Windows 设置中不起作用!
    • 非常感谢您的建议,我仍在努力 - 没想到 webfonts 会这么难!由于这个原因解决了 Chrome,但 Firefox 网络字体具有跨域策略 D:当我达到最终设置时会更新这篇文章
    猜你喜欢
    • 2016-03-19
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-20
    • 2018-06-24
    • 2013-07-12
    • 2019-01-22
    相关资源
    最近更新 更多