os2Extra.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import struct
  2. from lxml.etree import Element
  3. class PANOSE:
  4. """
  5. Class representing the PANOSE segment of an OS/2 table.
  6. """
  7. def __init__(self
  8. , bFamilyType
  9. , bSerifStyle
  10. , bWeight
  11. , bProportion
  12. , bContrast
  13. , bStrokeVariation
  14. , bArmStyle
  15. , bLetterForm
  16. , bMidline
  17. , bXHeight
  18. ):
  19. # these are all hard-coded to be the optimal values for an emoji font.
  20. self.bFamilyType = bFamilyType
  21. self.bSerifStyle = bSerifStyle
  22. self.bWeight = bWeight
  23. self.bProportion = bProportion
  24. self.bContrast = bContrast
  25. self.bStrokeVariation = bStrokeVariation
  26. self.bArmStyle = bArmStyle
  27. self.bLetterForm = bLetterForm
  28. self.bMidline = bMidline
  29. self.bXHeight = bXHeight
  30. def toTTX(self):
  31. panose = Element("panose")
  32. panose.append(Element("bFamilyType", {'value': str(self.bFamilyType) }))
  33. panose.append(Element("bSerifStyle", {'value': str(self.bSerifStyle) }))
  34. panose.append(Element("bWeight", {'value': str(self.bWeight) }))
  35. panose.append(Element("bProportion", {'value': str(self.bProportion) }))
  36. panose.append(Element("bContrast", {'value': str(self.bContrast) }))
  37. panose.append(Element("bStrokeVariation", {'value': str(self.bStrokeVariation) }))
  38. panose.append(Element("bArmStyle", {'value': str(self.bArmStyle) }))
  39. panose.append(Element("bLetterForm", {'value': str(self.bLetterForm) }))
  40. panose.append(Element("bMidline", {'value': str(self.bMidline) }))
  41. panose.append(Element("bXHeight", {'value': str(self.bXHeight) }))
  42. return panose
  43. def toBytes(self):
  44. return struct.pack(">HHHHHHHHHH" # All are UInt16s.
  45. , self.bFamilyType
  46. , self.bSerifStyle
  47. , self.bWeight
  48. , self.bProportion
  49. , self.bContrast
  50. , self.bStrokeVariation
  51. , self.bArmStyle
  52. , self.bLetterForm
  53. , self.bMidline
  54. , self.bXHeight
  55. )