Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# -*- coding: utf-8 -*-
import sys
import urllib
import fontforge
import psMat
BASE_FONT = "TW-Kai-98_1.ttf"
IDS_URL = "字體=%s"
IDS_FONT = "楷體"
IDS_SVG_OUTPUT = "ids_svg/%s.svg"
def main():
base_font =
font = fontforge.font()
font.encoding = "UnicodeBmp"
font.addLookup('ligatures','gsub_ligature', (),[['liga',[['DFLT', ['dflt']], ['latn', ['dflt']]]]])
font.addLookupSubtable('ligatures', 'ids_lookup')
code = 0
for ids_code in sys.stdin:
add_ids_glyph(font, base_font, ids_code.strip(), code)
code += 1
def add_ids_glyph(font, base_font, ids_code, code):
print ids_code
glyph_code = "_".join(c.encode("unicode_escape").strip("\\") for c in ids_code.decode("utf-8"))
ligature_tuple = tuple("uni%s" % (c.encode("unicode_escape").strip("\\u").upper()) for c in ids_code.decode("utf-8"))
urllib.urlretrieve(IDS_URL % (ids_code,IDS_FONT), IDS_SVG_OUTPUT % (glyph_code))
for c in ids_code.decode("utf-8"):"unicode", None), ord(c))
base_font.copy()"unicode", None), ord(c))
glyph = font.createChar(-1, "ids%04x" % (code))
glyph.importOutlines(IDS_SVG_OUTPUT % (glyph_code))
glyph.transform(psMat.translate(0, -630))
glyph.width = 1000
glyph.addPosSub('ids_lookup', ligature_tuple)
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment