通过删除字形缩小 .OTF 字体 [英] Downsizing an .OTF font by removing glyphs

查看:39
本文介绍了通过删除字形缩小 .OTF 字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太相信这个问题不是专门针对 OpenType 字体提出的,但有人知道从这些字体中删除字形的方法吗?

I can't quite believe this question hasn't been asked specifically for OpenType fonts, but does anyone know of a way to remove glyphs from these fonts?

我有一个 .OTF 文件非常大(将近 10MB),我需要把它缩小.原因有两个.

I have an .OTF with a very large file-size (almost 10MB) and I need to make it smaller. The reasons are two fold.

1) 我正在尝试为 Web 嵌入做准备,因此文件越小,客户端就越容易.

1) I'm trying to prepare it for web embedding, so the smaller the files, the easier for the client.

2) Font Squirrel(用于轻松准备字体文件)有 2MB 的上传限制 - 我知道有其他替代方案,但到目前为止都没有成功.为了避免浪费人们的时间,我尝试过的失败的有 http://fontface.codeandmore.com/http://www.font2web.com/.CodeAndMore.com 看起来可以工作,但它吐出的字体与我给它的完全不同.

2) Font Squirrel (used for easy preparation of font files) has a 2MB upload limit - I know there are alternatives, but none so far have been successful. To save wasting peoples time, the ones I've tried that have failed are http://fontface.codeandmore.com/ and http://www.font2web.com/. CodeAndMore.com appears to work, but the fonts it spits back out are completely different to the one I gave it.

请注意,我不是字体专家,所以请轻松回答.

Please be aware I'm not a font expert, so go easy on the answer.

推荐答案

我用 fontforge 库编写了一个 Python2 脚本 执行以下操作:

I've written a Python2 script with fontforge library does the following:

  • 接受源字体
  • 接受包含要使用的所有字符的文件.它可以是翻译文件、字符串资产文件、HTML 文件等.
  • 输出带有未显示在已删除文件中的字符的字体

代码如下:

#!/usr/bin/python2
import sys
import fontforge

if len(sys.argv) == 4:
    font = fontforge.open(sys.argv[1])

    with open(sys.argv[2], "r") as f:
        for i in f.read().decode("UTF-8"):
            font.selection[ord(i)] = True

    font.selection.invert()

    for i in font.selection.byGlyphs:
        font.removeGlyph(i)

    font.generate(sys.argv[3])
else:
    print "WARNING: Check the license of the source font
before distributing the output font generated by this script.
I'm not responsible for any legal issue caused by
inappropriate use of this script!
"
    print "Usage: {} [source font] [file with glyphs NOT to be removed] [output]".format(sys.argv[0])
    print "Example: {} /path/to/ukai.ttc chineseTranslation.txt ukaiStripped.ttf".format(sys.argv[0])

请注意,在某些字体上使用此脚本可能不合法.确保检查源字体的许可证.对于因使用此脚本生成的任何字体而导致的任何法律问题,我概不负责.

Please notice that it may not be legal to use this script on certain fonts. Ensure to checkout the license of the source font. I'm not responsible for any legal issue caused by using any font generated by this script.

这篇关于通过删除字形缩小 .OTF 字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