【问题标题】:Font positioning differences in a <span> between Mac and WindowsMac 和 Windows 之间 <span> 中的字体定位差异
【发布时间】:2019-04-23 00:46:27
【问题描述】:

我最近发现了一种字体(-file),它在不同操作系统的跨度内的位置似乎大不相同。如果熟悉字体的人知道这里到底出了什么问题,并且如果有类似的修复或解决方法,我将不胜感激。

我在这里做了一支笔:https://codepen.io/jls_chris/pen/rQmpEE 它应该向您展示元素的基本设置:

<div class="box">
  <div class="wrapper">
    <span class="value">24%</span>
  </div>
</div>

@font-face {
  font-family: 'Impact LT Std';
  src: url('https://sorry.font.is.licensed/ImpactLTStd.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}

.box {
  height: 163px;
  width: 259px;
  position: relative;
  z-index: 10;

  // Set by gsap
  opacity: 1;
  transform: matrix(1, 0, 0, 1, 0, 0);

  // For debugging
  background-color: lightblue;

  .wrapper {
    height: calc(163px - 33px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    // For debugging
    background-color: lightgreen;

    .value {
      font-family: 'Impact LT Std', Sans-Serif;
      font-size: 95px;
      -webkit-font-smoothing: subpixel-antialiased;

      // For debugging
      text-decoration: underline;
      outline: 1px solid red;
    }
  }
}

由于字体许可不允许我分享,这里有几张图片:

在 Windows(任何浏览器)上:

在 Mac(任何浏览器)上:

在 Windows 上一切看起来都正确,但在 Mac 上,文本显然没有像我预期的那样居中。

跨度在两者上都正确定位并且具有正确的尺寸,但看起来基线在两个操作系统上的定位完全不同。我测试了其他几种字体,但无法重现。

有人知道这种字体可能有什么问题/损坏以及是否可以修复?

【问题讨论】:

  • 这听起来像是字体渲染问题,或者可能只是行高问题。 .value { line-height: 1; } 能解决什么问题吗?
  • @elveti 不,遗憾的是这没有帮助。
  • 哦,太糟糕了。那么问题可能出在字体本身。您可以尝试这里提到的解决方案:stackoverflow.com/questions/11726442/… 特别是 FontSquirrel WebfontGenerator 过去曾帮助我处理过类似的情况。 Squirrel 将您的 .otf 字体转换为所有其他类型(ttf、woff),以使其尽可能跨浏览器兼容。但是他们将许可字体列入黑名单,所以我不知道它是否适合您。抱歉,我无法为您提供更简单/更好的解决方案
  • @elveti 哦,这个问题看起来非常非常相似。遗憾的是,该字体在 FontSquirrel 上被列入黑名单,所以我必须看看我能做什么。

标签: html css layout browser


【解决方案1】:

elveti 链接了以下帖子(在评论中,如果可能,我会接受该评论作为解决方案):Font Rendering / Line-Height Issue on Mac/PC (outside of element) 它概述了相同的问题并包含解决方案。

遗憾的是,FontSquirrel 不是一个选项,因为它会阻止 Adob​​e 字体。但是我使用 FontForge 编辑了字体,正如 Luke 的帖子中提到的那样:https://stackoverflow.com/a/38508202/1084239

对我来说,没有选中任何复选框,但“Win ...”指标与其他指标不同。我将“Win Ascent”和“Win Descent”值复制到相应的“Typo”和“HHead”字段中,因为我的问题是 mac 显示字体不正确(并且未选中所有复选框)。使用默认设置将字体导出为 ttf 并忽略任何警告后,它生成的字体最终在 mac 和 windows 上都能正常工作。

【讨论】:

    猜你喜欢
    • 2022-09-24
    • 2017-12-03
    • 2015-02-26
    • 2010-12-18
    • 1970-01-01
    • 2013-07-11
    • 1970-01-01
    • 2012-06-06
    • 2010-12-03
    相关资源
    最近更新 更多