예제 #1
0
def reverseContours(glyph):
    glyphCopy = RGlyph()
    glyphCopy.width = glyph.width
    pointPen = glyphCopy.getPointPen()
    reversePen = ReverseContourPointPen(pointPen)
    glyph.drawPoints(reversePen)
    return glyphCopy
예제 #2
0
def extractComposites(glyph):
    """Return a new glyph with outline copies of each composite from the source glyph."""

    decomposedComposites = RGlyph()

    if len(glyph.components):
        font = glyph.layer

        for comp in reversed(glyph.components):

            # obtain source data
            baseGlyphName = comp.baseGlyph
            baseGlyph = font[baseGlyphName]
            t = transform.Transform(*comp.transformation)

            # create a temporary glyph on which to draw the decomposed composite
            single_decomposedComposite = RGlyph()
            decompPen = single_decomposedComposite.getPen()
            baseGlyph.draw(decompPen)
            single_decomposedComposite.transformBy(tuple(t))

            # add single composite to the returned glyph
            decomposedComposites.appendGlyph(single_decomposedComposite)

    return decomposedComposites
예제 #3
0
def _makeTestGlyphLine():
    from fontParts.fontshell import RGlyph
    testGlyph = RGlyph()
    testGlyph.name = "testGlyph"
    testGlyph.width = 500
    testPen = testGlyph.getPen()
    testPen.moveTo((10, 0))
    testPen.lineTo((30, 0))
    testPen.lineTo((50, 0))
    testPen.lineTo((70, 0))
    testPen.lineTo((90, 0))
    testPen.endPath()
    return testGlyph
예제 #4
0
def _makeTestGlyphRect():
    # make a simple glyph that we can test the pens with.
    from fontParts.fontshell import RGlyph
    testGlyph = RGlyph()
    testGlyph.name = "testGlyph"
    testGlyph.width = 500
    pen = testGlyph.getPen()
    pen.moveTo((100, 100))
    pen.lineTo((100, 300))
    pen.lineTo((300, 300))
    pen.lineTo((300, 100))
    pen.closePath()
    return testGlyph
예제 #5
0
def _makeTestGlyphWithCurve():
    # make a simple glyph that we can test the pens with.
    from fontParts.fontshell import RGlyph
    testGlyph = RGlyph()
    testGlyph.name = "testGlyph"
    testGlyph.width = 500
    pen = testGlyph.getPen()
    pen.moveTo((84, 37))
    pen.lineTo((348, 37))
    pen.lineTo((348, 300))
    pen.curveTo((265, 350.0), (177, 350.0), (84, 300))
    pen.closePath()
    return testGlyph
예제 #6
0
def _makeTestGlyph():
    # make a simple glyph that we can test the pens with.
    from fontParts.fontshell import RGlyph
    testGlyph = RGlyph()
    testGlyph.name = "testGlyph"
    testGlyph.width = 500
    pen = testGlyph.getPen()
    pen.moveTo((10, 10))
    pen.lineTo((10, 30))
    pen.lineTo((30, 30))
    pen.lineTo((30, 10))
    pen.closePath()
    return testGlyph
def _makeTestGlyph():
    # make a simple glyph that we can test the pens with.
    from fontParts.fontshell import RGlyph
    testGlyph = RGlyph()
    testGlyph.name = "testGlyph"
    testGlyph.width = 1000
    pen = testGlyph.getPen()
    pen.moveTo((100, 100))
    pen.lineTo((900, 100))
    pen.lineTo((900, 109))
    pen.lineTo((900, 800))
    pen.lineTo((100, 800))
    pen.closePath()
    pen.addComponent("a", (1, 0, 0, 1, 0, 0))
    return testGlyph
예제 #8
0
def _makeTestGlyph():
    # make a simple glyph that we can test the pens with.
    from fontParts.fontshell import RGlyph
    testGlyph = RGlyph()
    testGlyph.name = "testGlyph"
    testGlyph.width = 1000
    pen = testGlyph.getPen()
    pen.moveTo((100, 100))
    pen.lineTo((900, 100))
    pen.lineTo((900, 109))
    pen.lineTo((900, 800))
    pen.lineTo((100, 800))
    pen.closePath()
    pen.addComponent("a", (1, 0, 0, 1, 0, 0))
    return testGlyph
예제 #9
0
 def _getInstanceGlyph(self, location, masters):
     I = self._getInstance(location, masters)
     if I is not None:
         return I.extractGlyph(RGlyph())
     else:
         errorMessage = self.mutatorErrors[-1]['error']
         return ErrorGlyph('Interpolation', errorMessage)
예제 #10
0
 def test_extract_scaled_glyph_as_FontParts_Glyph(self):
     """Test scaled glyph retrieval as a FontParts Glyph."""
     from fontParts.fontshell import RGlyph
     for testFont in [self.smallFont, self.stemedSmallFont]:
         scaledGlyph = RGlyph()
         for glyphName in self.glyphNames:
             testFont.extractGlyph(glyphName, scaledGlyph)
             self.assertIsInstance(scaledGlyph, RGlyph)
예제 #11
0
def removeOverlap(glyph):
    glyphCopy = RGlyph()
    glyphCopy.width = glyph.width
    pointPen = glyphCopy.getPointPen()
    glyph.drawPoints(pointPen)
    glyphCopy.removeOverlap()
    return glyphCopy
예제 #12
0
def copyContours(glyph):
    glyphCopy = RGlyph()
    glyphCopy.width = glyph.width
    pen = glyphCopy.getPen()
    glyph.draw(pen)
    glyphCopy.unicode = glyph.unicode
    glyphCopy.name = glyph.name
    return glyphCopy
예제 #13
0
def freezeGlyph(glyph):
    """Return a copy of a glyph, with components decomposed and all overlap removed."""

    toRFGlyph = RGlyph()
    toRFpen = toRFGlyph.getPen()
    glyph.draw(toRFpen)

    if len(glyph.components):
        decomposedComponents = extractComposites(glyph)
        decomposedComponents.draw(toRFpen)

    singleContourGlyph = RGlyph()
    singleContourGlyph.width = glyph.width
    singleContourGlyph.name = glyph.name
    pointPen = singleContourGlyph.getPointPen()

    if len(toRFGlyph.contours) > 1:

        try:
            booleanGlyphs = []

            for c in toRFGlyph.contours:
                if len(c) > 1:
                    b = BooleanGlyph()
                    pen = b.getPen()
                    c.draw(pen)
                    booleanGlyphs.append(b)

            finalBooleanGlyph = reduce(lambda g1, g2: g1 | g2, booleanGlyphs)
            finalBooleanGlyph.drawPoints(pointPen)

        except:
            toRFGlyph.drawPoints(pointPen)
    else:
        toRFGlyph.drawPoints(pointPen)

    return singleContourGlyph