def __init__(self, path, debug=0, capacity=-1): self.fontList = copy.copy(xhtml2pdf.default.DEFAULT_FONT) set_value(self, ('path', 'story', 'text', 'log', 'frameStaticList', 'pisaBackgroundList', 'frameList', 'anchorFrag', 'anchorName', 'fragList', 'fragAnchor', 'fragStack' ), [], _copy=True) set_value(self, ('node', 'indexing_story', 'template', 'keepInFrameIndex', 'tableData', 'image'), None) set_value(self, ('err', 'warn', 'uidctr', 'listCounter'), 0) set_value(self, ('text', 'cssText', 'cssDefaultText'), "") set_value(self, ('templateList', 'frameStatic', 'imageData'), {}, _copy=True) self.capacity = capacity self.toc = PmlTableOfContents() self.multiBuild = False self.pageSize = A4 self.baseFontSize = getSize("12pt") self.frag = self.fragBlock = getParaFrag( ParagraphStyle('default%d' % self.UID())) self.fragStrip = True self.force = False # External callback function for path calculations self.pathCallback = None # Store path to document self.pathDocument = path or "__dummy__" parts = urlparse.urlparse(self.pathDocument) if not parts.scheme: self.pathDocument = os.path.abspath(self.pathDocument) self.pathDirectory = getDirName(self.pathDocument) self.meta = dict( author="", title="", subject="", keywords="", pagesize=A4, )
def __init__(self, path, debug=0, capacity=-1): self.fontList = copy.copy(xhtml2pdf.default.DEFAULT_FONT) self.asianFontList = copy.copy(xhtml2pdf.default.DEFAULT_ASIAN_FONT) set_value(self, ('path', 'story', 'text', 'log', 'frameStaticList', 'pisaBackgroundList', 'frameList', 'anchorFrag', 'anchorName', 'fragList', 'fragAnchor', 'fragStack' ), [], _copy=True) set_value(self, ('node', 'indexing_story', 'templates', 'keepInFrameIndex', 'tableData', 'image'), None) set_value(self, ('err', 'warn', 'uidctr', 'listCounter'), 0) set_value(self, ('text', 'cssText', 'cssDefaultText'), "") set_value(self, ('templateList', 'frameStatic', 'imageData'), {}, _copy=True) self.capacity = capacity self.toc = PmlTableOfContents() self.multiBuild = False self.pageSize = A4 self.baseFontSize = getSize("12pt") self.frag = self.fragBlock = getParaFrag( ParagraphStyle('default%d' % self.UID())) self.fragStrip = True self.force = False # External callback function for path calculations self.pathCallback = None # Store path to document self.pathDocument = path or "__dummy__" parts = urlparse.urlparse(self.pathDocument) if not parts.scheme: self.pathDocument = os.path.abspath(self.pathDocument) self.pathDirectory = getDirName(self.pathDocument) self.meta = dict( author="", title="", subject="", keywords="", pagesize=A4, )
def set_borders(self, frag, attrs): set_value(frag, ('borderLeftColor', 'borderRightColor', 'borderTopColor', 'borderBottomColor'), attrs.bordercolor) set_value(frag, ('borderLeftWidth', 'borderRightWidth', 'borderTopWidth', 'borderBottomWidth'), attrs.border) set_value(frag, ('borderBottomStyle', 'borderLeftStyle', 'borderTopStyle', 'borderRightStyle'), "solid")
def getParaFrag(style): frag = ParaFrag() set_value(frag, ('sub', 'super', 'rise', 'underline', 'strike', 'greek', 'leading', 'leadingSpace', 'spaceBefore', 'spaceAfter', 'leftIndent', 'rightIndent', 'firstLineIndent', 'borderPadding', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'bulletIndent', 'insideStaticFrame', 'outlineLevel' ), 0) set_value(frag, ('backColor', 'vAlign', 'link', 'borderStyle', 'borderColor', 'listStyleType', 'listStyleImage', 'wordWrap', 'height', 'width', 'bulletText' ), None ) set_value(frag, ('pageNumber', 'pageCount', 'outline', 'outlineOpen', 'keepWithNext'), False) frag.text = "" frag.fontName = "Times-Roman" frag.fontName, frag.bold, frag.italic = ps2tt(style.fontName) frag.fontSize = style.fontSize frag.textColor = style.textColor # Extras frag.letterSpacing = "normal" frag.leadingSource = "150%" frag.alignment = TA_LEFT frag.borderWidth = 1 frag.borderLeftWidth = frag.borderWidth frag.borderLeftColor = frag.borderColor frag.borderLeftStyle = frag.borderStyle frag.borderRightWidth = frag.borderWidth frag.borderRightColor = frag.borderColor frag.borderRightStyle = frag.borderStyle frag.borderTopWidth = frag.borderWidth frag.borderTopColor = frag.borderColor frag.borderTopStyle = frag.borderStyle frag.borderBottomWidth = frag.borderWidth frag.borderBottomColor = frag.borderColor frag.borderBottomStyle = frag.borderStyle frag.whiteSpace = "normal" frag.bulletFontName = "Helvetica" frag.zoom = 1.0 return frag
def test_set_value(self): a = self.A() b = self.B(20, 30) c = self.C() set_value(a, ["attr", "attr1"], 8) set_value(b, ["attr", "attr1"], 8) set_value(c, ["attr", "attr1"], 8) self.assertEqual(a.attr, 8) self.assertEqual(a.attr1, 8) self.assertEqual(b.attr, 8) self.assertEqual(b.attr1, 8) self.assertEqual(c.attr, 8) self.assertEqual(c.attr1, 8)
def set_borders(self, frag, attrs): set_value(frag, ('borderLeftColor', 'borderRightColor', 'borderTopColor', 'borderBottomColor'), attrs.bordercolor) set_value(frag, ('borderLeftWidth', 'borderRightWidth', 'borderTopWidth', 'borderBottomWidth'), attrs.border) set_value(frag, ('borderBottomStyle', 'borderLeftStyle', 'borderTopStyle', 'borderRightStyle'), "solid" )
def start(self, c): if self.attr.align is not None: c.frag.alignment = getAlign(self.attr.align) c.clearFrag() self.story = c.swapStory() attrs = self.attr tdata = c.tableData cspan = attrs.colspan rspan = attrs.rowspan row = tdata.row col = tdata.col while 1: for x, y in tdata.span: if x == col and y == row: col += 1 tdata.col += 1 break begin = (col, row) end = (col, row) if cspan: end = (end[0] + cspan - 1, end[1]) if rspan: end = (end[0], end[1] + rspan - 1) if begin != end: tdata.add_style(('SPAN', begin, end)) for x in six.moves.range(begin[0], end[0] + 1): for y in six.moves.range(begin[1], end[1] + 1): if x != begin[0] or y != begin[1]: tdata.add_empty(x, y) # Set Border and padding styles tdata.add_cell_styles(c, begin, end, "td") # Calculate widths # Add empty placeholders for new columns if (col + 1) > len(tdata.colw): tdata.colw = tdata.colw + \ ((col + 1 - len(tdata.colw)) * [_width()]) # Get value of with, if no spanning if not cspan: width = c.frag.width or self.attr.width # If is value, the set it in the right place in the arry if width is not None: tdata.colw[col] = _width(width) log.debug("Col {} has width {}".format(col, width)) else: # If there are no child nodes, nothing within the column can change the # width. Set the column width to the sum of the right and left padding # rather than letting it default. log.debug(width) if len(self.node.childNodes) == 0: width = c.frag.paddingLeft + c.frag.paddingRight log.debug("Col {} has width {}".format(col, width)) if width: tdata.colw[col] = _width(width) else: # Child nodes are present, we cannot do anything about the # width except set it externally. pass # Calculate heights if row + 1 > len(tdata.rowh): tdata.rowh = tdata.rowh + \ ((row + 1 - len(tdata.rowh)) * [_width()]) if not rspan: height = c.frag.height or self.attr.get('height', None) if height is not None: tdata.rowh[row] = _height(height) tdata.add_style(('FONTSIZE', begin, end, 1.0)) tdata.add_style(('LEADING', begin, end, 1.0)) # Vertical align valign = self.attr.valign or c.frag.vAlign if valign is not None: tdata.add_style(('VALIGN', begin, end, valign.upper())) # Reset border, otherwise the paragraph block will have borders too frag = c.frag set_value(frag, ('borderLeftWidth', 'borderRightWidth', 'borderTopWidth', 'borderBottomWidth'), 0) set_value(frag, ('borderLeftColor', 'borderLeftStyle', 'borderRightColor', 'borderRightStyle', 'borderTopColor', 'borderTopStyle', 'borderBottomColor', 'borderBottomStyle'), None)
def start(self, c): if self.attr.align is not None: c.frag.alignment = getAlign(self.attr.align) c.clearFrag() self.story = c.swapStory() attrs = self.attr tdata = c.tableData cspan = attrs.colspan rspan = attrs.rowspan row = tdata.row col = tdata.col while 1: for x, y in tdata.span: if x == col and y == row: col += 1 tdata.col += 1 break begin = (col, row) end = (col, row) if cspan: end = (end[0] + cspan - 1, end[1]) if rspan: end = (end[0], end[1] + rspan - 1) if begin != end: tdata.add_style(('SPAN', begin, end)) for x in six.moves.range(begin[0], end[0] + 1): for y in six.moves.range(begin[1], end[1] + 1): if x != begin[0] or y != begin[1]: tdata.add_empty(x, y) # Set Border and padding styles tdata.add_cell_styles(c, begin, end, "td") # Calculate widths # Add empty placeholders for new columns if (col + 1) > len(tdata.colw): tdata.colw = tdata.colw + \ ((col + 1 - len(tdata.colw)) * [_width()]) # Get value of with, if no spanning if not cspan: width = c.frag.width or self.attr.width # If is value, the set it in the right place in the arry if width is not None: tdata.colw[col] = _width(width) log.debug("Col {} has width {}".format(col, width)) else: # If there are no child nodes, nothing within the column can change the # width. Set the column width to the sum of the right and left padding # rather than letting it default. log.debug(width) if len(self.node.childNodes) == 0: width = c.frag.paddingLeft + c.frag.paddingRight log.debug("Col {} has width {}".format(col, width)) if width: tdata.colw[col] = _width(width) else: # Child nodes are present, we cannot do anything about the # width except set it externally. pass # Calculate heights if row + 1 > len(tdata.rowh): tdata.rowh = tdata.rowh + \ ((row + 1 - len(tdata.rowh)) * [_width()]) if not rspan: height = c.frag.height or self.attr.get('height', None) if height is not None: tdata.rowh[row] = _height(height) tdata.add_style(('FONTSIZE', begin, end, 1.0)) tdata.add_style(('LEADING', begin, end, 1.0)) # Vertical align valign = self.attr.valign or c.frag.vAlign if valign is not None: tdata.add_style(('VALIGN', begin, end, valign.upper())) # Reset border, otherwise the paragraph block will have borders too frag = c.frag set_value(frag, ('borderLeftWidth', 'borderRightWidth', 'borderTopWidth', 'borderBottomWidth'), 0) set_value(frag, ('borderLeftColor', 'borderLeftStyle', 'borderRightColor', 'borderRightStyle', 'borderTopColor', 'borderTopStyle', 'borderBottomColor', 'borderBottomStyle'), None )