otlFeature.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from lxml.etree import Element
  2. from data import Tag
  3. # OTLFeature
  4. # -----------------------------
  5. # Classes representing common OpenType Layout Feature structures.
  6. # (https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#features-and-lookups)
  7. class Feature:
  8. """
  9. Class representing a Feature table.
  10. Currently not editable atm - it's just designed to have the right data for forc's particular context.
  11. """
  12. def __init__(self):
  13. self.whatever = 0
  14. def toTTX(self):
  15. feature = Element("Feature")
  16. feature.append(Element("LookupListIndex", {"index": "0", "value": "0"}))
  17. return feature
  18. class FeatureRecord:
  19. """
  20. Class representing a placeholder FeatureRecord table.
  21. Currently not editable atm - it's just designed to have the right data for forc's particular context.
  22. """
  23. def __init__(self):
  24. self.tag = Tag("liga")
  25. self.feature = Feature() # placeholder feature
  26. def toTTX(self, index):
  27. featureRecord = Element("FeatureRecord", {"index": str(index) })
  28. featureRecord.append(Element("FeatureTag", {"value": str(self.tag) }))
  29. featureRecord.append(self.feature.toTTX())
  30. return featureRecord
  31. class FeatureList:
  32. """
  33. Class representing a FeatureList table.
  34. """
  35. def __init__(self):
  36. self.featureRecords = [FeatureRecord()]
  37. def toTTX(self):
  38. featureList = Element("FeatureList")
  39. for index, fr in enumerate(self.featureRecords):
  40. featureList.append(fr.toTTX(index))
  41. return featureList