C_F_F_.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from io import BytesIO
  2. from fontTools import cffLib
  3. from . import DefaultTable
  4. class table_C_F_F_(DefaultTable.DefaultTable):
  5. def __init__(self, tag=None):
  6. DefaultTable.DefaultTable.__init__(self, tag)
  7. self.cff = cffLib.CFFFontSet()
  8. self._gaveGlyphOrder = False
  9. def decompile(self, data, otFont):
  10. self.cff.decompile(BytesIO(data), otFont, isCFF2=False)
  11. assert len(self.cff) == 1, "can't deal with multi-font CFF tables."
  12. def compile(self, otFont):
  13. f = BytesIO()
  14. self.cff.compile(f, otFont, isCFF2=False)
  15. return f.getvalue()
  16. def haveGlyphNames(self):
  17. if hasattr(self.cff[self.cff.fontNames[0]], "ROS"):
  18. return False # CID-keyed font
  19. else:
  20. return True
  21. def getGlyphOrder(self):
  22. if self._gaveGlyphOrder:
  23. from fontTools import ttLib
  24. raise ttLib.TTLibError("illegal use of getGlyphOrder()")
  25. self._gaveGlyphOrder = True
  26. return self.cff[self.cff.fontNames[0]].getGlyphOrder()
  27. def setGlyphOrder(self, glyphOrder):
  28. pass
  29. # XXX
  30. # self.cff[self.cff.fontNames[0]].setGlyphOrder(glyphOrder)
  31. def toXML(self, writer, otFont):
  32. self.cff.toXML(writer)
  33. def fromXML(self, name, attrs, content, otFont):
  34. if not hasattr(self, "cff"):
  35. self.cff = cffLib.CFFFontSet()
  36. self.cff.fromXML(name, attrs, content, otFont)