コード例 #1
0
ファイル: glyphUtils.py プロジェクト: roboDocs/PenBallWizard
def reverseContours(glyph):
    glyphCopy = RGlyph()
    glyphCopy.width = glyph.width
    pointPen = glyphCopy.getPointPen()
    reversePen = ReverseContourPointPen(pointPen)
    glyph.drawPoints(reversePen)
    return glyphCopy
コード例 #2
0
ファイル: fontUtils.py プロジェクト: roboDocs/MutatorScale
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
ファイル: spikePen.py プロジェクト: robotools/fontPens
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
ファイル: spikePen.py プロジェクト: robotools/fontPens
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
コード例 #7
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
コード例 #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
ファイル: scaler.py プロジェクト: roboDocs/MutatorScale
 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
ファイル: glyphUtils.py プロジェクト: roboDocs/PenBallWizard
def removeOverlap(glyph):
    glyphCopy = RGlyph()
    glyphCopy.width = glyph.width
    pointPen = glyphCopy.getPointPen()
    glyph.drawPoints(pointPen)
    glyphCopy.removeOverlap()
    return glyphCopy
コード例 #12
0
ファイル: glyphUtils.py プロジェクト: roboDocs/PenBallWizard
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
ファイル: fontUtils.py プロジェクト: roboDocs/MutatorScale
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