2013-11-15 56 views
2

我正在尝试fontforge Python库/包装的东西,我似乎并没有得到多个字符替代工作。 也许你加尔和家伙可以帮我指点我做错了什么?FontForge Python的扩展:无法让gsub_multiple查找工作

基本上,我试图用“a”的字符表示来代替“ABC”,但是我打算在正常工作时用适当的替换来扩展它。

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 

回答

0

我认为你的查找类型doens't匹配的功能。

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

提示:您可以通过生成特征文件检查你的特点:

font.generateFeatureFile("features.fea") 
+0

第一线工作就像一个魅力。第二个没有,但我想我现在有一个工作状态可以延长。谢谢! – user2996332

+0

我删除了第二行,因为'subs'(下标)功能不相关。别客气! – allcaps