1from fontTools.misc.textTools import safeEval 2from . import DefaultTable 3import sys 4import array 5 6class table__c_v_t(DefaultTable.DefaultTable): 7 8 def decompile(self, data, ttFont): 9 values = array.array("h") 10 values.frombytes(data) 11 if sys.byteorder != "big": values.byteswap() 12 self.values = values 13 14 def compile(self, ttFont): 15 values = self.values[:] 16 if sys.byteorder != "big": values.byteswap() 17 return values.tobytes() 18 19 def toXML(self, writer, ttFont): 20 for i in range(len(self.values)): 21 value = self.values[i] 22 writer.simpletag("cv", value=value, index=i) 23 writer.newline() 24 25 def fromXML(self, name, attrs, content, ttFont): 26 if not hasattr(self, "values"): 27 self.values = array.array("h") 28 if name == "cv": 29 index = safeEval(attrs["index"]) 30 value = safeEval(attrs["value"]) 31 for i in range(1 + index - len(self.values)): 32 self.values.append(0) 33 self.values[index] = value 34 35 def __len__(self): 36 return len(self.values) 37 38 def __getitem__(self, index): 39 return self.values[index] 40 41 def __setitem__(self, index, value): 42 self.values[index] = value 43 44 def __delitem__(self, index): 45 del self.values[index] 46