def _table_style_get(self, style_node): styles = [] for node in style_node.childNodes: if node.nodeType==node.ELEMENT_NODE: start = utils.getAttrAsIntTuple(node, 'start', (0, 0)) stop = utils.getAttrAsIntTuple(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, utils.as_color(str(node.getAttribute('colorName'))))) elif node.localName=='blockLeading': styles.append(('LEADING', start, stop, utils.as_pt(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.as_pt(node.getAttribute('length')))) elif node.localName=='blockRightPadding': styles.append(('RIGHTPADDING', start, stop, utils.as_pt(node.getAttribute('length')))) elif node.localName=='blockTopPadding': styles.append(('TOPPADDING', start, stop, utils.as_pt(node.getAttribute('length')))) elif node.localName=='blockBottomPadding': styles.append(('BOTTOMPADDING', start, stop, utils.as_pt(node.getAttribute('length')))) elif node.localName=='blockBackground': styles.append(('BACKGROUND', start, stop, utils.as_color(node.getAttribute('colorName')))) elif node.localName=='blockSpan': styles.append(('SPAN', start, stop)) if node.hasAttribute('size'): styles.append(('FONTSIZE', start, stop, utils.as_pt(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, utils.as_color(node.getAttribute('colorName')))) return platypus.tables.TableStyle(styles)
def init_tag_handlers(self): self.tag_handlers = { 'drawCentredString': self._drawCenteredString, 'drawRightString': self._drawRightString, 'drawString': self._drawString, 'rect': self._rect, 'ellipse': self._ellipse, 'lines': self._lines, 'grid': self._grid, 'curves': self._curves, 'fill': lambda node: self.canvas.setFillColor(utils.as_color(node.getAttribute('color'))), 'stroke': lambda node: self.canvas.setStrokeColor(utils.as_color(node.getAttribute('color'))), 'setFont': lambda node: self.canvas.setFont(node.getAttribute('name'), utils.as_pt(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 }
def _para_style_update(self, style, node): for attr in ['textColor', 'backColor', 'bulletColor']: if node.hasAttribute(attr): style.__dict__[attr] = utils.as_color(node.getAttribute(attr)) for attr in ['fontName', 'bulletFontName', 'bulletText', 'wordWrap']: 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.as_pt(node.getAttribute(attr)) if node.hasAttribute('alignment'): align = dict(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