Esempio n. 1
0
def makeGlyph(glyphList, font, message, mark, saveBackup):
    # Initialize the progress bar
    tickCount = len(glyphList)
    bar = ProgressBar(message, tickCount)
    tick = 0

    for item in glyphList:
        glyphName, advanceWidth, components = item

        # If the font has the glyph, lots of checking is required to see if changes have been made
        if font.has_key(glyphName):
            glyph = font[glyphName]

            #Build new glyph for comparisons
            newGlyph = RGlyph()
            count = 0
            while count < len(components):
                component, x, y = components[count]
                newGlyph.appendComponent(component, offset=(x, y))
                count = count + 1
            newGlyph.width = advanceWidth

            # Make digest of the new glyph
            pointPen = DigestPointPen()
            newGlyph.drawPoints(pointPen)
            newDigest = pointPen.getDigest()

            # Make digest of the old glyph
            pointPen = DigestPointPen()
            glyph.drawPoints(pointPen)
            oldDigest = pointPen.getDigest()

            # Check the advance width
            if glyph.width != advanceWidth:
                glyph.width = advanceWidth
                if mark == 1:
                    glyph.mark = 200

            # If the digests don't match, rebuild components
            if oldDigest is not newDigest:
                if saveBackup == 1:
                    backupName = glyph.name + '.bkup'
                    font.insertGlyph(glyph, name=backupName)
                glyph.clearComponents()
                count = 0
                while count < len(components):
                    component, x, y = components[count]
                    glyph.appendComponent(component, offset=(x, y))
                    count = count + 1
                if mark == 1:
                    glyph.mark = 200

            # Clean up things
            glyph.update()
            bar.tick(tick)
            tick = tick + 1

        # If the glyph is not in the font, build a new glyph
        else:
            font.newGlyph(glyphName, clear=True)
            glyph = font[glyphName]
            glyph.width = advanceWidth
            count = 0
            while count < len(components):
                component, x, y = components[count]
                glyph.appendComponent(component, offset=(x, y))
                count = count + 1
            if mark == 1:
                glyph.mark = 300
            glyph.update()
            bar.tick(tick)
            tick = tick + 1
    bar.close()