【问题标题】:FontForge Python extension: Can't get gsub_multiple lookup to workFontForge Python 扩展:无法让 gsub_multiple 查找工作
【发布时间】:2013-11-28 21:15:18
【问题描述】:

我正在尝试使用 fontforge Python 库/包装器,但我似乎无法使用多个字符替换。 也许你们可以帮助指出我做错了什么?

基本上,我正在尝试将“ABC”替换为“a”的字符表示,但一旦它起作用,我将通过适当的替换来扩展它。

from random import randint
from datetime import datetime

def add_pixel(pen, x, y, scale = 100):
    pen.moveTo(((x + 0) * scale, (y + 0) * scale))
    pen.lineTo(((x + 0) * scale, (y + 1) * scale))
    pen.lineTo(((x + 1) * scale, (y + 1) * scale))
    pen.lineTo(((x + 1) * scale, (y + 0) * scale))
    pen.closePath()

def add_character(font, code, name):
    if not name in list(font):
        font.createChar(code, name)

    pen = font[code].glyphPen()
    for i in range(1, 15):
        add_pixel(pen, randint(0, 15), randint(0, 15), 100 * 10 / 15)

try:
    import fontforge
except Exception, e:
    raise
else:
    font = fontforge.font()
    font.familyname = "font"
    font.fontname = "font x15"
    font.fullname = "font x15"
    font.version = datetime.now().strftime("%Y-%m-%d %H:%M")

    # lower
    for c in range(0x61, 0x61 + 26):
        add_character(font, c, unichr(c))

    # upper
    for c in range(0x41, 0x41 + 26):
        add_character(font, c, unichr(c))

    font.addLookup("gsub", "gsub_multiple", (), (("dlig",(("latn",("dflt")),)),))
    font.addLookupSubtable("gsub", "gsub_n")

    glyph = font["a"]
    glyph.addPosSub("gsub_n", ("A", "B", "C"))

    # font.save("font.x15.sfd")
    font.generate("font.x15.otf", flags=("PfEd-lookups", "opentype"))
finally:
    pass

【问题讨论】:

    标签: python gsub opentype fontforge


    【解决方案1】:

    我认为您的查找类型与功能不匹配。

    # Try "gsub_ligature" as type.
    font.addLookup("gsub", "gsub_ligature", (), (("dlig",(("latn",("dflt")),)),))
    

    提示:您可以通过生成功能文件来检查您的功能:

    font.generateFeatureFile("features.fea")
    

    【讨论】:

    • 第一行就像一个魅力。第二个没有,但我想我现在可以扩展一个工作状态。谢谢!
    • 我删除了第二行,因为“subs”(下标)功能不相关。不客气!
    猜你喜欢
    • 2018-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-02
    • 1970-01-01
    • 2017-05-03
    • 1970-01-01
    相关资源
    最近更新 更多