"""A couple of point pens which return the glyph as a list of basic values."""


from robofab.pens.pointPen import AbstractPointPen


class DigestPointPen(AbstractPointPen):

	"""Calculate a digest of all points
		AND coordinates
		AND components
	in a glyph.
	"""

	def __init__(self, ignoreSmoothAndName=False):
		self._data = []
		self.ignoreSmoothAndName = ignoreSmoothAndName

	def beginPath(self):
		self._data.append('beginPath')

	def endPath(self):
		self._data.append('endPath')

	def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs):
		if self.ignoreSmoothAndName:
			self._data.append((pt, segmentType))
		else:
			self._data.append((pt, segmentType, smooth, name))

	def addComponent(self, baseGlyphName, transformation):
		self._data.append((baseGlyphName, tuple(transformation)))

	def getDigest(self):
		return tuple(self._data)
	
	def getDigestPointsOnly(self):
		"""Return a tuple with all coordinates of all points, 
			but without smooth info or drawing instructions.
			For instance if you want to compare 2 glyphs in shape,
			but not interpolatability.
			"""
		points = []
		for item in self._data:
			points.append(item[0])
		points.sort()
		return tuple(points)


class DigestPointStructurePen(DigestPointPen):

	"""Calculate a digest of the structure of the glyph
		NOT coordinates
		NOT values.
	"""

	def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs):
		self._data.append(segmentType)

	def addComponent(self, baseGlyphName, transformation):
		self._data.append(baseGlyphName)


"""A couple of point pens which return the glyph as a list of basic values."""


from robofab.pens.pointPen import AbstractPointPen


class DigestPointPen(AbstractPointPen):

	"""Calculate a digest of all points
		AND coordinates
		AND components
	in a glyph.
	"""

	def __init__(self, ignoreSmoothAndName=False):
		self._data = []
		self.ignoreSmoothAndName = ignoreSmoothAndName

	def beginPath(self):
		self._data.append('beginPath')

	def endPath(self):
		self._data.append('endPath')

	def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs):
		if self.ignoreSmoothAndName:
			self._data.append((pt, segmentType))
		else:
			self._data.append((pt, segmentType, smooth, name))

	def addComponent(self, baseGlyphName, transformation):
		t = []
		for v in transformation:
			if int(v) == v:
				t.append(int(v))
			else:
				t.append(v)
		self._data.append((baseGlyphName, tuple(t)))

	def getDigest(self):
		return tuple(self._data)
	
	def getDigestPointsOnly(self):
		"""Return a tuple with all coordinates of all points, 
			but without smooth info or drawing instructions.
			For instance if you want to compare 2 glyphs in shape,
			but not interpolatability.
			"""
		points = []
		for item in self._data:
			points.append(item[0])
		points.sort()
		return tuple(points)


class DigestPointStructurePen(DigestPointPen):

	"""Calculate a digest of the structure of the glyph
		NOT coordinates
		NOT values.
	"""

	def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs):
		self._data.append(segmentType)

	def addComponent(self, baseGlyphName, transformation):
		self._data.append(baseGlyphName)


Change to the way the transformation tuple of a component is added to the digest. Values which can be ints (int(a) == a) are added as int, rather than float. This solves a problem comparing digests in UFO and VFB.