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