CSS @font-face 在 iPhone 版本的 Safari 上已被弃用。我的选择是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1149417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:50:51  来源:igfitidea点击:

@font-face is deprecated on the iPhone version of Safari. What are my alternatives?

iphonecsssafariwebkitfont-face

提问by Andrew Hedges

According to Apple's documentation, @font-face is deprecated for use on the iPhone version of Safari. The iPhone only includes 11 fonts, AFAIK, and, in any case, I need a nice blackletter font for an app I'm building. I'll be generating random text, so images are not an option. What alternatives do I have? Am I stuck with a JavaScript solution like Cufón?

根据Apple 的文档,@font-face 在 iPhone 版本的 Safari 上被弃用。iPhone 只包含11 种字体,AFAIK,而且,无论如何,我需要为我正在构建的应用程序提供一个漂亮的黑色字体。我将生成随机文本,因此图像不是一种选择。我有哪些选择?我是否坚持使用像Cufón这样的 JavaScript 解决方案?

回答by christophercotton

Well, just found out @font-faceis NOW support on the current iPhone and iPad. The documentation linked to above, which is Safari CSS ReferenceShows the example for how to embed the font.

好吧,刚刚发现@font-face现在支持当前的 iPhone 和 iPad。上面链接的文档,即Safari CSS Reference显示了如何嵌入字体的示例。

@font-face {
    font-family: "MyFamilyname", cursive [, ...];
    font-style: normal [, ...];
    font-variant: normal[, ...];
    font-weight: bold[, ...];
    font-stretch: condensed[, ...]; /* Not supported */
    font-size: 12pt;[, ...] /* Not supported */
    src: local("Font Family Name"),
        url(http://..../fontfile.ttf) format("truetype"),
        url(http://..../fontfile.ttf) [, ...];
}

Just wanted to make sure someone else who came along and read this like me, knew the current state.

只是想确保其他像我一样来阅读本文的人了解当前状态。

回答by mikelikespie

You can actually use @font-face. You just need to use SVG fonts. There are utilities to convert TTFs to SVGs

你实际上可以使用@font-face。您只需要使用 SVG 字体。有一些实用程序可以将 TTF 转换为 SVG

See this for more info (not my post)

请参阅此了解更多信息(不是我的帖子)

http://blog.themeforest.net/tutorials/how-to-achieve-cross-browser-font-face-support/

http://blog.themeforest.net/tutorials/how-to-achieve-cross-browser-font-face-support/

回答by Nathan de Vries

Cufón is really the only solution you'll be able to use out of the box. It has the added advantage of being rather quick on the iPhone since it uses canvas rather than inline SVG, and the generated fonts are typically around 60-80% smaller than the original fonts (when compressed).

Cufón 确实是您可以开箱即用的唯一解决方案。它具有在 iPhone 上相当快的附加优势,因为它使用画布而不是内联 SVG,并且生成的字体通常比原始字体(压缩时)小 60-80%。

回答by zoul

I'll be generating random text, so images are not an option.

我将生成随机文本,因此图像不是一种选择。

You could use a graphics library on the server and draw the images on the fly. I've done something similar and it works, but of course it depends on the amount of text you want to draw. Plus if the text repeats at least sometimes, you could cache the images.

您可以使用服务器上的图形库并动态绘制图像。我做过类似的事情并且它有效,但当然这取决于您要绘制的文本量。另外,如果文本至少有时重复,您可以缓存图像。