Ejemplo n.º 1
0
def spikeGlyph(aGlyph, segmentLength=20, spikeLength=40, patternFunc=None):
	
	"""Add narly spikes or dents to the glyph.
	patternFunc is an optional function which recalculates the offset."""

	from math import atan2, sin, cos, pi
	
	new = _RGlyph()
	new.appendGlyph(aGlyph)
	new.width = aGlyph.width
	
	if len(new.contours) == 0:
		return
	flattenGlyph(new, segmentLength, segmentLines=True)
	for contour in new:
		l = len(contour.points)
		lastAngle = None
		for i in range(0, len(contour.points), 2):
			prev = contour.points[i-1]
			cur = contour.points[i]
			next = contour.points[(i+1)%l]
			angle = atan2(prev.x - next.x, prev.y - next.y)
			lastAngle = angle
			if patternFunc is not None:
				thisSpikeLength = patternFunc(spikeLength)
			else:
				thisSpikeLength = spikeLength
			cur.x -= sin(angle+.5*pi)*thisSpikeLength
			cur.y -= cos(angle+.5*pi)*thisSpikeLength
			new.update()
	aGlyph.clear()
	aGlyph.appendGlyph(new)
	aGlyph.update()
	return aGlyph
Ejemplo n.º 2
0
def spikeGlyph(aGlyph, segmentLength=20, spikeLength=40, patternFunc=None):
    """Add narly spikes or dents to the glyph.
	patternFunc is an optional function which recalculates the offset."""

    from math import atan2, sin, cos, pi

    new = _RGlyph()
    new.appendGlyph(aGlyph)
    new.width = aGlyph.width

    if len(new.contours) == 0:
        return
    flattenGlyph(new, segmentLength, segmentLines=True)
    for contour in new:
        l = len(contour.points)
        lastAngle = None
        for i in range(0, len(contour.points), 2):
            prev = contour.points[i - 1]
            cur = contour.points[i]
            next = contour.points[(i + 1) % l]
            angle = atan2(prev.x - next.x, prev.y - next.y)
            lastAngle = angle
            if patternFunc is not None:
                thisSpikeLength = patternFunc(spikeLength)
            else:
                thisSpikeLength = spikeLength
            cur.x -= sin(angle + .5 * pi) * thisSpikeLength
            cur.y -= cos(angle + .5 * pi) * thisSpikeLength
            new.update()
    aGlyph.clear()
    aGlyph.appendGlyph(new)
    aGlyph.update()
    return aGlyph
Ejemplo n.º 3
0
def makeTestGlyph():
    g = _RGlyph()
    pen = g.getPen()
    pen.moveTo((100, 100))
    pen.lineTo((800, 100))
    pen.curveTo((1000, 300), (1000, 600), (800, 800))
    pen.lineTo((100, 800))
    pen.lineTo((100, 100))
    pen.closePath()
    return g
Ejemplo n.º 4
0
def thresholdGlyph(aGlyph, threshold=10):
	from robofab.pens.adapterPens import PointToSegmentPen
	new = _RGlyph()
	filterpen = ThresholdPen(new.getPen(), threshold)
	wrappedPen = PointToSegmentPen(filterpen)
	aGlyph.drawPoints(wrappedPen)
	aGlyph.clear()
	aGlyph.appendGlyph(new)
	aGlyph.update()
	return aGlyph
Ejemplo n.º 5
0
def makeTestGlyph():
	g = _RGlyph()
	pen = g.getPen()
	pen.moveTo((100, 100))
	pen.lineTo((800, 100))
	pen.curveTo((1000, 300), (1000, 600), (800, 800))
	pen.lineTo((100, 800))
	pen.lineTo((100, 100))
	pen.closePath()
	return g
Ejemplo n.º 6
0
def thresholdGlyph(aGlyph, threshold=10):
    from robofab.pens.adapterPens import PointToSegmentPen
    new = _RGlyph()
    filterpen = ThresholdPen(new.getPen(), threshold)
    wrappedPen = PointToSegmentPen(filterpen)
    aGlyph.drawPoints(wrappedPen)
    aGlyph.clear()
    aGlyph.appendGlyph(new)
    aGlyph.update()
    return aGlyph
Ejemplo n.º 7
0
def thresholdGlyphPointPen(aGlyph, threshold=10):
    """ Same a thresholdGlyph, but using the ThresholdPointPen, which should respect anchors."""
    from robofab.pens.adapterPens import PointToSegmentPen
    new = _RGlyph()
    wrappedPen = new.getPointPen()
    filterpen = ThresholdPointPen(wrappedPen, threshold)
    aGlyph.drawPoints(filterpen)
    aGlyph.clear()
    new.drawPoints(aGlyph.getPointPen())
    aGlyph.update()
    return aGlyph
