コード例 #1
0
def rev_path(x1, y1, x2, y2, txt=None):
    elements = []
    # x1, y1 = r1.get_cx(), r1.get_cy()
    # x2, y2 = r2.get_cx(), r2.get_cy(),
    l = line(x1, y1, x2, y2)
    elements.append(l)
    style = 'stroke-width:{0};stroke:{1}'.format(16, ALUM_6)
    l.set_style(style)
    if txt:
        x, y = middle(x1, y1, x2, y2)
        style2 = StyleBuilder()
        #style2.setFontFamily('envy code r')
        style2.setFontFamily('arial')
        style2.setFontWeight('bold')
        style2.setFilling(ALUM_1)
        # shift text left and up by a bit
        # whole alphabet in this font is 167 px width
        per_char = 167. / 26
        t = text(txt, -len(txt) / 2 * per_char, 4)
        t.set_style(style2.getStyle())

        #import pdb; pdb.set_trace()
        group = rotate([t], slope_angle(x1, y1, x2, y2))
        group = translate([group], x, y)
        elements.append(group)

    return elements
コード例 #2
0
ファイル: svg.py プロジェクト: ncqgm/gnumed
 def _get_font_style(self, size, anchor, dash_array):
     style = StyleBuilder()
     style.setStrokeDashArray(dash_array)
     style.setFontFamily(fontfamily="Verdana")
     style.setFontSize("%dpx" % size)
     style.setTextAnchor(anchor)
     return style
コード例 #3
0
def rev_path(x1,y1, x2,y2, txt=None):
    elements = []
    # x1, y1 = r1.get_cx(), r1.get_cy()
    # x2, y2 = r2.get_cx(), r2.get_cy(),
    l = line(x1, y1,
             x2, y2)
    elements.append(l)
    style = 'stroke-width:{0};stroke:{1}'.format(16, ALUM_6)
    l.set_style(style)
    if txt:
        x, y = middle(x1, y1, x2, y2)
        style2 = StyleBuilder()
        #style2.setFontFamily('envy code r')
        style2.setFontFamily('arial')
        style2.setFontWeight('bold')
        style2.setFilling(ALUM_1)
        # shift text left and up by a bit
        # whole alphabet in this font is 167 px width
        per_char = 167./26
        t = text(txt, -len(txt)/2*per_char, 4)
        t.set_style(style2.getStyle())

        #import pdb; pdb.set_trace()
        group = rotate([t], slope_angle(x1, y1, x2, y2))
        group = translate([group], x, y)
        elements.append(group)


    return elements
コード例 #4
0
 def _get_font_style(self, size, anchor, dash_array):
     style = StyleBuilder()
     style.setStrokeDashArray(dash_array)
     style.setFontFamily(fontfamily="Verdana")
     style.setFontSize("%dpx" % size)
     style.setTextAnchor(anchor)
     return style
コード例 #5
0
def words(txt, family='arial', weight='bold', color=ALUM_1):
    style2 = StyleBuilder()
    #style2.setFontFamily('envy code r')
    style2.setFontFamily('arial')
    style2.setFontWeight('bold')
    style2.setFilling(ALUM_1)
    t = text(txt, 0, 0)
    t.set_style(style2.getStyle())
    return t
コード例 #6
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def words(txt, family='arial', weight='bold', color=ALUM_1):
    style2 = StyleBuilder()
    #style2.setFontFamily('envy code r')
    style2.setFontFamily('arial')
    style2.setFontWeight('bold')
    style2.setFilling(ALUM_1)
    t = text(txt, 0, 0)
    t.set_style(style2.getStyle())
    return t
