CSS 如何将 TTF 文件转换为 OTF 格式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5712047/
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-30 00:19:04  来源:igfitidea点击:

How can I convert TTF files to OTF format?

cssbrowserfont-face

提问by useCase

I need to use @font-facefeature and my fonts are in TrueType (TTF) format, so how to convert TTF to OpenType (OTF) format.

我需要使用 @font-face功能并且我的字体是 TrueType (TTF) 格式,那么如何将 TTF 转换为 OpenType (OTF) 格式。

采纳答案by Farzin Zaker

you can use TTF file format directly in css :

您可以直接在 css 中使用 TTF 文件格式:

@font-face { 
font-family: Vinegar; 
src: url(http://www.4bit.co.uk/testing/design01/vinegar.ttf); 
}

h3 {
font-family: Vinegar, "Times New Roman", Times, serif;
}

It is working!

这是工作!

Or you can use this link to generate your font face!

或者您可以使用此链接生成您的字体!

回答by fileformat

If you are on Linux, you can use FontForge, which can be scripted from Python.

如果您使用的是 Linux,则可以使用 FontForge,它可以从 Python 编写脚本。

#!/usr/bin/python
import fontforge
font = fontforge.open("STIXGeneral.otf")
font.generate("STIXGeneral.ttf")

Here is a longer python script that does this for a whole directory at a time:

这是一个较长的 python 脚本,一次对整个目录执行此操作:

http://fonts.fileformat.info/bin/otf2ttf.py

http://fonts.fileformat.info/bin/otf2ttf.py

回答by Andrei

It was painfully hard to find how to do it correctly. Here is how I got it to work on OS X

很难找到正确的方法。这是我如何让它在 OS X 上工作

$ brew install fontforge
$ fontforge  -c 'Open("my.ttf"); Generate("my.otf")'

I was desperately looking for pip install fontforgewhich does not exist and I haven't got it to work with python - I guess you need to compile it with --enable-pyextensionor something.

我拼命寻找pip install fontforge哪个不存在,我还没有让它与 python 一起工作 - 我想你需要用它--enable-pyextension或其他东西来编译它。

回答by nitro2k01

A quick Google search for ttf otf convertergave me a number of results, such as:

快速的谷歌搜索给ttf otf converter了我一些结果,例如:

https://onlinefontconverter.com

https://onlinefontconverter.com

http://www.freefontconverter.com

http://www.freefontconverter.com

http://www.font2web.com

http://www.font2web.com

No idea how well they work, but you can try them.

不知道它们的效果如何,但您可以尝试一下。

回答by AvL

For cross browser/mobile support you definitely need at least three formats:

对于跨浏览器/移动支持,您肯定至少需要三种格式:

  1. Embedded OpenType: eotfor Internet Explorer 6-8.
    There is a command line converter: http://code.google.com/p/ttf2eot/

  2. Web Open Font Format: woffthe W3C recommendation for webfonts: http://www.w3.org/TR/WOFF/
    A converter can be fond here: http://people.mozilla.org/~jkew/woff/

  3. and TrueType: ttffor Safari and Opera

  4. (You could add Scalable Vector Graphics: svgfor older iOS support…)

  1. 嵌入式 OpenType:eot适用于 Internet Explorer 6-8。
    有一个命令行转换器:http: //code.google.com/p/ttf2eot/

  2. 网络开放字体格式:woff对于网络字体的W3C推荐:http://www.w3.org/TR/WOFF/
    A转换器可以喜欢这里:http://people.mozilla.org/~jkew/woff/

  3. 和 TrueType:ttf用于 Safari 和 Opera

  4. (您可以添加可缩放矢量图形:svg对于较旧的 iOS 支持...)

The bulletproof @font-face Syntax is this:

防弹@font-face 语法是这样的:

@font-face {
  font-family: 'Vinegar';
  src: url('vinegar.eot?') format('embedded-opentype'),
       url('vinegar.woff') format('woff'),
       url('vinegar.ttf') format('truetype'),
       url('vinegar.svg#svgVinegar') format('svg');
}

Further resources:
http://www.paulirish.com/2009/bulletproof-font-face-implementation-syntax/
http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax
http://webfonts.info/

更多资源:http:
//www.paulirish.com/2009/bulletproof-font-face-implementation-syntax/
http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax
http: //webfonts.info/

You might also want to check out this tool:
https://github.com/zoltan-dulac/css3FontConverter

您可能还想查看此工具:https:
//github.com/zoltan-dulac/css3FontConverter

回答by Mikecito

You could also try this:

你也可以试试这个:

http://www.freefontconverter.com/

http://www.freefontconverter.com/

回答by jazzfan

As mentionned by others, fontforge scripting has switched to python. I found the easiest way was to invoke python from the command line.

正如其他人所提到的,fontforge 脚本已切换到 python。我发现最简单的方法是从命令行调用 python。

I could convert multiple ttf fonts to otf on Arch Linux this way, but it should work on other distros by installing fontforge with your favorite package manager.

我可以通过这种方式在 Arch Linux 上将多个 ttf 字体转换为 otf,但通过使用您最喜欢的包管理器安装 fontforge,它应该适用于其他发行版。

[user@host]$ sudo pacman -S fontforge
[user@host]$ cd /path/to/your/fonts/folder
[user@host]$ python
>>> import fontforge
>>> import os
>>> fonts = [f for f in os.listdir('.') if f.endswith('.ttf')]
>>> for font in fonts:
...      f = fontforge.open(font)
...      f.generate(font[:-3] + 'otf')  # changes extension from ttf to otf
...
>>> exit()