Exemple #1
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
Exemple #2
0
    def test_subdividePathWithPaths(self):
        divided, intersections = TFSTesselation().subdividePathWithPaths([openPathWithPoints(TFSPoint(0, 2),
                                                                                             TFSPoint(4, 2)),
                                                                          openPathWithPoints(TFSPoint(6, 0),
                                                                                             TFSPoint(6, 4)),
                                                                          ])
        self.assertEqual(len(divided), 2)
        self.assertEqual(len(intersections), 0)

        divided, intersections = TFSTesselation().subdividePathWithPaths([openPathWithPoints(TFSPoint(0, 2),
                                                                                             TFSPoint(4, 2)),
                                                                          openPathWithPoints(TFSPoint(2, 0),
                                                                                             TFSPoint(2, 4)),
                                                                          ])
#        debugPaths('divided', divided)
        self.assertEqual(len(divided), 4)
        self.assertEqual(len(intersections), 1)

        divided, intersections = TFSTesselation().subdividePathWithPaths([openPathWithPoints(TFSPoint(0, 2),
                                                                                             TFSPoint(4, 2)),
                                                                          openPathWithPoints(TFSPoint(2, 0),
                                                                                             TFSPoint(2, 4)),
                                                                          openPathWithPoints(TFSPoint(3, 0),
                                                                                             TFSPoint(3, 4)),
                                                                          ])
#        debugPaths('divided', divided)
        self.assertEqual(len(divided), 7)
        self.assertEqual(len(intersections), 2)

        divided, intersections = TFSTesselation().subdividePathWithPaths([openPathWithPoints(TFSPoint(0, 2),
                                                                                             TFSPoint(4, 2)),
                                                                          openPathWithPoints(TFSPoint(0, 1),
                                                                                             TFSPoint(4, 1)),
                                                                          openPathWithPoints(TFSPoint(2, 0),
                                                                                             TFSPoint(2, 4)),
                                                                          openPathWithPoints(TFSPoint(3, 0),
                                                                                             TFSPoint(3, 4)),
                                                                          ])
#        debugPaths('divided', divided)
        self.assertEqual(len(divided), 12)
        self.assertEqual(len(intersections), 4)

        '''
        Endpoint intersection
        '''
        divided, intersections = TFSTesselation().subdividePathWithPaths([openPathWithPoints(TFSPoint(0, 2),
                                                                                             TFSPoint(4, 2)),
                                                                          openPathWithPoints(TFSPoint(4, 2),
                                                                                             TFSPoint(4, 4)),
                                                                          ])
        self.assertEqual(len(divided), 2)
        self.assertEqual(len(intersections), 0)