<commit_before>import DefaultTable
from fontTools import cffLib


# temporary switch:
# - if true use possibly incomplete compile/decompile/toXML/fromXML implementation
# - if false use DefaultTable, ie. dump as hex.
TESTING_CFF = 0


class table_C_F_F_(DefaultTable.DefaultTable):
	
	def __init__(self, tag):
		DefaultTable.DefaultTable.__init__(self, tag)
		self.cff = cffLib.CFFFontSet()
		self._gaveGlyphOrder = 0
	
	def decompile(self, data, otFont):
		from cStringIO import StringIO
		self.data = data  # XXX while work is in progress...
		self.cff.decompile(StringIO(data))
		assert len(self.cff.fonts) == 1, "can't deal with multi-font CFF tables."
	
	#def compile(self, otFont):
	#	xxx
	
	def haveGlyphNames(self):
		if hasattr(self.cff.fonts[self.cff.fontNames[0]], "ROS"):
			return 0  # CID-keyed font
		else:
			return 1
	
	def getGlyphOrder(self):
		if self._gaveGlyphOrder:
			from fontTools import ttLib
			raise ttLib.TTLibError, "illegal use of getGlyphOrder()"
		self._gaveGlyphOrder = 1
		return self.cff.fonts[self.cff.fontNames[0]].getGlyphOrder()
	
	def setGlyphOrder(self, glyphOrder):
		self.cff.fonts[self.cff.fontNames[0]].setGlyphOrder(glyphOrder)
	
	def toXML(self, writer, otFont, progress=None):
		if TESTING_CFF:
			self.cff.toXML(writer, progress)
		else:
			# dump as hex as long as we can't compile
			DefaultTable.DefaultTable.toXML(self, writer, otFont)
	
	#def fromXML(self, (name, attrs, content), otFont):
	#	xxx
<commit_msg>some changes to adapt to new cffLib.py<commit_after>import DefaultTable
from fontTools import cffLib


# temporary switch:
# - if true use possibly incomplete compile/decompile/toXML/fromXML implementation
# - if false use DefaultTable, ie. dump as hex.
TESTING_CFF = 0


class table_C_F_F_(DefaultTable.DefaultTable):
	
	def __init__(self, tag):
		DefaultTable.DefaultTable.__init__(self, tag)
		self.cff = cffLib.CFFFontSet()
		self._gaveGlyphOrder = 0
	
	def decompile(self, data, otFont):
		from cStringIO import StringIO
		self.data = data  # XXX while work is in progress...
		self.cff.decompile(StringIO(data))
		assert len(self.cff) == 1, "can't deal with multi-font CFF tables."
	
	#def compile(self, otFont):
	#	xxx
	
	def haveGlyphNames(self):
		if hasattr(self.cff[self.cff.fontNames[0]], "ROS"):
			return 0  # CID-keyed font
		else:
			return 1
	
	def getGlyphOrder(self):
		if self._gaveGlyphOrder:
			from fontTools import ttLib
			raise ttLib.TTLibError, "illegal use of getGlyphOrder()"
		self._gaveGlyphOrder = 1
		return self.cff[self.cff.fontNames[0]].getGlyphOrder()
	
	def setGlyphOrder(self, glyphOrder):
		pass
		# XXX
		#self.cff[self.cff.fontNames[0]].setGlyphOrder(glyphOrder)
	
	def toXML(self, writer, otFont, progress=None):
		if TESTING_CFF:
			self.cff.toXML(writer, progress)
		else:
			# dump as hex as long as we can't compile
			DefaultTable.DefaultTable.toXML(self, writer, otFont)
	
	#def fromXML(self, (name, attrs, content), otFont):
	#	xxx

{'fraction_non_alphanumeric': 0.11028164234815066, 'fraction_numerical': 0.006107906345436036, 'mean_word_length': 4.292639138240575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6595562', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1042, 'n_words': 266}