def test_appending(self):
        frag_file = "tmp/b.svg"
        main_file = "tmp/a.svg"
        main = svg()
        frag = svg()
        exp = svg()
        sb = ShapeBuilder()

        main.addElement(sb.createRect(0, 0, "200px", "100px"))
        exp.addElement(sb.createRect(0, 0, "200px", "100px"))

        frag.addElement(text("Hello World", x=210, y=110))
        exp.addElement(text("Hello World", x=210, y=110))
        main.save(main_file)
        frag.save(frag_file)
        append_svg_to_file(frag_file, main_file)

        svg_main = parse(main_file)
        gotS = str(svg_main.getXML())
        expS = str(exp.getXML())
        print "Got:", gotS
        print "Exp:", expS
        #self.assertEqual(exp.getXML(), svg_main.getXML(), "Appended files are equal" )
        if gotS != expS:
            print "Different\nGot:\n", gotS, "\nExp:\n", expS
 def test_appending(self):
     frag_file="tmp/b.svg"
     main_file="tmp/a.svg"
     main = svg()
     frag = svg()
     exp = svg()
     sb = ShapeBuilder()
     
     main.addElement(sb.createRect(0, 0, "200px", "100px"))
     exp.addElement(sb.createRect(0, 0, "200px", "100px"))
     
     frag.addElement(text("Hello World", x = 210, y = 110))
     exp.addElement(text("Hello World", x = 210, y = 110))
     main.save(main_file)
     frag.save(frag_file)
     append_svg_to_file(frag_file,main_file)
     
     svg_main = parse(main_file)
     gotS =str(svg_main.getXML())
     expS = str(exp.getXML())
     print"Got:",gotS
     print"Exp:",expS
     #self.assertEqual(exp.getXML(), svg_main.getXML(), "Appended files are equal" )
     if gotS != expS :
         print "Different\nGot:\n",gotS,"\nExp:\n",expS
Beispiel #3
0
    def render_frame(self, svg, x, y):
        shape_builder = ShapeBuilder()
        frame = shape_builder.createRect(x, y, self.content_width, self.content_height, strokewidth=self.conf.group.thickness)
        svg.addElement(frame)

        #header_box = shape_builder.createRect(x, y, self.header_width, self.header_height, fill='black', strokewidth=self.conf.group.thickness)
        header_box = shape_builder.createRect(x, y, self.header_text.getWidth(), self.header_text.getHeight(), fill='black', strokewidth=self.conf.group.thickness)
        svg.addElement(header_box)

        self.header_text.renderHeader(svg, x + self.header_padding, y + self.header_padding)
Beispiel #4
0
    def render_content(self, svg, x, y):
        shape_builder = ShapeBuilder()
        frame = shape_builder.createRect(x, y, self.content_width, self.content_height, self.content_height / 2 - 1, self.content_height / 2 - 1, strokewidth=self.conf.terminal.thickness)
        svg.addElement(frame)

        x += max(1, (self.content_width - self.text.width - 2 * self.padding) / 2)
        self.text.render(svg, x + self.padding, y + self.padding)
Beispiel #5
0
def createblock(number):
    colors = {}
    colors[None] = ('#eee4da', '#776e65')
    colors[2] = ('#eee4da', '#776e65')
    colors[4] = ('#ede0c8', '#776e65')
    colors[8] = ('#f2b179', '#f9f6f2')
    colors[16] = ('#f59563', '#f9f6f2')
    colors[32] = ('#f67c5f', '#f9f6f2')
    colors[64] = ('#f65e3b', '#f9f6f2')
    colors[128] = ('#edcf72', '#f9f6f2')
    colors[256] = ('#edcc61', '#f9f6f2')
    colors[512] = ('#eee4da', '#776e65')
    colors[1024] = ('#edc53f', '#f9f6f2')
    colors[2048] = ('#edc22e', '#f9f6f2')

    canvas = Svg(0, 0, 100, 100)
    sb = ShapeBuilder()
    canvas.addElement(sb.createRect(5, 5, 90, 90, fill=colors[number][0]))

    t = Text(number, 50, 60)
    t.set_style(
        "font-family:FreeSans;font-weight:bold;font-size:36px;text-anchor:middle"
    )
    t.set_fill(colors[number][1])
    canvas.addElement(t)
    return canvas.getXML()
