【问题标题】:HTML font rendering issue on non-retina display非视网膜显示器上的 HTML 字体渲染问题
【发布时间】:2020-04-01 00:30:39
【问题描述】:

我无法像在 Google 字体演示网站上那样在我的网站上渲染 Poppins。

当使用非视网膜显示器时,它会呈现“太薄”,例如,当我在 font.google.com 上查看相同的文本时,T 上的条只有 1 像素高,而不是 1.5 像素高。

我更喜欢它在 Google 字体上的外观。在我的网站上,字体在顶部看起来“被切碎”,但我无法弄清楚他们在 HTML 中做了什么以获得不同的渲染。

This codepen 演示了问题,但请注意:您需要非视网膜显示器才能看到问题!

代码:

<html>

<head>
  <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap" rel="stylesheet" />
</head>
<style>
  body {
    margin: 48px;

    font-family: "Poppins", sans-serif;
    font-weight: 700;
    font-style: normal;
    font-size: 18px;
  }

  main {
    display: grid;
    grid-template-columns: 20% 30% 40%;
    column-gap: 5%;
    align-items: center;
  }

  h2 {
    font-size: 1.2em;
    font-weight: normal;
    align-self: center;
  }

  a {
    color: #000;
  }

  small {
    display: block;
    font-weight: normal;
    font-size: 12px;
  }

  img:first-of-type {
    grid-row-end: span 2;
  }
</style>

<body>
  <h1>⚠️This issue is only visible on non-retina display!</h1>
  <main>
    <h2>
      Browser rendering
    </h2>
    <div>
      TITLE TEXT HERE IS 18<br />
      <small>^^^ T bars will be too thin on non-retina browser</small>
    </div>
    <img src="https://i.imgur.com/7LyzjJy.png" />

    <h2>
      Screenshot of Chrome on MacOS (broken)
    </h2>
    <div>
      <img src="https://i.imgur.com/2OZ0wv6.png" />
      <small>^^^ Notice how the T bar is too thin.</small>
    </div>

    <h2>
      Google Fonts<br />
      (screenshot of Bold 700 on <a href="https://fonts.google.com/specimen/Poppins?preview.text=HTML+TITLE+TEXT+HERE+IS+18&preview.text_type=custom&selection.family=Poppins:wght@400;700&sidebar.open">
        the demo page</a>)
    </h2>
    <div>
      <img src="https://i.imgur.com/dgld0Jw.png" /><br />
      <small>^^^ Notice how the T bars are thicker</small>
    </div>
    <img src="https://i.imgur.com/pQPZ6Ch.png" />
  </main>
</body>

</html>

【问题讨论】:

  • 它似乎对我来说很好imgur.com/QtDwjKm,哎呀,编辑:我刚刚注意到您现在可能解决问题的日期,想评论一下问题是什么?
  • 不,问题没有解决。你需要在非视网膜显示器上查看问题,我被告知它在 Windows 上运行良好,所以这可能是一个仅限 mac 的问题,但我还没有确认这一点。
  • 我在使用 macbook pro,屏幕截图来自我使用 chrome 的第二个 viewsonic 高清显示器,仍然不确定这是否与您在高清屏幕上看到的输出相似,对我来说好像还可以
  • 是的,我同意。你的截图看起来不错。如果你打开我在问题中链接的代码笔,你能看到问题吗?
  • 不一样 imgur.com/d4HRgWq 您是否在浏览器中设置了任何标志(已编辑默认浏览器设置)?不同的浏览器会出现同样的问题吗?

标签: html css font-face retina-display google-fonts


【解决方案1】:

我明白你的意思, 似乎这种字体的最新版本存在一些问题,其他人也抱怨过。 现在为什么它在谷歌上呈现得很好?可能是谷歌脚本使用的演示版本与他们的字体 CDN 上的不一样,虽然我不确定


解决方案:

在他们解决问题之前,使用 Webfont

与您笔中的字体相同的 CSS 除了这是older version,您可以将其托管在您自己的服务器上 使用类似 webfont 的东西(我相信你知道怎么做,但万一你不知道) fontsquirrel 让过程变得非常简单。

顺便说一句,这是在 Mac 和单独的高清屏幕上

注意: 我注意到字母/单词之间有一点间距,但没有 无法用某些 CSS 修复 letter-spacingword-spacing

【讨论】:

  • 我会试试这个并报告。非常感谢!
  • 我尝试了 Adob​​e fontkit 中的字体,fontsquirrel 上的 Poppins 字体 - 他们没有用。然后我尝试了由 fontsquirrel 处理的your link 的 ttf,现在我得到了我期望的渲染。非常感谢!
【解决方案2】:

第一件事 - 自 macOS Mojave 以来,Apple 默认禁用字体平滑。这在 Retina Displays 上很难注意到,但 easy to notice on non-Retina。执行defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO 并注销主要可以解决问题。没有字体平滑的文字看起来有点小。

第二个问题似乎与 Google 字体的工作方式有关。当您在 Google 字体演示页面上键入预览文本时,您只会加载此给定文本所需的字符 - 这是为了节省带宽,因为您将下载大约 18 种样式。

但字体似乎有点不同。

  1. Google 字体嵌入
  2. 从 Google Fonts 下载的 Poppins,通过 @font-face 手动导入
  3. 由 Google Fonts 构建的字体,从开发者工具的网络页面下载

1 和 2 看起来相同。除了字母 T 和 E 之外,3 中的差异几乎不明显。

还请注意,在 Google Fonts 演示页面上,文本以-webkit-font-smoothing: antialiased; 呈现,这通常会使文本看起来更小,也许这就是生成的字体更大的原因。

如果您缓存了 Poppins 并手动将字体从生成的 Poppins 更改为真实的 Poppins,则会注意到这一点。

这是我对这个问题的看法,但在解决这个问题的过程中,我还发现有时会出现亚像素渲染。

【讨论】:

  • 感谢您精心研究的答案。我尝试了-webkit-font-smoothing: antialiased;,但它似乎是默认设置,我没有看到任何区别。我同意您的结论,即 Google 发送的字体似乎与他们在 CDN 上提供的字体不同。
猜你喜欢
  • 2014-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-05
  • 2015-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多