morx.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from lxml.etree import Element, ElementTree, fromstring
  2. ################################
  3. # CURRENTLY DISCONTINUED TABLE #
  4. ################################
  5. def morphSubtable(index):
  6. morph = Element("MorphSubstable", {"index": index})
  7. return morph
  8. def morphFeature(index, featureType, featureSetting, enableFlags, disableFlags):
  9. feature = Element("MorphFeature", {"index": index})
  10. feature.append(Element("FeatureType", {"value": featureType}))
  11. feature.append(Element("FeatureSetting", {"value": featureSetting}))
  12. feature.append(Element("EnableFlags", {"value": enableFlags}))
  13. feature.append(Element("DisableFlags", {"value": disableFlags}))
  14. return feature
  15. def toTTX(glyphs):
  16. """
  17. Generates and returns a morx table with ligature data.
  18. """
  19. morx = Element("morx")
  20. # header stuff
  21. # (hardcoded)
  22. morx.append(Element("Version", {"value": "2"}))
  23. morx.append(Element("Reserved", {"value": "0"}))
  24. # metamorphosis chain
  25. # (we only get the one)
  26. morphChain = Element("MorphChain", {"index": "0"})
  27. # chain header
  28. morphChain.append(Element("DefaultFlags", {"value": "0x00000003"})) #default spec for subtables
  29. # feature array
  30. morphChain.append(morphFeature("0", "1", "0", "0x00000001", "0xFFFFFFFF"))
  31. morphChain.append(morphFeature("1", "1", "1", "0x00000000", "0xFFFFFFFE"))
  32. morphChain.append(morphFeature("2", "27", "2", "0x00000002", "0xFFFFFFFF"))
  33. morphChain.append(morphFeature("3", "27", "3", "0x00000000", "0xFFFFFFFD"))
  34. morphChain.append(morphFeature("4", "0", "1", "0x00000000", "0x00000000"))
  35. # metamorphosis subtables
  36. # morphChain.append(morphSubtable("0"))
  37. morx.append(morphChain)
  38. return morx