Beispiel #6
0
def testIterationsWithAttributesChange():
    s=Svg()
    
    sb =ShapeBuilder()
    coords=[(1,1),(200,200)]
    for (x,y) in coords:
        rectangle = sb.createRect(0,0,100,200,fill='000')
        rectangle.set_x(x)
        rectangle.set_y(y)
        s.addElement(rectangle)

    s.save('./testoutput/iterationsWithAttributesChange.svg')
Beispiel #7
0
def testIterationsWithAttributesChange():
    s = Svg()

    sb = ShapeBuilder()
    coords = [(1, 1), (200, 200)]
    for (x, y) in coords:
        rectangle = sb.createRect(0, 0, 100, 200, fill='000')
        rectangle.set_x(x)
        rectangle.set_y(y)
        s.addElement(rectangle)

    s.save('./testoutput/iterationsWithAttributesChange.svg')
Beispiel #8
0
    def render_content(self, svg, x, y):
        shape_builder = ShapeBuilder()
        frame = shape_builder.createRect(x, y, self.content_width, self.content_height, self.content_height / 2 - 1, self.content_height / 2 - 1, fill='black', strokewidth=self.conf.invterminal.thickness)
        svg.addElement(frame)

        first = True
        for child in self.children:
            if first:
                first = False
            else:
                l = shape_builder.createLine(x, y + 3, x, y + self.content_height - 3, stroke = 'white', strokewidth=self.conf.connection.thickness)
                svg.addElement(l)

            child.render(svg, x + self.padding, y + self.padding)
            x += child.width + 2 * self.padding
Beispiel #9
0
def testIterationsWithUse():
    s=Svg()
    d = Defs()
    sb =ShapeBuilder()
    rectangle = sb.createRect(0,0,100,200,fill='000')
    rectangle.set_id('baseRect')
    d.addElement(rectangle)
    s.addElement(d)
    coords=[(1,1),(200,200)]
    for (x,y) in coords:
        r=Use()
        r.set_x(x)
        r.set_y(y)
        r.set_xlink_href('#baseRect')
        s.addElement(r)

    s.save('./testoutput/iterationsWithUse.svg')
Beispiel #10
0
def testIterationsWithUse():
    s = svg()
    d = defs()
    sb = ShapeBuilder()
    rectangle = sb.createRect(0, 0, 100, 200, fill="000")
    rectangle.set_id("baseRect")
    d.addElement(rectangle)
    s.addElement(d)
    coords = [(1, 1), (200, 200)]
    for (x, y) in coords:
        r = use()
        r.set_x(x)
        r.set_y(y)
        r.set_xlink_href("#baseRect")
        s.addElement(r)

    s.save("./testoutput/iterationsWithUse.svg")
Beispiel #11
0
def testIterationsWithUse():
    s = Svg()
    d = Defs()
    sb = ShapeBuilder()
    rectangle = sb.createRect(0, 0, 100, 200, fill='000')
    rectangle.set_id('baseRect')
    d.addElement(rectangle)
    s.addElement(d)
    coords = [(1, 1), (200, 200)]
    for (x, y) in coords:
        r = Use()
        r.set_x(x)
        r.set_y(y)
        r.set_xlink_href('#baseRect')
        s.addElement(r)

    s.save('./testoutput/iterationsWithUse.svg')
Beispiel #12
0
def createblock(number):
    colors = {}
    colors[2]=('#eee4da','#776e65')
    colors[4]=('#ede0c8','#776e65')
    colors[8]=('#f2b179','#f9f6f2')
    colors[16]=('#f59563','#f9f6f2')
    colors[32]=('#f67c5f','#f9f6f2')
    colors[64]=('#f65e3b','#f9f6f2')
    colors[128]=('#edcf72','#f9f6f2')
    colors[256]=('#edcc61','#f9f6f2')
    colors[512]=('#eee4da','#776e65')
    colors[1024]=('#edc53f','#f9f6f2')
    colors[2048]=('#edc22e','#f9f6f2')
    
    canvas = Svg(0,0,100,100)
    sb = ShapeBuilder()
    canvas.addElement( sb.createRect(5,5,90,90,fill=colors[number][0]) )
    
    t = Text(number,50,60)
    t.set_style("font-family:FreeSans;font-weight:bold;font-size:36px;text-anchor:middle")
    t.set_fill(colors[number][1])
    canvas.addElement(t)
    canvas.save('/tmp/try7.svg')
Beispiel #13
0
from pysvg.builders import Svg, ShapeBuilder, StyleBuilder
from pysvg.text import *

canvas = Svg(0, 0, 100, 100)

