def matching_glyph(self, glyph, search_shape=True):
     # find glyph by name
     index = self._obj.FindGlyph(glyph.name)
     if index >= 0:
         return compGlyph(self._obj.glyphs[index])
     # find glyph by unicode
     if glyph.unicode:
         index = self._obj.FindGlyph(glyph.unicode)
         if index >= 0:
             return compGlyph(self._obj.glyphs[index])
     # find glyph by shape
     if search_shape:
         outline_description = sortinplace(
             compGlyph(glyph).outline_description(0))
         for candidate in self.glyphs:
             # check nodes number
             if candidate.nodes_number == glyph.nodes_number:
                 # make sure the candidate does not have a partner in the other font
                 if not compFont(glyph.parent).matching_glyph(
                         candidate, search_shape=False):
                     continue
                     # check whether the outlines match
                     if sortinplace(
                             compGlyph(candidate).outline_description(
                                 0)) == outline_description:
                         return compGlyph(candidate)
     return None
	def __init__(self, obj):
		self._obj = obj
		# calculate median of x-values of all nodes (not BCPs) for each master
		if self.nodes:
			self.x_median = [ sortinplace( [ node.Layer(m)[0].x for node in self.nodes ] )[len(self.nodes)/2] for m in range( self.layers_number ) ]
		else:
			self.x_median = [ 0 ] * self.layers_number
 def __init__(self, obj):
     self._obj = obj
     # calculate median of x-values of all nodes (not BCPs) for each master
     if self.nodes:
         self.x_median = [
             sortinplace([node.Layer(m)[0].x
                          for node in self.nodes])[len(self.nodes) / 2]
             for m in range(self.layers_number)
         ]
     else:
         self.x_median = [0] * self.layers_number
 def hints_description(self, master):
     hhints = [
         'h %i %i' % (h.widths[master], h.positions[master])
         for h in self.hhints
     ]
     vhints = [
         'v %i %i' %
         (h.widths[master], h.positions[master] - self.x_median[master])
         for h in self.vhints
     ]
     return sortinplace(hhints + vhints)
	def matching_glyph( self, glyph, search_shape = True ):
		# find glyph by name
		index = self._obj.FindGlyph( glyph.name )
		if index >= 0:
			return compGlyph( self._obj.glyphs[index] )
		# find glyph by unicode
		if glyph.unicode:
			index = self._obj.FindGlyph( glyph.unicode )
			if index >= 0:
				return compGlyph( self._obj.glyphs[index] )
		# find glyph by shape
		if search_shape:
			outline_description = sortinplace( compGlyph( glyph ).outline_description( 0 ) )
			for candidate in self.glyphs:
				# check nodes number
				if candidate.nodes_number == glyph.nodes_number:
					# make sure the candidate does not have a partner in the other font
					if not compFont( glyph.parent ).matching_glyph( candidate, search_shape = False ):
						continue
						# check whether the outlines match
						if sortinplace( compGlyph( candidate ).outline_description( 0 ) ) == outline_description:
							return compGlyph( candidate )
		return None
 def anchors_description(self, master):
     return sortinplace([
         '%i %i' %
         (a.Layer(master).y, a.Layer(master).x - self.x_median[master])
         for a in self.anchors
     ])
 def links_description(self):
     hlinks = ['h %i %i' % (link.node1, link.node2) for link in self.hlinks]
     vlinks = ['v %i %i' % (link.node1, link.node2) for link in self.vlinks]
     return sortinplace(hlinks + vlinks)
 def components_description(self, master):
     return sortinplace([
         '%i %i' %
         (c.deltas[master].y, c.deltas[master].x - self.x_median[master])
         for c in self.components
     ])
 def anchors_names(self):
     return sortinplace([anchor.name for anchor in self.anchors])
	def links_description( self ):
		hlinks = [ 'h %i %i' % ( link.node1, link.node2 ) for link in self.hlinks ]
		vlinks = [ 'v %i %i' % ( link.node1, link.node2 ) for link in self.vlinks ]
		return sortinplace( hlinks + vlinks )
	def hints_description( self, master ):
		hhints = [ 'h %i %i' % ( h.widths[master], h.positions[master] ) for h in self.hhints ]
		vhints = [ 'v %i %i' % ( h.widths[master], h.positions[master] - self.x_median[master] ) for h in self.vhints ]
		return sortinplace( hhints + vhints )
	def components_description( self, master ):
		return sortinplace( [ '%i %i' % ( c.deltas[master].y, c.deltas[master].x - self.x_median[master] ) for c in self.components ] )
	def anchors_names( self ):
		return sortinplace( [ anchor.name for anchor in self.anchors ] )
	def anchors_description( self, master ):
		return sortinplace( [ '%i %i' % ( a.Layer( master ).y, a.Layer( master ).x - self.x_median[master] ) for a in self.anchors ] )