예제 #1
0
    def renderToFile(self, content, imagePath):
        """
        content - текст, описывающий диаграмму
        imagePath - полный путь до создаваемого файла
        """
        from blockdiag.parser import parse_string
        from blockdiag.drawer import DiagramDraw
        from blockdiag.builder import ScreenNodeBuilder
        from blockdiag.utils.fontmap import FontMap

        font = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            u"fonts",
                            self._fontDefault)

        fontmap = FontMap()
        fontmap.set_default_font(font)

        text = u"blockdiag {{ {content} }}".format(content=content)

        tree = parse_string(text)
        diagram = ScreenNodeBuilder.build(tree)

        draw = DiagramDraw("png", diagram, imagePath,
                           fontmap=fontmap, antialias=True)
        draw.draw()
        draw.save()
예제 #2
0
    def renderToFile(self, content, imagePath):
        """
        content - текст, описывающий диаграмму
        imagePath - полный путь до создаваемого файла
        """
        from blockdiag.parser import parse_string
        from blockdiag.drawer import DiagramDraw
        from blockdiag.builder import ScreenNodeBuilder
        from blockdiag.utils.fontmap import FontMap

        font = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            u"fonts", self._fontDefault)

        fontmap = FontMap()
        fontmap.set_default_font(font)

        text = u"blockdiag {{ {content} }}".format(content=content)

        tree = parse_string(text)
        diagram = ScreenNodeBuilder.build(tree)

        draw = DiagramDraw("png",
                           diagram,
                           imagePath,
                           fontmap=fontmap,
                           antialias=True)
        draw.draw()
        draw.save()
예제 #3
0
    def test_unknown_image_driver(self):
        from blockdiag.drawer import DiagramDraw
        from blockdiag.elements import Diagram

        with self.assertRaises(RuntimeError):
            DiagramDraw('unknown', Diagram())
예제 #4
0
    def node2image(self, node, diagram):
        options = node['options']
        filename = self.image_filename(node)
        fontmap = self.create_fontmap()
        _format = self.global_options['format'].lower()

        if _format == 'svg' and self.global_options['inline_svg'] is True:
            filename = None

        kwargs = dict(self.global_options)
        del kwargs['format']
        drawer = DiagramDraw(_format, diagram, filename,
                             fontmap=fontmap, **kwargs)

        if filename is None or not os.path.isfile(filename):
            drawer.draw()
            content = drawer.save()

            if _format == 'svg' and self.global_options['inline_svg'] is True:
                size = drawer.pagesize()
                if 'maxwidth' in options and options['maxwidth'] < size[0]:
                    ratio = float(options['maxwidth']) / size[0]
                    new_size = (options['maxwidth'], int(size[1] * ratio))
                    content = drawer.save(new_size)

                return nodes.raw('', content, format='html')

        size = drawer.pagesize()
        if 'maxwidth' in options and options['maxwidth'] < size[0]:
            ratio = float(options['maxwidth']) / size[0]
            thumb_size = (options['maxwidth'], int(size[1] * ratio))

            thumb_filename = self.image_filename(node, prefix='_thumb')
            if not os.path.isfile(thumb_filename):
                drawer.filename = thumb_filename
                drawer.draw()
                drawer.save(thumb_size)

            image = nodes.image(uri=thumb_filename, target=filename)
        else:
            image = nodes.image(uri=filename)

        if node['alt']:
            image['alt'] = node['alt']

        return image
예제 #5
0
def _draw_lines(line, radius, expected_calls, **kwargs):
    drawer = MockDrawer()
    DiagramDraw.line(drawer, line, radius, **kwargs)
    assert drawer.calls == expected_calls, \
        "expected:%r\nactual:%r" % (expected_calls, drawer.calls)