Ejemplo n.º 8
0
def thresholdGlyph(aGlyph, threshold=10):
	""" Convenience function that handles the filtering. """
	from robofab.pens.adapterPens import PointToSegmentPen
	new = _RGlyph()
	filterpen = ThresholdPen(new.getPen(), threshold)
	wrappedPen = PointToSegmentPen(filterpen)
	aGlyph.drawPoints(wrappedPen)
	aGlyph.clear()
	aGlyph.appendGlyph(new)
	aGlyph.update()
	return aGlyph
Ejemplo n.º 9
0
def thresholdGlyph(aGlyph, threshold=10):
    """ Convenience function that handles the filtering. """
    from robofab.pens.adapterPens import PointToSegmentPen
    new = _RGlyph()
    filterpen = ThresholdPen(new.getPen(), threshold)
    wrappedPen = PointToSegmentPen(filterpen)
    aGlyph.drawPoints(wrappedPen)
    aGlyph.clear()
    aGlyph.appendGlyph(new)
    aGlyph.update()
    return aGlyph
Ejemplo n.º 10
0
def thresholdGlyphPointPen(aGlyph, threshold=10):
	""" Same a thresholdGlyph, but using the ThresholdPointPen, which should respect anchors."""
	from robofab.pens.adapterPens import PointToSegmentPen
	new = _RGlyph()
	wrappedPen = new.getPointPen()
	filterpen = ThresholdPointPen(wrappedPen, threshold)
	aGlyph.drawPoints(filterpen)
	aGlyph.clear()
	new.drawPoints(aGlyph.getPointPen())
	aGlyph.update()
	return aGlyph
Ejemplo n.º 11
0
def thresholdGlyph(aGlyph, threshold=10):
    """Convenience function that applies the **ThresholdPen** to a glyph. Returns a new glyph object (from objectsRF.RGlyph)."""

    from robofab.pens.adapterPens import PointToSegmentPen
    new = _RGlyph()
    filterpen = ThresholdPen(new.getPen(), threshold)
    wrappedPen = PointToSegmentPen(filterpen)
    aGlyph.drawPoints(wrappedPen)
    aGlyph.clear()
    aGlyph.appendGlyph(new)
    aGlyph.update()
    return aGlyph
Ejemplo n.º 12
0
def thresholdGlyph(aGlyph, threshold=10):
	
	"""Convenience function that applies the **ThresholdPen** to a glyph. Returns a new glyph object (from objectsRF.RGlyph)."""
	
	from robofab.pens.adapterPens import PointToSegmentPen
	new = _RGlyph()
	filterpen = ThresholdPen(new.getPen(), threshold)
	wrappedPen = PointToSegmentPen(filterpen)
	aGlyph.drawPoints(wrappedPen)
	aGlyph.clear()
	aGlyph.appendGlyph(new)
	aGlyph.update()
	return aGlyph
Ejemplo n.º 13
0
def flattenGlyph(aGlyph, threshold=10, segmentLines=True):
    """Convenience function that applies the **FlattenPen** pen to a glyph. Returns a new glyph object."""

    from robofab.pens.adapterPens import PointToSegmentPen
    if len(aGlyph.contours) == 0:
        return
    new = _RGlyph()
    writerPen = new.getPen()
    filterpen = FlattenPen(writerPen, threshold, segmentLines)
    wrappedPen = PointToSegmentPen(filterpen)
    aGlyph.drawPoints(wrappedPen)
    aGlyph.clear()
    aGlyph.appendGlyph(new)
    aGlyph.update()
    return aGlyph
Ejemplo n.º 14
0
def flattenGlyph(aGlyph, threshold=10, segmentLines=True):
    """Replace curves with series of straight l ines."""

    from robofab.pens.adapterPens import PointToSegmentPen
    if len(aGlyph.contours) == 0:
        return
    new = _RGlyph()
    writerPen = new.getPen()
    filterpen = FlattenPen(writerPen, threshold, segmentLines)
    wrappedPen = PointToSegmentPen(filterpen)
    aGlyph.drawPoints(wrappedPen)
    aGlyph.clear()
    aGlyph.appendGlyph(new)
    aGlyph.update()
    return aGlyph
