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
How can I convert TTF files to OTF format?
提问by useCase
I need to use @font-face
feature 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!
这是工作!
回答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 脚本,一次对整个目录执行此操作:
回答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 fontforge
which does not exist and I haven't got it to work with python - I guess you need to compile it with --enable-pyextension
or something.
我拼命寻找pip install fontforge
哪个不存在,我还没有让它与 python 一起工作 - 我想你需要用它--enable-pyextension
或其他东西来编译它。
回答by nitro2k01
A quick Google search for ttf otf converter
gave me a number of results, such as:
快速的谷歌搜索给ttf otf converter
了我一些结果,例如:
https://onlinefontconverter.com
https://onlinefontconverter.com
http://www.freefontconverter.com
http://www.freefontconverter.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:
对于跨浏览器/移动支持,您肯定至少需要三种格式:
Embedded OpenType:
eot
for Internet Explorer 6-8.
There is a command line converter: http://code.google.com/p/ttf2eot/Web Open Font Format:
woff
the W3C recommendation for webfonts: http://www.w3.org/TR/WOFF/
A converter can be fond here: http://people.mozilla.org/~jkew/woff/and TrueType:
ttf
for Safari and Opera(You could add Scalable Vector Graphics:
svg
for older iOS support…)
嵌入式 OpenType:
eot
适用于 Internet Explorer 6-8。
有一个命令行转换器:http: //code.google.com/p/ttf2eot/网络开放字体格式:
woff
对于网络字体的W3C推荐:http://www.w3.org/TR/WOFF/
A转换器可以喜欢这里:http://people.mozilla.org/~jkew/woff/和 TrueType:
ttf
用于 Safari 和 Opera(您可以添加可缩放矢量图形:
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
回答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()