コード例 #7
0
def draw_tree(width, height):
    global nameStyle

    nameStyle = StyleBuilder()
    nameStyle.setFontFamily(fontfamily=dc.nameFont)
    nameStyle.setFontSize("%spt" % dc.nameFontSize)
    nameStyle.setTextAnchor("left")
    nameStyle = nameStyle.getStyle()

    svg = Svg(width=width, height=height)

    # draw nodes

    for depth in depthToNames:
        for name in depthToNames[depth]:
            node = nameToNode[name]
            draw_node(svg, node, name)

    # draw branches

    for depth in depthToNames:
        for name in depthToNames[depth]:
            node = nameToNode[name]
            isLeaf = (node.children == [])
            if (isLeaf): continue

            numChildren = len(node.children)
            for (i, child) in enumerate(node.children):
                rootFrac = 0.4 + (0.2 * i) / (numChildren - 1)
                sinkFrac = 0.5

                if (orientation == "T2B"):
                    (rootX, rootY) = (node.x + rootFrac * dc.nodeWdt,
                                      node.y + dc.nodeHgt)
                    (sinkX, sinkY) = (child.x + sinkFrac * dc.nodeWdt, child.y)
                    draw_vert_branch(svg, "%s_branch_%d" % (name, i), rootX,
                                     rootY, sinkX, sinkY)
                else:  # if (orientation == "L2R"):
                    (rootX, rootY) = (node.x + dc.nodeWdt,
                                      node.y + rootFrac * dc.nodeHgt)
                    (sinkX, sinkY) = (child.x, child.y + sinkFrac * dc.nodeHgt)
                    draw_horz_branch(svg, "%s_branch_%d" % (name, i), rootX,
                                     rootY, sinkX, sinkY)

    return svg
コード例 #8
0
def command(num_txt, cmd, explanation, color):
    x = 0
    y = 0
    elems = [scale(num(num_txt, color), 2)]
    cmd_txt = text(cmd, x + 40, y + 12)
    s = StyleBuilder()
    s.setFontWeight('bold')
    s.setFontFamily('Bitstream Vera Sans Mono')
    cmd_txt.set_style(s.getStyle())
    elems.append(cmd_txt)

    exp_txt = text(explanation, x + 45, y + 27)
    s = StyleBuilder()
    #s.setFontWeight('bold')
    s.setFontFamily('Bitstream Vera Serif')
    s.setFontSize('10px')
    exp_txt.set_style(s.getStyle())
    elems.append(exp_txt)
    return elems
コード例 #9
0
def command(num_txt, cmd, explanation, color):
    x = 0
    y = 0
    elems = [scale(num(num_txt, color), 2)]
    cmd_txt = text(cmd, x+40, y+12)
    s = StyleBuilder()
    s.setFontWeight('bold')
    s.setFontFamily('Bitstream Vera Sans Mono')
    cmd_txt.set_style(s.getStyle())
    elems.append(cmd_txt)

    exp_txt = text(explanation, x+45, y+27)
    s = StyleBuilder()
    #s.setFontWeight('bold')
    s.setFontFamily('Bitstream Vera Serif')
    s.setFontSize('10px')
    exp_txt.set_style(s.getStyle())
    elems.append(exp_txt)
    return elems
コード例 #10
0
def num(txt, color):
    txt = str(txt)
    elems = []
    r = rect(0, 0, 16, 16)
    s = StyleBuilder()
    s.setFilling(color)
    r.set_style(s.getStyle())
    elems.append(r)
    if txt:
        style2 = StyleBuilder()
        #style2.setFontFamily('envy code r')
        style2.setFontFamily('arial')
        style2.setFontWeight('bold')
        style2.setFilling(ALUM_1)
        # shift text left and up by a bit
        if len(txt) == 1:
            x = 5
        elif len(txt) == 2:
            x = 1.5
        t = text(txt, x, 12.5)
        t.set_style(style2.getStyle())
        elems.append(t)
    return elems
コード例 #11
0
def num(txt, color):
    txt = str(txt)
    elems = []
    r = rect(0, 0, 16, 16)
    s = StyleBuilder()
    s.setFilling(color)
    r.set_style(s.getStyle())
    elems.append(r)
    if txt:
        style2 = StyleBuilder()
        #style2.setFontFamily('envy code r')
        style2.setFontFamily('arial')
        style2.setFontWeight('bold')
        style2.setFilling(ALUM_1)
        # shift text left and up by a bit
        if len(txt) == 1:
            x = 5
        elif len(txt) == 2:
            x = 1.5
        t = text(txt, x, 12.5)
        t.set_style(style2.getStyle())
        elems.append(t)
    return elems
