def _evalMeasurement(n): if isinstance(n, str): from reportlab.platypus.paraparser import _num n = _num(n) if isSeq(n): n = n[1] return n
def _evalMeasurement(n): if isinstance(n,str): from reportlab.platypus.paraparser import _num n = _num(n) if isSeq(n): n = n[1] return n
def _evalMeasurement(n): if type(n) is type(''): from reportlab.platypus.paraparser import _num n = _num(n) if type(n) is type(()): n = n[1] return n
def _flowable(self, node): if node.tag == 'para': style = self.styles.para_style_get(node) yield platypus.Paragraph(self._serialize_paragraph_content(node), style) elif node.tag == 'ref': style = self.styles.para_style_get(node) yield Ref(node.attrib.get('target'),style) elif node.tag == 'toc': styles = [] style_names = node.attrib.get('levelStyles','') for style_name in style_names.split(','): styles.append(self.styles.styles[style_name]) toc = TableOfContents(levelStyles=styles) yield toc elif node.tag == 'name': self.styles.names[ node.attrib.get('id')] = node.attrib.get('value') yield None elif node.tag == 'xpre': style = self.styles.para_style_get(node) raw = self._serialize_paragraph_content(node) yield XPreformatted(raw, style, **(utils.attr_get(node, [], {'bulletText': 'str', 'dedent': 'int', 'frags': 'int'}))) elif node.tag == 'pre': style = self.styles.para_style_get(node) text = self._textual(node) yield platypus.Preformatted(text, style, **(utils.attr_get(node, [], {'bulletText': 'str', 'dedent': 'int'}))) elif node.tag == 'illustration': yield self._illustration(node) elif node.tag == 'blockTable': yield self._table(node) elif node.tag == 'floatToEnd': yield self._floattoend(node) elif node.tag == 'keepTogether': yield self._keeptogether(node) elif node.tag == 'title': style = copy.deepcopy(self.styles.styles['Title']) self.styles._para_style_update(style,node) yield platypus.Paragraph(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText': 'str'}))) elif node.tag == 'h1': style = copy.deepcopy(self.styles.styles['Heading1']) self.styles._para_style_update(style,node) yield Heading( self._textual(node), style, short=node.attrib.get('short'), toc=node.attrib.get('toc'), outline=node.attrib.get('outline'), ) elif node.tag == 'h2': style = copy.deepcopy(self.styles.styles['Heading2']) self.styles._para_style_update(style,node) yield Heading( self._textual(node), style, short=node.attrib.get('short'), toc=node.attrib.get('toc'), outline=node.attrib.get('outline'), ) elif node.tag == 'h3': style = copy.deepcopy(self.styles.styles['Heading3']) self.styles._para_style_update(style,node) yield Heading( self._textual(node), style, short=node.attrib.get('short'), toc=node.attrib.get('toc'), outline=node.attrib.get('outline'), ) elif node.tag == 'h4': style = copy.deepcopy(self.styles.styles['Heading4']) self.styles._para_style_update(style,node) yield Heading( self._textual(node), style, short=node.attrib.get('short'), toc=node.attrib.get('toc'), outline=node.attrib.get('outline'), ) elif node.tag == 'h5': style = copy.deepcopy(self.styles.styles['Heading5']) self.styles._para_style_update(style,node) yield Heading( self._textual(node), style, short=node.attrib.get('short'), toc=node.attrib.get('toc'), outline=node.attrib.get('outline'), ) elif node.tag == 'h6': style = copy.deepcopy(self.styles.styles['Heading6']) self.styles._para_style_update(style,node) yield Heading( self._textual(node), style, short=node.attrib.get('short'), toc=node.attrib.get('toc'), outline=node.attrib.get('outline'), ) elif node.tag == 'image': attrs = utils.attr_get(node, ['width', 'height', 'kind', 'hAlign','mask','lazy']) if 'mask' not in attrs: attrs['mask'] = (250, 255, 250, 255, 250, 255) yield platypus.Image( node.attrib.get('file'),**attrs) elif node.tag == 'bookmark': yield Anchor( node.attrib.get('key'), short=node.attrib.get('short'), toc=node.attrib.get('tox'), outline=node.attrib.get('outline'), level=node.attrib.get('level'), ) elif node.tag == 'pdfpage': page_number = node.attrib.get('page') if not page_number: page_number = 0 else: page_number = int(page_number) page = PdfReader(node.attrib.get('file'), decompress=False).pages[page_number] yield PdfPage(page, **(utils.attr_get(node, ['width', 'height', 'kind','hAlign','rotation']))) elif node.tag == 'pdfpages': wrapper = node.attrib.get('wrapper') pdf = PdfReader(node.attrib.get('file'), decompress=False) options = utils.attr_get(node, ['width', 'height', 'kind','hAlign','rotation']) if wrapper: Wrapper = globals()[wrapper] for page in pdf.pages: yield Wrapper(PdfPage(page,**options)) else: for page in pdf.pages: yield PdfPage(page,**options) elif node.tag == 'spacer': if 'width' in node.attrib: width = utils.unit_get(node.attrib.get('width')) else: width = utils.unit_get('1cm') length = utils.unit_get(node.attrib.get('length')) yield platypus.Spacer(width=width, height=length) elif node.tag == 'barCode': yield code39.Extended39(self._textual(node)) elif node.tag == 'pageBreak': yield platypus.PageBreak() elif node.tag == 'condPageBreak': yield platypus.CondPageBreak(**(utils.attr_get(node, ['height']))) elif node.tag == 'setNextTemplate': yield platypus.NextPageTemplate(str(node.attrib.get('name'))) elif node.tag == 'nextFrame': yield platypus.CondPageBreak(1000) # TODO: change the 1000 ! elif node.tag == 'ul': yield self._list(node) elif node.tag == 'hr': kw = {} if 'thickness' in node.attrib: kw['thickness'] = utils.unit_get(node.attrib.get('thickness')) if 'spaceBefore' in node.attrib: kw['spaceBefore'] = utils.unit_get(node.attrib.get('spaceBefore')) if 'spaceAfter' in node.attrib: kw['spaceAfter'] = utils.unit_get(node.attrib.get('spaceAfter')) if 'color' in node.attrib: kw['color'] = color.get(node.attrib.get('color','')) if 'width' in node.attrib: kw['width'] = node.attrib.get('width') if 'dash' in node.attrib: kw['dash'] = node.attrib.get('dash') if 'hAlign' in node.attrib: kw['hAlign'] = node.attrib.get('hAlign') if 'cAlign' in node.attrib: kw['cAlign'] = node.attrib.get('cAlign') yield platypus.flowables.HRFlowable(**kw) elif node.tag == 'indent': from reportlab.platypus.paraparser import _num kw = {} for key in ('left','right'): if key in node.attrib: kw[key] = _num(node.attrib.get(key)) yield platypus.Indenter(**kw) for child in node: for flow in self._flowable(child): yield flow yield platypus.Indenter(**{x:-1*y for x,y in kw.items()}) else: logger.warn('flowable "%s" not yet implemented',node.tag) yield None