Beispiel #1
0
    def render(self, node):
        tags = {
            'drawCentredString': self._draw_centred_string,
            'drawCenteredString': self._draw_centred_string,
            'drawRightString': self._draw_right_string,
            'drawString': self._draw_string,
            'rect': self._rect,
            'ellipse': self._ellipse,
            'lines': self._lines,
            'grid': self._grid,
            'curves': self._curves,
            'fill': lambda node: self.canvas.setFillColor(color.get(node.getAttribute('color'))),
            'stroke': lambda node: self.canvas.setStrokeColor(color.get(node.getAttribute('color'))),
            'setFont': lambda node: self.canvas.setFont(node.getAttribute('name'), utils.unit_get(node.getAttribute('size'))),
            'place': self._place,
            'circle': self._circle,
            'lineMode': self._line_mode,
            'path': self._path,
            'rotate': lambda node: self.canvas.rotate(float(node.getAttribute('degrees'))),
            'translate': self._translate,
            'image': self._image}

        for nd in node.childNodes:
            if nd.nodeType == nd.ELEMENT_NODE:
                for tag in tags:
                    if nd.localName == tag:
                        tags[tag](nd)
                        break
Beispiel #2
0
 def _table_style_get(self, style_node):
     styles = []
     for node in style_node.childNodes:
         if node.nodeType == node.ELEMENT_NODE:
             start = utils.tuple_int_get(node, 'start', (0, 0))
             stop = utils.tuple_int_get(node, 'stop', (-1, -1))
             if node.localName == 'blockValign':
                 styles.append(('VALIGN', start, stop,
                             str(node.getAttribute('value'))))
             elif node.localName == 'blockFont':
                 styles.append(('FONT', start, stop,
                                 str(node.getAttribute('name'))))
             elif node.localName == 'blockTextColor':
                 styles.append(('TEXTCOLOR', start, stop,
                     color.get(str(node.getAttribute('colorName')))))
             elif node.localName == 'blockLeading':
                 styles.append(('LEADING', start, stop,
                     utils.unit_get(node.getAttribute('length'))))
             elif node.localName == 'blockAlignment':
                 styles.append(('ALIGNMENT', start, stop,
                     str(node.getAttribute('value'))))
             elif node.localName == 'blockLeftPadding':
                 styles.append(('LEFTPADDING', start, stop,
                     utils.unit_get(node.getAttribute('length'))))
             elif node.localName == 'blockRightPadding':
                 styles.append(('RIGHTPADDING', start, stop,
                     utils.unit_get(node.getAttribute('length'))))
             elif node.localName == 'blockTopPadding':
                 styles.append(('TOPPADDING', start, stop,
                     utils.unit_get(node.getAttribute('length'))))
             elif node.localName == 'blockBottomPadding':
                 styles.append(('BOTTOMPADDING', start, stop,
                     utils.unit_get(node.getAttribute('length'))))
             elif node.localName == 'blockBackground':
                 styles.append(('BACKGROUND', start, stop,
                     color.get(node.getAttribute('colorName'))))
             if node.hasAttribute('size'):
                 styles.append(('FONTSIZE', start, stop,
                     utils.unit_get(node.getAttribute('size'))))
             elif node.localName == 'lineStyle':
                 kind = node.getAttribute('kind')
                 kind_list = ['GRID', 'BOX', 'OUTLINE',
                              'INNERGRID', 'LINEBELOW',
                              'LINEABOVE', 'LINEBEFORE',
                              'LINEAFTER']
                 assert kind in kind_list
                 thick = 1
                 if node.hasAttribute('thickness'):
                     thick = float(node.getAttribute('thickness'))
                 styles.append((kind, start, stop, thick,
                               color.get(node.getAttribute('colorName'))))
     return platypus.tables.TableStyle(styles)
Beispiel #3
0
def attr_get(node, attrs, encoding, types=None, defaults=None):
    """
    parse a node and its attributes
    returning the data type specified in types
    otherwise returns a string

    parameter defaults must be dict or None
    """
    res = {}
    if defaults is not None:
        res.update(defaults)

    for name in attrs:
        if node.hasAttribute(name):
            res[name] = unit_get(node.getAttribute(name))
    if types:
        for key in types:
            if node.hasAttribute(key):
                if types[key] == 'str':
                    res[key] = node.getAttribute(key).encode(encoding)
                elif types[key] == 'bool':
                    res[key] = bool_get(node.getAttribute(key))
                elif types[key] == 'int':
                    res[key] = int(node.getAttribute(key))
                elif types[key] == 'color':
                    res[key] = color.get(node.getAttribute(key))
    return res
Beispiel #4
0
def attr_get(node, attrs, encoding, types=None, defaults=None):
    """
    parse a node and its attributes
    returning the data type specified in types
    otherwise returns a string

    parameter defaults must be dict or None
    """
    res = {}
    if defaults is not None:
        res.update(defaults)

    for name in attrs:
        if node.hasAttribute(name):
            res[name] = unit_get(node.getAttribute(name))
    if types:
        for key in types:
            if node.hasAttribute(key):
                if types[key] == "str":
                    res[key] = node.getAttribute(key).encode(encoding)
                elif types[key] == "bool":
                    res[key] = bool_get(node.getAttribute(key))
                elif types[key] == "int":
                    res[key] = int(node.getAttribute(key))
                elif types[key] == "color":
                    res[key] = color.get(node.getAttribute(key))
    return res
Beispiel #5
0
 def _para_style_update(self, style, node):
     for attr in ['textColor', 'backColor', 'bulletColor']:
         if node.hasAttribute(attr):
             style.__dict__[attr] = color.get(node.getAttribute(attr))
     for attr in ['fontName', 'bulletFontName', 'bulletText']:
         if node.hasAttribute(attr):
             style.__dict__[attr] = node.getAttribute(attr)
     for attr in ['fontSize', 'leftIndent', 'rightIndent', 'spaceBefore',
                  'spaceAfter', 'firstLineIndent', 'bulletIndent',
                  'bulletFontSize', 'leading']:
         if node.hasAttribute(attr):
             style.__dict__[attr] = utils.unit_get(node.getAttribute(attr))
     if node.hasAttribute('alignment'):
         align = {
             'right': reportlab.lib.enums.TA_RIGHT,
             'center': reportlab.lib.enums.TA_CENTER,
             'justify': reportlab.lib.enums.TA_JUSTIFY}
         style.alignment = align.get(node.getAttribute('alignment').lower(),
                                     reportlab.lib.enums.TA_LEFT)
     return style