简体   繁体   English

base64字体与二进制字体的呈现方式不同

[英]base64 font renders differently to binary font

I'm seeing a strange change in the rendering of a font when it's encoded as base64. 当将字体编码为base64时,我看到字体的呈现方式发生了奇怪的变化。

To improve page performance I'm working on saving my site's webfonts as base64 data in localStorage using a method like Smashing Magazine's . 为了提高页面性能,我正在使用Smashing Magazine's之类的方法将网站的网络字体保存为localStorage中的base64数据。 The JS is pretty straightforward. JS非常简单。 But when I convert the woff font data to base64 the font in my headlines renders differently. 但是,当我将woff字体数据转换为base64时,标题中的字体呈现出不同的效果。

This is how the binary font looks: 这是二进制字体的外观:

在此处输入图片说明

And this is what happens in base64: 这就是base64中发生的情况:

在此处输入图片说明

In each case the HTML is the same: 在每种情况下,HTML都是相同的:

<h3 class="title">
    <a href="http://domain.co.uk/sarah-palin-923489/"><span>What happens after Sarah Palin's teleprompter breaks is hardly surprising</span></a>
</h3>

and the CSS: 和CSS:

.title {
    font-size: 26px;
    line-height: 1.2;
    position: relative;
    z-index: 2;
    font-family: ScoutBold, Arial, Helvetica, sans-serif;
    font-weight: normal;
}

span {
    color: white;
    background-color: rgba(126, 211, 33, 0.8);
    box-shadow: 10px 0 0 rgba(126, 211, 33, 0.8), -10px 0 0 rgba(126, 211, 33, 0.8);
}

My scout-light.woff font contains binary data like: 我的scout-light.woff字体包含如下二进制数据:

774f 4646 0001 0000 0000 7856 0011 0000
0001 1564 0001 0000 0000 76a0 0000 01b6
0000 02f9 0000 0000 0000 0000 4750 4f53
0000 65d0 0000 0da6 0000 47f2 b51f 87a4

I'm uploading the woff file here and pasting it into my font CSS like so: 我在这里上传woff文件并将其粘贴到我的字体CSS中,如下所示:

@font-face {
  font-family: ScoutLight;
  src: url(data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAGKIABMAAAAA70AAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABqAAAABwAAAAcak+p20dERUYAAAHEAAAAMgAAADgCIAEQR1BPUwAAAfgAAA3LAABSqL7EBrtHU1VCAAAPxAAAAJIAAAEmGQ8brU9TLzIAABBYAAAA... mCGKVBUG8hLUWlnoKDzARBPFyOqu7sZs3/ye8zwgX1qK/7nqAq+wbV3RzzGSL5YaCo5yhK7YdQ17VyMUS46p+MW4zZomvI+XYSoxD5Qj2xoFyCJGxX9X34KHhEfybhkvwThqOGnP/Z2wqOjuNhMAnPwCm+rMRZVNhiZ43B2KmNqQwZUMmp4ZsNbAg5ouBY2LhGUosxQdf6EtzAAABVCFFcAAA) format("woff"), url("../fonts/scout-light/scout-light.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
}

So I'd assume the encoded data is a good match to the unencoded data. 因此,我假设编码后的数据与未编码后的数据非常匹配。 And that's the only difference. 那是唯一的区别。 Can anybody suggest why I'm seeing this change in the rendering, when all that's different is the font data encoding? 当字体数据编码的所有不同之处时,有人可以建议为什么我会在渲染中看到这种变化吗? Should I encode using a different method? 我应该使用其他方法编码吗?

Example of the base64 version here . 此处为base64版本的示例。

//////////////////////////// EDIT //////////////////////////// ///////////////////////////////////////////////// ///////

I've discovered that encoding a font as base64 definitely involves some degradation in quality. 我发现将字体编码为base64肯定会导致质量下降。 My customers are complaining that single quotes are now positioned too high above the baseline. 我的客户抱怨现在单引号的位置比基线高。 I'm going to have to give up on storing fonts locally. 我将不得不放弃在本地存储字体。

Look at what happens to the ' before "This" in this example. 查看此示例中“此”之前的'发生了什么。 The encoding screws it up. 编码将其拧紧。

在此处输入图片说明

Hard to look at without a live example, but have you tried adding the line-height to the span-tag 没有实际示例很难看,但是您是否尝试过将line-height添加到span-tag

The line heigh should be 100% and in the span-tag. 线高应为100%,并在span标签中。

 .title {
  position: relative;
  z-index: 2;
  font-family: ScoutBold, Arial, Helvetica, sans-serif;
}

.title span {
  line-height: 100%;
  font-size: 25px;
  background-color: rgba(126, 211, 33, 0.8);
  box-shadow: 10px 0 0 rgba(126, 211, 33, 0.8), -10px 0 0 rgba(126, 211, 33, 0.8);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM