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