Ejemplo n.º 15
0
def flattenGlyph(aGlyph, threshold=10, segmentLines=True):

	"""Convenience function that applies the **FlattenPen** pen to a glyph. Returns a new glyph object."""

	from robofab.pens.adapterPens import PointToSegmentPen
	if len(aGlyph.contours) == 0:
		return
	new = _RGlyph()
	writerPen = new.getPen()
	filterpen = FlattenPen(writerPen, threshold, segmentLines)
	wrappedPen = PointToSegmentPen(filterpen)
	aGlyph.drawPoints(wrappedPen)
	aGlyph.clear()
	aGlyph.appendGlyph(new)
	aGlyph.update()
	return aGlyph
Ejemplo n.º 16
0
def flattenGlyph(aGlyph, threshold=10, segmentLines=True):

	"""Replace curves with series of straight l ines."""

	from robofab.pens.adapterPens import PointToSegmentPen
	if len(aGlyph.contours) == 0:
		return
	new = _RGlyph()
	writerPen = new.getPen()
	filterpen = FlattenPen(writerPen, threshold, segmentLines)
	wrappedPen = PointToSegmentPen(filterpen)
	aGlyph.drawPoints(wrappedPen)
	aGlyph.clear()
	aGlyph.appendGlyph(new)
	aGlyph.update()
	return aGlyph
Ejemplo n.º 17
0
 def copy(self, aParent=None):
     """Make a copy of this glyph.
     Note: the copy is not a duplicate fontlab glyph, but
     a RF RGlyph with the same outlines. The new glyph is
     not part of the fontlab font in any way. Use font.appendGlyph(glyph)
     to get it in a FontLab glyph again."""
     from robofab.objects.objectsRF import RGlyph as _RGlyph
     newGlyph = _RGlyph()
     newGlyph.appendGlyph(self)
     for attr in GLYPH_COPY_ATTRS:
         value = getattr(self, attr)
         setattr(newGlyph, attr, value)
     parent = self.getParent()
     if aParent is not None:
         newGlyph.setParent(aParent)
     elif self.getParent() is not None:
         newGlyph.setParent(self.getParent())
     return newGlyph
Ejemplo n.º 18
0
 def copy(self, aParent=None):
     """Make a copy of this glyph.
     Note: the copy is not a duplicate fontlab glyph, but
     a RF RGlyph with the same outlines. The new glyph is
     not part of the fontlab font in any way. Use font.appendGlyph(glyph)
     to get it in a FontLab glyph again."""
     from robofab.objects.objectsRF import RGlyph as _RGlyph
     newGlyph = _RGlyph()
     newGlyph.appendGlyph(self)
     for attr in GLYPH_COPY_ATTRS:
         value = getattr(self, attr)
         setattr(newGlyph, attr, value)
     parent = self.getParent()
     if aParent is not None:
         newGlyph.setParent(aParent)
     elif self.getParent() is not None:
         newGlyph.setParent(self.getParent())
     return newGlyph
Ejemplo n.º 19
0
from robofab.world import CurrentFont

# We need to import a class with a different
# implementation for the glyph object.
# It looks a bit odd, but this is how it is done
from robofab.objects.objectsRF import RGlyph as _RGlyph

f = CurrentFont()

# pick two compatible glyphs as masters
m1 = f["A"]
m2 = f["B"]

# make a new glyph object from this other glyph class
g = _RGlyph()

# interpolation factor which is  bound to make floats
oddFactor = 0.2382345

# go!
g.interpolate(oddFactor, m1, m2)

# let's have a look at the raw results
for contour in g:
    for pt in contour.points:
        print "float", pt.x, pt.y

# a glyph can round itself off:
g.round()
Ejemplo n.º 20
0
 def _getMathDestination(self):
     from robofab.objects.objectsRF import RGlyph as _RGlyph
     return _RGlyph()
Ejemplo n.º 21
0
 def _getMathDestination(self):
     from robofab.objects.objectsRF import RGlyph as _RGlyph
     return _RGlyph()
Ejemplo n.º 22
0
def _makeFlat(aGlyph, segmentLength = 10):
	"""Helper function to flatten the glyph with a given approximate segment length."""
	new = _RGlyph()
	filterpen = FlattenPen(aGlyph, new.getPen(), segmentLength)
	aGlyph.draw(filterpen)
	return new
Ejemplo n.º 23
0
def _makeFlat(aGlyph, segmentLength=10):
    """Helper function to flatten the glyph with a given approximate segment length."""
    new = _RGlyph()
    filterpen = FlattenPen(aGlyph, new.getPen(), segmentLength)
    aGlyph.draw(filterpen)
    return new