def outline_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
    source.clear(contours=False, components=False, anchors=True, guides=False)
    
    # Temporary glyph to which the pen is writing
    target = RGlyph()
    target_pen = target.getPointPen()
    
    source_pen = OutlinePen(font, contrast=1, offset=5, connection="round")
    source.draw(source_pen)
    source_pen.drawSettings(drawInner=True, drawOuter=True)
    source_pen.drawPoints(target_pen)
    
    # Clear the original glyph and add the modfied outline
    source.clear()
    source.appendGlyph(target)
    
    # Restore the saved anchors
    for a in anchors:
        source.appendAnchor(a.name, a.position)
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. 3
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. 5
0
if __name__ == "__main__":
	"""
	
	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()
	
    
    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 ...
Esempio n. 7
0
#FLM: 010 FontLab to RoboFab and Back

# In which an adventurous glyph of your choice
# makes a trip into RoboFab land,
# and returns safely home after various inspections
# and modifications.

from robofab.world import CurrentGlyph, CurrentFont

c = CurrentGlyph()
f = CurrentFont()

from robofab.objects.objectsRF import RGlyph
d = RGlyph()

# woa! d is now  a rf version of a fl glyph!
d.appendGlyph(c)
d.width = 100

c.printDump()
d.printDump()

e = f.newGlyph('copyTest')

# dump the rf glyph back to a fl glyph!
e.appendGlyph(d)

# see, it still takes its own kind as well
e.appendGlyph(f['a'])
e.printDump()