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

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

问题描述

我不太相信这个问题没有被问及专门为OpenType字体,但有谁知道一种方法来从这些字体中去除字形?



我有一个非常大的文件大小(几乎10MB)的.OTF,我需要使它更小。原因是两倍。
$ b 1)我正在尝试为web嵌入做准备,因此文件越小,客户端越容易。

2)字体松鼠(用于容易准备字体文件)有一个2MB的上传限制 - 我知道有其他选择,但目前为止都没有成功。为了节省浪费时间,我尝试过的失败的是 http://fontface.codeandmore.com/ http://www.font2web.com/ 。 CodeAndMore.com似乎工作,但它吐出的字体是完全不同的,我给了它。



请知道我不是一个字体专家,所以去容易的答案。

解决方案

创建一个帐户回答这个问题。我知道这是一个老问题。但最好有一个迟到的答案比没有答案。

我刚刚遇到类似的问题。显然,没有Googlable解决方案。因此,我已经使用 fontforge库编写了一个Python2脚本来执行以下操作:




  • 接受源字体

  • 接受包含要使用的所有字符的文件。它可以是一个翻译文件,字符串资产文件,HTML文件等。

  • 输出一个字体, / ul>

    以下是代码:

     #!/ usr / bin / python2 
    import sys
    import fontforge
    $ b $ if len(sys.argv)== 4:
    font = fontforge.open(sys.argv [1])$ (UTF-8):

    f = open(sys.argv [2],r)

    b font.selection [ord(i)] = True
    f.close()

    font.selection.invert()

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

    font.generate(sys.argv [3])
    else:
    printWARNING:Check the license of在分发由此脚本生成的输出字体之前,请使用源字体。\\\
    我不负责由此脚本引起的任何法律问题!\\\

    print用法:{} [源字体] [带有字形的文件不能被删除]格式(sys.argv [0])
    print例子:{} /path/to/ukai.ttc chineseTranslation.txt ukaiStripped.ttf.format(sys.argv [0])

    请注意,在某些字体上使用此脚本可能不合法。确保签出源字体的许可证。对于使用由此脚本生成的任何字体造成的任何法律问题,我不承担任何责任。


    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?

    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) I'm trying to prepare it for web embedding, so the smaller the files, the easier for the client.

    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.

    解决方案

    Created an account for answering this question. I know that it's an old question. But it's better to have a late answer than having no answer.

    I've just run into a similar issue. Apparently, there is no Googlable solution. Therefore, I've written a Python2 script with fontforge library does the following:

    • Accepts a source font
    • Accepts a file containing all characters to be used. It can be a translation file, string asset file, HTML file, etc.
    • Output a font with characters that aren't shown in the file removed

    Here is the code:

    #!/usr/bin/python2
    import sys
    import fontforge
    
    if len(sys.argv) == 4:
        font = fontforge.open(sys.argv[1])
    
        f = open(sys.argv[2], "r")
    
        for i in f.read().decode("UTF-8"):
            font.selection[ord(i)] = True
        f.close()
    
        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\nbefore distributing the output font generated by this script.\nI'm not responsible for any legal issue caused by\ninappropriate use of this script!\n"
        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天全站免登陆