gdef.py 941 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from lxml.etree import Element, ElementTree, fromstring
  2. from transform.bytes import outputTableBytes
  3. ################################
  4. # CURRENTLY DISCONTINUED TABLE #
  5. ################################
  6. def toTTX(glyphs):
  7. """
  8. Creates a basic GDEF table.
  9. """
  10. gdef = Element("GDEF")
  11. gdef.append(Element("Version", {"value": "0x00010000"}))
  12. # GlyphClassDef
  13. gcd = Element("GlyphClassDef", {"Format": "2"})
  14. for g in glyphs["img_empty"]:
  15. if g.codepoints.seq[0] != 0: # filter out .notdef
  16. if len(g.codepoints.seq) > 1: # if a ligature
  17. classNum = 2
  18. else:
  19. classNum = 1
  20. gcd.append(Element("ClassDef", {"glyph": g.name(), "class": str(classNum)}))
  21. gdef.append(gcd)
  22. # LigCaretList
  23. lcl = Element("LigCaretList")
  24. lcl.append(Element("Coverage", {"Format": "2"}))
  25. gdef.append(lcl)
  26. return outputTableBytes(gdef)