sb = ShapeBuilder()
canvas.addElement(sb.createRect(5, 5, 90, 90, fill="#00FF00"))

t = Text('Hello!', 50, 50)
t.set_style(
    "font-family:FreeSans;font-weight:bold;font-size:24px;text-anchor:middle")
t.set_fill("#FF0000")
canvas.addElement(t)

canvas.save('/tmp/try7.svg')
Beispiel #14
0
from pysvg.builders import Svg, ShapeBuilder, StyleBuilder
from pysvg.text import *

canvas = Svg(0,0,100,100)

sb = ShapeBuilder()
canvas.addElement( sb.createRect(5,5,90,90,fill="#00FF00") )

t = Text('Hello!',50,50)
t.set_style("font-family:FreeSans;font-weight:bold;font-size:24px;text-anchor:middle")
t.set_fill("#FF0000")
canvas.addElement(t)
 

canvas.save('/tmp/try7.svg')

Beispiel #15
0
class NodeRenderer(object):
    def __init__(self, conf):

        self.__shapeBuilder = ShapeBuilder()

        self.__fontSize = conf['frame']['font']['size'];
        self.__fontFamily = conf['frame']['font']['name'];
        self.__alignment = conf['frame']['font']['align'];

        self.__frameThickness = conf['frame']['thickness'];
        self.__frameWidth = conf['frame']['width'];
        self.__framePadding = conf['frame']['padding'];

        self.__separatorWidth = conf['frame']['separator']['width'];

        self.__textStyle = StyleBuilder()
        self.__textStyle.setFontFamily(self.__fontFamily)
        self.__textStyle.setFontSize(self.__fontSize.__str__() + 'px')

        self.__LINE_SEPARATOR = 5;
        
        self.__resolver = BBCodeResolver();

    def __createLines(self, values):
        result = [];

        for value in values:
            if isinstance(value, basestring):
                lines = self.__resolver.resolveString(value);
                
                if isinstance(lines, list):
                    for line in lines:
                        result.append(line);
            elif isinstance(value, int):
                result.append(value);
            else:
                assert 1 == 2

        return result;

    def __determineLineHeight(self, isSeparator):
        if isSeparator:
            return self.__separatorWidth + self.__LINE_SEPARATOR;
        else:
            return self.__fontSize + self.__LINE_SEPARATOR;

    def __determineContainterHeight(self, lines):
        #TODO wrapping!

        height = 0;

        for line in lines:
            if isinstance(line, int):
                height = height + self.__determineLineHeight(True);
            else:
                height = height + self.__determineLineHeight(False);

        return height + 2 * self.__framePadding;

    def __prepareNodeContainer(self, startX, startY, width, height, isReference):
        nodeGroup = g()
        nodeGroup.set_style(self.__textStyle.getStyle())

        if isReference:
            color = 'gray';
        else:
            color = 'white';

        rect = self.__shapeBuilder.createRect(startX, startY, width, height, strokewidth = self.__frameThickness, stroke='black', fill=color)
        nodeGroup.addElement(rect)

        return nodeGroup;

    def render(self, node, startX, startY, isReference = False):
        if node['type'] != 'node':
            raise Exception("Wrong input object. Expected type: 'node'");

        lines = self.__createLines(node['value']);

        height = self.__determineContainterHeight(lines);

        nodeContainer = self.__prepareNodeContainer(startX, startY, self.__frameWidth, height, isReference)

        y = startY + self.__framePadding;

        for line in lines:
            if isinstance(line, int): # if int, then render horizontal line
                lineHeight = self.__determineLineHeight(True);
                x = startX;

                separatorObj = self.__shapeBuilder.createLine(x, y, x + self.__frameWidth, y, strokewidth = self.__separatorWidth)
                nodeContainer.addElement(separatorObj)

            elif isinstance(line, list): #list, because line is list of bbcoded spans
                lineHeight = self.__determineLineHeight(False);
                x = startX + self.__framePadding;

                txtObj = text(None, x, y + self.__fontSize);

                for txt in line:
                    span = tspan();
                    span.appendTextContent(txt.getText());
                    span.setAttribute("style", txt.getStyle())
                    txtObj.addElement(span)

                nodeContainer.addElement(txtObj)
            else:
                raise Exception("unsupported value type")

            y = y + lineHeight;

        return nodeContainer;

    #pseudo static method
    def getNodeHeight(self, node):
        lines = self.__createLines(node['value']);
        return self.__determineContainterHeight(lines);