Exemplo n.º 1
0
    def getTableSvg(self, glyphs, maxValue):
        glyphs.sort(lambda glyph0, glyph1:cmp(glyph0.codePoint, glyph1.codePoint))
        glyphs = glyphs[:1000]

        from tfs.common.TFSSvg import TFSSvg, TFSSvgPath, blendArgbColors

        CANVAS_BACKGROUND_COLOR = 0xffffffff
        CANVAS_BORDER_COLOR = 0x07fbfbfbf
        fiSvg = TFSSvg().withBackground(CANVAS_BACKGROUND_COLOR).withBorder(CANVAS_BORDER_COLOR)

        glyphCount = len(glyphs)
        margin = 10
        hSpacing = vSpacing = 10
        cellWidth = cellHeight = 10
        glyphsPerRow = 13
        width = 2 * margin + (glyphsPerRow * cellWidth) + ((glyphsPerRow - 1) * hSpacing)
        rowCount = int(math.ceil(glyphCount / glyphsPerRow))
        height = 2 * margin + (rowCount * cellHeight) + ((rowCount - 1) * vSpacing)

        for index, glyph in enumerate(glyphs):
            x = index % glyphsPerRow
            y = int(math.floor(index / glyphsPerRow))
            corner = TFSPoint(margin + x * (cellWidth + hSpacing),
                              margin + y * (cellHeight + vSpacing))
            path = polygonWithPoints(corner,
                                     corner.right(cellWidth),
                                     corner.right(cellWidth).up(cellHeight),
                                     corner.up(cellHeight))
            path = path.applyScaleXY(1.0, -1.0)
            minGlyphColor = 0xffafafff
            maxGlyphColor = 0xff0f0f5f
            phase = glyph.count / float(maxValue)
            glyphColor = blendArgbColors(minGlyphColor, maxGlyphColor, phase)
            fiSvg.addItem(TFSSvgPath(path).addFill(glyphColor))

        return fiSvg.renderRaw(None, width, height)
Exemplo n.º 2
0
    def renderSvgScene(self,
                       filenamePrefix,
                       pathTuples,
                       hGuidelines=None):
        from tfs.common.TFSSvg import TFSSvg, TFSSvgPath

        filename = '%s.svg' % ( filenamePrefix, )
        dstFile = os.path.abspath(os.path.join(self.svg_folder, filename))

        CANVAS_BACKGROUND_COLOR = 0xffffffff
        CANVAS_BORDER_COLOR = 0x07fbfbfbf
        fiSvg = TFSSvg().withBackground(CANVAS_BACKGROUND_COLOR).withBorder(CANVAS_BORDER_COLOR)

    #    if pathTuples:
        for color, contours in pathTuples:
            self.subrenderGlyphContours(fiSvg, contours, color)

        if hGuidelines:
            for hGuideline in hGuidelines:
                p0 = TFSPoint(hGuideline, self.fifont.info.descender)
                p1 = TFSPoint(hGuideline, self.fifont.info.ascender)
                GUIDELINE_COLOR = 0x7fdfdfdf
                fiSvg.addItem(TFSSvgPath(openPathWithPoints(p0, p1)).addStroke(GUIDELINE_COLOR, 1))

        vGuidelines = ( 0,
                        self.fifont.info.ascender,
                        self.fifont.info.descender,
                        )
        if vGuidelines:
            minmax = None
            for color, contours in pathTuples:
                minmax = minmaxMerge(minmax, minmaxPaths(contours))

            for vGuideline in vGuidelines:
                p0 = TFSPoint(0, vGuideline)
                p1 = TFSPoint(minmax.maxX, vGuideline)
                GUIDELINE_COLOR = 0x7fdfdfdf
                fiSvg.addItem(TFSSvgPath(openPathWithPoints(p0, p1)).addStroke(GUIDELINE_COLOR, 1))

        SVG_HEIGHT = 400
        SVG_MAX_WIDTH = 800
        fiSvg.renderToFile(dstFile, margin=10, height=SVG_HEIGHT, maxWidth=SVG_MAX_WIDTH)
        return filename