Exemplo n.º 1
0
    def _generateFont(self,
                      name,
                      fontfile,
                      width,
                      height=0,
                      rangemin=32,
                      rangemax=127):
        try:
            font = FontFreetype(fontfile, width, height)
        except:
            print("Failed to load " + fontfile + "!")
            sys.exit(1)

        chars = ""
        for i in range(rangemin, rangemax):
            chars += chr(i)

        (bodys, masks,
         composites) = zip(*self._generateFontImages(font, chars))

        if self._drawTest:
            cells = bodys
            width = cells[0].width()
            height = cells[0].height()
            testImg = QImage(len(cells) * width, height, QImage.Format_ARGB32)
            testImg.fill(Qt.black)
            testPainter = QPainter(testImg)
            penx = 0
            for cell in cells:
                testPainter.drawImage(penx, 0, cell)
                penx += cell.width()
            testPainter.end()
            testImg.save(self._outputpath + "/test_" + name + ".png")

        bodysData = ""
        masksData = ""
        for ch, body, mask in zip(chars, bodys, masks):
            comment = ord(ch)
            if (comment <= 126) and (comment >= 32): comment = str(ch)
            comment += ' character'
            bodysData += BitmapGenerator.imageToCArray(body, comment)
            masksData += BitmapGenerator.imageToCArray(mask, comment)

        fontc = fontcTemplate.substitute(bodysData=bodysData,
                                         masksData=masksData,
                                         fontName=name,
                                         lineSpace=1,
                                         width=bodys[0].width(),
                                         height=bodys[0].height(),
                                         rangeMin=rangemin,
                                         rangeMax=rangemax)

        f = open(self._outputpath + '/font' + name + '.c', 'w')
        print(fontc, file=f)
        f.close()
Exemplo n.º 2
0
    def _generateFont(self, name, fontfile, width, height = 0, rangemin = 32, rangemax = 127):
        try:
            font = FontFreetype(fontfile, width, height)
        except:
            print("Failed to load " + fontfile + "!")
            sys.exit(1)

        chars = ""
        for i in range(rangemin, rangemax):
            chars += chr(i)

        (bodys, masks, composites) = zip(*self._generateFontImages(font, chars))

        if self._drawTest:
            cells = bodys
            width = cells[0].width()
            height = cells[0].height()
            testImg = QImage(len(cells) * width, height, QImage.Format_ARGB32)
            testImg.fill(Qt.black)
            testPainter = QPainter(testImg)
            penx = 0
            for cell in cells:
                testPainter.drawImage(penx, 0, cell)
                penx += cell.width()
            testPainter.end()
            testImg.save(self._outputpath + "/test_" + name + ".png")


        bodysData = ""
        masksData = ""
        for ch, body, mask in zip(chars, bodys, masks):
            comment = ord(ch)
            if (comment <= 126) and (comment >= 32): comment = str(ch)
            comment += ' character'
            bodysData += BitmapGenerator.imageToCArray(body, comment)
            masksData += BitmapGenerator.imageToCArray(mask, comment)

        fontc = fontcTemplate.substitute(
            bodysData = bodysData,
            masksData = masksData,
            fontName = name,
            lineSpace = 1,
            width = bodys[0].width(),
            height = bodys[0].height(),
            rangeMin = rangemin,
            rangeMax = rangemax)

        f = open(self._outputpath  + '/font' + name + '.c', 'w')
        print(fontc, file=f)
        f.close()
Exemplo n.º 3
0
    def _generateFontImages(self, font, chars):
        bodyImages = font.renderChars(chars)

        images = []
        for bodyImage in bodyImages:
            maskImage = BitmapGenerator.imageOutline(bodyImage)
            #maskImage.setColor(1, 0xff000000)

            compositeImage = QImage(maskImage.width(), maskImage.height(), QImage.Format_ARGB32)
            compositeImage.fill(Qt.yellow)
            compositePainter = QPainter(compositeImage)
            compositePainter.drawImage(0, 0, maskImage)
            compositePainter.drawImage(1, 1, bodyImage)
            compositePainter.end()

            images.append((bodyImage, maskImage, compositeImage))

        return images
Exemplo n.º 4
0
    def _generateFontImages(self, font, chars):
        bodyImages = font.renderChars(chars)

        images = []
        for bodyImage in bodyImages:
            maskImage = BitmapGenerator.imageOutline(bodyImage)
            #maskImage.setColor(1, 0xff000000)

            compositeImage = QImage(maskImage.width(), maskImage.height(),
                                    QImage.Format_ARGB32)
            compositeImage.fill(Qt.yellow)
            compositePainter = QPainter(compositeImage)
            compositePainter.drawImage(0, 0, maskImage)
            compositePainter.drawImage(1, 1, bodyImage)
            compositePainter.end()

            images.append((bodyImage, maskImage, compositeImage))

        return images