1from __future__ import print_function, division, absolute_import
2from fontTools.misc.py23 import *
3from fontTools import cffLib
4from . import DefaultTable
5
6
7class table_C_F_F_(DefaultTable.DefaultTable):
8
9	def __init__(self, tag):
10		DefaultTable.DefaultTable.__init__(self, tag)
11		self.cff = cffLib.CFFFontSet()
12		self._gaveGlyphOrder = False
13
14	def decompile(self, data, otFont):
15		self.cff.decompile(StringIO(data), otFont)
16		assert len(self.cff) == 1, "can't deal with multi-font CFF tables."
17
18	def compile(self, otFont):
19		f = StringIO()
20		self.cff.compile(f, otFont)
21		return f.getvalue()
22
23	def haveGlyphNames(self):
24		if hasattr(self.cff[self.cff.fontNames[0]], "ROS"):
25			return False  # CID-keyed font
26		else:
27			return True
28
29	def getGlyphOrder(self):
30		if self._gaveGlyphOrder:
31			from fontTools import ttLib
32			raise ttLib.TTLibError("illegal use of getGlyphOrder()")
33		self._gaveGlyphOrder = True
34		return self.cff[self.cff.fontNames[0]].getGlyphOrder()
35
36	def setGlyphOrder(self, glyphOrder):
37		pass
38		# XXX
39		#self.cff[self.cff.fontNames[0]].setGlyphOrder(glyphOrder)
40
41	def toXML(self, writer, otFont, progress=None):
42		self.cff.toXML(writer, progress)
43
44	def fromXML(self, name, attrs, content, otFont):
45		if not hasattr(self, "cff"):
46			self.cff = cffLib.CFFFontSet()
47		self.cff.fromXML(name, attrs, content)
48
49