vmtx.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from lxml.etree import Element
  2. from transform.bytes import outputTableBytes
  3. class vmtxMetric:
  4. """
  5. Class representing a single metric in a vmtx table.
  6. """
  7. def __init__(self, name, height, tsb):
  8. self.name = name
  9. self.height = height
  10. self.TSB = tsb
  11. def toTTX(self):
  12. return Element("mtx", {"name": self.name
  13. ,"height": str(self.height)
  14. ,"tsb": str(self.TSB)
  15. })
  16. class vmtx:
  17. """
  18. Class representing a vmtx table.
  19. """
  20. # number of Vmetrics must equal the total number of glyphs in the font.
  21. def __init__(self, m, glyphs):
  22. self.metrics = []
  23. for g in glyphs["img_empty"]:
  24. self.metrics.append(vmtxMetric(g.name(), m['metrics']['normalHeight'], m['metrics']['normalTSB']))
  25. def toTTX(self):
  26. vmtx = Element("vmtx")
  27. for m in self.metrics:
  28. vmtx.append(m.toTTX())
  29. return vmtx
  30. def toBytes(self):
  31. return outputTableBytes(b'\0') #temp
  32. # TODO: figure out how to compile vmtx in bytes.