def randomize_glyph(glyph):
    source = glyph
    font = glyph._parent

    # Save the anchors from the original glyph in a list
    anchors = [a for a in source.anchors]

    # Remove all anchors from the glyph so they don't interfere with our processing
    for a in anchors:
        source.removeAnchor(a)
    
    # Convert to small segments
    source = flattenGlyph(aGlyph=source, threshold=20, segmentLines=True)

    # Temporary glyph to which the pen is writing
    target = RGlyph()
    target_pen = target.getPen()

    source_pen = MyPen(font, target_pen, 8)
    source.draw(source_pen)

    # Clear the original glyph and add the modfied outline
    source.clear(components=False)
    source.appendGlyph(target)

    # Restore the saved anchors
    for a in anchors:
        source.appendAnchor(a.name, a.position)
Esempio n. 2
0
	def makeTestGlyph():
		# make a simple glyph that we can test the pens with.
		from robofab.objects.objectsRF import RGlyph
		testGlyph = RGlyph()
		testGlyph.name = "testGlyph"
		testGlyph.width = 1000
		pen = testGlyph.getPen()
		pen.moveTo((100, 100))
		pen.lineTo((900, 100))
		pen.lineTo((900, 800))
		pen.lineTo((100, 800))
		# a curve
		pen.curveTo((120, 700), (120, 300), (100, 100))
		pen.closePath()
		return testGlyph
 def makeTestGlyph():
     # make a simple glyph that we can test the pens with.
     from robofab.objects.objectsRF import RGlyph
     testGlyph = RGlyph()
     testGlyph.name = "testGlyph"
     testGlyph.width = 1000
     pen = testGlyph.getPen()
     pen.moveTo((100, 100))
     pen.lineTo((900, 100))
     pen.lineTo((900, 800))
     pen.lineTo((100, 800))
     # a curve
     pen.curveTo((120, 700), (120, 300), (100, 100))
     pen.closePath()
     return testGlyph
Esempio n. 4
0
	"""
	
	beginPath
	((112, 651), 'line', False, None)
	((112, 55), 'line', False, None)
	((218, 55), 'line', False, None)
	((218, 651), 'line', False, None)
	endPath
	
	"""
	# a test
	
	from robofab.objects.objectsRF import RGlyph
	
	g = RGlyph()
	p = g.getPen()
	p.moveTo((112, 651))
	p.lineTo((112, 55))
	p.lineTo((218, 55))
	p.lineTo((218, 651))
	p.closePath()
	
	print g, len(g)
	
	digestPen = DigestPointPen()
	g.drawPoints(digestPen)

	print
	print "getDigest", digestPen.getDigest()
	
	print
    
    def _lineTo(self, pt):
        self.writer_pen.lineTo(pt)
    
    def _curveToOne(self, bcp1, bcp2, pt):
        self.writer_pen.curveTo(bcp1, bcp2, pt)
    
    def _closePath(self):
        self.writer_pen.closePath()
    
    def _endPath(self):
        self.writer_pen.endPath()
    
    def addComponent(self, baseGlyphName, transformation):
        pass


source = CurrentGlyph()

# Temporary glyph to which the pen is writing
target = RGlyph()
target_pen = target.getPen()

source_pen = MyPen(CurrentFont(), target_pen)
source.draw(source_pen)

# Clear the original glyph and add the modfied outline
source.clear()
source.appendGlyph(target)

# You will notice any anchors are converted to stray points ...