branchcount.py

download
class essai:

    def expandBitmaps(self):

        """
        convert the minimum bitmap from BDF file to the one that will
        be output in NGF file
        """

        def bitmapAppendColumn(bitmap, xMin, xMax):
            """add a full column of white pixels to the bitmap"""
            for dummy in range(xMin, xMax):
                for y in range(self.fontSize):
                    bitmap[y] += "0"
            return

        def bitmapBefore():
            """empty columns before bitmap"""
            xCur = 0
            xMax = caract.bbox[2]
            if xMax < 0:
                xMax = 0 # le caractere repart sur la gauche!
            bitmapAppendColumn(bitmap, xCur, xMax)
            return

        def bitmapAbove():
            """partial empty columns above the real bitmap"""
            yCur = 0
            yMax = self.ascent - caract.bbox[1] - caract.bbox[3]
            for dummy in range(caract.bbox[0]):
                for y in range(yCur, yMax):
                    bitmap[y] += "0"
            return

        def bitmapReal():
            """copy of the real bitmap in the center of the destination one"""
            yCur = self.ascent - caract.bbox[1] - caract.bbox[3]
            yMax  = yCur + caract.bbox[1]
            for y in range(yCur, yMax):
                bitmap[y] += caract.bitmap[y-yCur]
            return

        def bitmapBelow():
            """partial empty columns below the real bitmap"""
            yCur = self.ascent - caract.bbox[3]
            yMax = self.fontSize
            for dummy in range(caract.bbox[0]):
                for y in range(yCur, yMax):
                    bitmap[y] += "0"
            return

        def bitmapAfter():
            """empty columns after the real part of the bitmap"""
            xCur = len(bitmap[0])
            xMax = caract.dwidth[0]
            if caract.bbox[2] < 0 and (caract.bbox[0] < caract.dwidth[0]):
                xMax -= caract.bbox[2]
            if USE_MORE_ADVANCE == 1:
                if caract.bbox[2] > 0:
                    xMax -= caract.bbox[2]
            bitmapAppendColumn(bitmap, xCur, xMax)
            return

        def bitmapSpace():
            """make specific bitmap for space character"""
            if self.chinois:
                return
            """specific design for white space character"""
            for y in range(self.fontSize):
                # Hack total ????
                if self.fontSize < 10:
                    bitmap[y] = "0" * self.fontSize
                else:
                    bitmap[y] = "0" * self.spacewidth
            return

        for caract in self.allChars:
            bitmap = []
            #print "char: ", caract.encoding
            for dummy in range(self.fontSize):
                bitmap.append("")

            if USE_MORE_ADVANCE == 0:
                bitmapBefore()
            bitmapAbove()
            bitmapReal()
            bitmapBelow()
            if USE_MORE_WIDTH == 0:
                bitmapAfter()

            if dbgLvl == DBG_NGF_ALL and caract.bbox[0] > caract.dwidth[0]:
                print "char %s, bbox: %d > width %d (adv %d)" % (caract.name,
                        caract.bbox[0], caract.dwidth[0], caract.bbox[2])

            if dbgLvl & DBG_NGF_BMP:
                print "char %s:" % caract.name
                for y in range(self.fontSize):
                    print bitmap[y]

            if caract.encoding == 0x20:
                bitmapSpace()

            caract.bitmap = bitmap
        # end for

    # end def expandBitmaps