コード例 #12
0
def draw_tree():
    if (dc.nameFontSize < 16):
        scale = dc.nameFontSize / 16.0
        nameCapsHgt = dc.nameCapsHgt * scale
        nameDescHgt = dc.nameDescHgt * scale
        nameFontLineHgt = dc.nameFontLineHgt * scale

    nameStyle = StyleBuilder()
    nameStyle.setFontFamily(fontfamily=dc.nameFont)
    nameStyle.setFontSize("%spt" % dc.nameFontSize)
    nameStyle.setTextAnchor("left")
    nameStyle = nameStyle.getStyle()

    svg = Svg()

    # draw nodes

    for depth in depthToNames:
        for name in depthToNames[depth]:
            node = nameToNode[name]
            isLeaf = (node.left == None)

            yLine = node.y + nameCapsHgt + 1

            ob = SvgRect(node.x,
                         node.y,
                         dc.nodeWidth,
                         dc.nodeHeight,
                         id="%s_box" % name)
            ob.set_stroke(dc.lineColor)
            ob.set_stroke_width(dc.lineThickness)
            if (isLeaf): ob.set_fill(dc.leafFillColor)
            else: ob.set_fill(dc.nodeFillColor)
            svg.addElement(ob)

            ob = SvgText("%s" % name, node.x + 1, yLine, id="%s_name" % node)
            ob.set_style(nameStyle)
            svg.addElement(ob)
            yLine += nameFontLineHgt

            if (hasattr(node, "bitsUnion")):
                ob = SvgText("U:" +
                             bits_to_string(node.numBits, node.bitsUnion),
                             node.x + 1,
                             yLine,
                             id="%s_Bunion" % node)
                ob.set_style(nameStyle)
                svg.addElement(ob)
            yLine += nameFontLineHgt

            if (hasattr(node, "bitsIntersection")):
                ob = SvgText(
                    "I:" + bits_to_string(node.numBits, node.bitsIntersection),
                    node.x + 1,
                    yLine,
                    id="%s_Bintersection" % node)
                ob.set_style(nameStyle)
                svg.addElement(ob)
            yLine += nameFontLineHgt

            if (hasattr(node, "bitsAll")):
                ob = SvgText("A:" + bits_to_string(node.numBits, node.bitsAll),
                             node.x + 1,
                             yLine,
                             id="%s_Ball" % node)
                ob.set_style(nameStyle)
                svg.addElement(ob)
            yLine += nameFontLineHgt

            if (hasattr(node, "bitsSome")):
                ob = SvgText("S:" +
                             bits_to_string(node.numBits, node.bitsSome),
                             node.x + 1,
                             yLine,
                             id="%s_Bsome" % node)
                ob.set_style(nameStyle)
                svg.addElement(ob)
            yLine += nameFontLineHgt

    # draw branches

    for depth in depthToNames:
        for name in depthToNames[depth]:
            node = nameToNode[name]
            if (node.left == None): continue

            (leftStartX, leftStartY) = (node.x + 0.4 * dc.nodeWidth,
                                        node.y + dc.nodeHeight)
            (rightStartX, rightStartY) = (node.x + 0.6 * dc.nodeWidth,
                                          node.y + dc.nodeHeight)
            (leftEndX, leftEndY) = (node.left.x + 0.5 * dc.nodeWidth,
                                    node.right.y)
            (rightEndX, rightEndY) = (node.right.x + 0.5 * dc.nodeWidth,
                                      node.right.y)

            draw_branch(svg, "%s_left_branch" % node, leftStartX, leftStartY,
                        leftEndX, leftEndY)
            draw_branch(svg, "%s_right_branch" % node, rightStartX,
                        rightStartY, rightEndX, rightEndY)

    return svg
コード例 #13
0
ファイル: NodeRenderer.py プロジェクト: perfidia/parsetreegen
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);