Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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()
Пример #20
0
 def _getMathDestination(self):
     from robofab.objects.objectsRF import RGlyph as _RGlyph
     return _RGlyph()
Пример #21
0
 def _getMathDestination(self):
     from robofab.objects.objectsRF import RGlyph as _RGlyph
     return _RGlyph()
Пример #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
Пример #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