def start(self, c): lst = _list_style_type.get(c.frag.listStyleType or "disc", _bullet) #log.debug("frag %r", c.copyFrag( # text=lst, # bulletFontName=c.getFontName("helvetica"), # fontName=c.getFontName("helvetica"))) # c.addFrag("") #frag = ParaFrag() #frag.fontName = frag.bulletFontName = c.getFontName("helvetica") #frag.fontSize = c.frag.fontSize #c.frag.fontName = c.getFontName("helvetica") frag = copy.copy(c.frag) #print "###", c.frag.fontName #frag.fontName = "au_00" # c.getFontName("helvetica") #frag.bulletFontName = "au_00" # c.getFontName("helvetica") if type(lst) == type(u""): frag.text = lst else: # XXX This should be the recent font, but it throws errors in Reportlab! frag.text = lst(c) # XXX This should usually be done in the context!!! frag.fontName = frag.bulletFontName = tt2ps(frag.fontName, frag.bold, frag.italic) c.frag.bulletText = [frag]
def start(self, c): lst = _list_style_type.get(c.frag.listStyleType or "disc", _bullet) frag = copy.copy(c.frag) self.offset = 0 if frag.listStyleImage is not None: frag.text = u"" f = frag.listStyleImage if f and (not f.notFound()): img = PmlImage( f.getData(), width=None, height=None) img.drawHeight *= dpi96 img.drawWidth *= dpi96 img.pisaZoom = frag.zoom img.drawWidth *= img.pisaZoom img.drawHeight *= img.pisaZoom frag.image = img self.offset = max(0, img.drawHeight - c.frag.fontSize) else: if type(lst) == type(u""): frag.text = lst else: # XXX This should be the recent font, but it throws errors in Reportlab! frag.text = lst(c) # XXX This should usually be done in the context!!! frag.fontName = frag.bulletFontName = tt2ps(frag.fontName, frag.bold, frag.italic) c.frag.bulletText = [frag]
def addFrag(self, text="", frag=None): frag = baseFrag = copy.deepcopy(self.frag) # if sub and super are both on they will cancel each other out if frag.sub == 1 and frag.super == 1: frag.sub = 0 frag.super = 0 # XXX Has to be replaced by CSS styles like vertical-align and font-size if frag.sub: frag.rise = -frag.fontSize * subFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) elif frag.super: frag.rise = frag.fontSize * superFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) if frag.greek: frag.fontName = 'symbol' data = _greekConvert(data) # bold, italic, and underline frag.fontName = tt2ps(frag.fontName, frag.bold, frag.italic) # Modify text for optimal whitespace handling # XXX Support Unicode whitespaces? # XXX What about images? # - Replace ­ by blank text = text.replace(u"\xad", "") # Replace ­ with blank if frag.whiteSpace == "pre": for text in re.split(r'(\r\n|\n|\r)', text): self.text += text if "\n" in text or "\r" in text: frag = copy.deepcopy(baseFrag) frag.text = "" frag.lineBreak = 1 self._appendFrag(frag) else: text = text.replace(u"\t", 8 * u" ") for text in re.split(r'(\ )', text): frag = copy.deepcopy(baseFrag) if text == " ": text = '\xc2\xa0' # XXX Don't ask me what's that! u"\xc2\xa0" frag.text = text self._appendFrag(frag) else: if text == u"\xa0": frag.text = '\xc2\xa0' self.text += text self._appendFrag(frag) else: frag.text = " ".join(("x" + text + "x").split())[1:-1] if self.fragStrip: frag.text = frag.text.lstrip() if frag.text: self.fragStrip = False self.text += frag.text self._appendFrag(frag)
def toParagraphStyle(self, first, full=False): style = ParagraphStyle('default%d' % self.UID(), keepWithNext=first.keepWithNext) style.fontName = first.fontName style.fontSize = first.fontSize style.leading = max(first.leading, first.fontSize * 1.25) style.backColor = first.backColor style.spaceBefore = first.spaceBefore style.spaceAfter = first.spaceAfter style.leftIndent = first.leftIndent style.rightIndent = first.rightIndent style.firstLineIndent = first.firstLineIndent style.textColor = first.textColor style.alignment = first.alignment style.bulletFontName = first.bulletFontName or first.fontName style.bulletFontSize = first.fontSize style.bulletIndent = first.bulletIndent # Border handling for Paragraph style.borderWidth = 0 if getBorderStyle(first.borderTopStyle): style.borderWidth = max(first.borderLeftWidth, first.borderRightWidth, first.borderTopWidth, first.borderBottomWidth) style.borderPadding = first.borderPadding # + first.borderWidth style.borderColor = first.borderTopColor # If no border color is given, the text color is used (XXX Tables!) if (style.borderColor is None) and style.borderWidth: style.borderColor = first.textColor if full: style.fontName = tt2ps(first.fontName, first.bold, first.italic) return style
def addFrag(self, text="", frag=None): frag = baseFrag = copy.deepcopy(self.frag) # if sub and super are both on they will cancel each other out if frag.sub == 1 and frag.super == 1: frag.sub = 0 frag.super = 0 # XXX Has to be replaced by CSS styles like vertical-align and font-size if frag.sub: frag.rise = -frag.fontSize * subFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) elif frag.super: frag.rise = frag.fontSize * superFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) if frag.greek: frag.fontName = "symbol" data = _greekConvert(data) # bold, italic, and underline frag.fontName = tt2ps(frag.fontName, frag.bold, frag.italic) # Modify text for optimal whitespace handling # XXX Support Unicode whitespaces? # XXX What about images? # - Replace ­ by blank text = text.replace(u"\xad", "") # Replace ­ with blank if frag.whiteSpace == "pre": for text in re.split(r"(\r\n|\n|\r)", text): self.text += text if "\n" in text or "\r" in text: frag = copy.deepcopy(baseFrag) frag.text = "" frag.lineBreak = 1 self._appendFrag(frag) else: text = text.replace(u"\t", 8 * u" ") for text in re.split(r"(\ )", text): frag = copy.deepcopy(baseFrag) if text == " ": text = "\xc2\xa0" # XXX Don't ask me what's that! u"\xc2\xa0" frag.text = text self._appendFrag(frag) else: if text == u"\xa0": frag.text = "\xc2\xa0" self.text += text self._appendFrag(frag) else: frag.text = " ".join(("x" + text + "x").split())[1:-1] if self.fragStrip: frag.text = frag.text.lstrip() if frag.text: self.fragStrip = False self.text += frag.text self._appendFrag(frag)
def toParagraphStyle(self, first): style = ParagraphStyle('default%d' % self.UID(), keepWithNext=first.keepWithNext) style.fontName = first.fontName style.fontSize = first.fontSize style.letterSpacing = first.letterSpacing style.leading = max(first.leading + first.leadingSpace, first.fontSize * 1.25) style.backColor = first.backColor style.spaceBefore = first.spaceBefore style.spaceAfter = first.spaceAfter style.leftIndent = first.leftIndent style.rightIndent = first.rightIndent style.firstLineIndent = first.firstLineIndent style.textColor = first.textColor style.alignment = first.alignment style.bulletFontName = first.bulletFontName or first.fontName style.bulletFontSize = first.fontSize style.bulletIndent = first.bulletIndent style.wordWrap = first.wordWrap # Border handling for Paragraph # Transfer the styles for each side of the border, *not* the whole # border values that reportlab supports. We'll draw them ourselves in # PmlParagraph. style.borderTopStyle = first.borderTopStyle style.borderTopWidth = first.borderTopWidth style.borderTopColor = first.borderTopColor style.borderBottomStyle = first.borderBottomStyle style.borderBottomWidth = first.borderBottomWidth style.borderBottomColor = first.borderBottomColor style.borderLeftStyle = first.borderLeftStyle style.borderLeftWidth = first.borderLeftWidth style.borderLeftColor = first.borderLeftColor style.borderRightStyle = first.borderRightStyle style.borderRightWidth = first.borderRightWidth style.borderRightColor = first.borderRightColor # If no border color is given, the text color is used (XXX Tables!) if (style.borderTopColor is None) and style.borderTopWidth: style.borderTopColor = first.textColor if (style.borderBottomColor is None) and style.borderBottomWidth: style.borderBottomColor = first.textColor if (style.borderLeftColor is None) and style.borderLeftWidth: style.borderLeftColor = first.textColor if (style.borderRightColor is None) and style.borderRightWidth: style.borderRightColor = first.textColor style.borderPadding = first.borderPadding style.paddingTop = first.paddingTop style.paddingBottom = first.paddingBottom style.paddingLeft = first.paddingLeft style.paddingRight = first.paddingRight style.fontName = tt2ps(first.fontName, first.bold, first.italic) return style
def toParagraphStyle(self, first): style = ParagraphStyle( 'default%d' % self.UID(), keepWithNext=first.keepWithNext) copy_attrs(style, first, ('fontName', 'fontSize', 'letterSpacing', 'backColor', 'spaceBefore', 'spaceAfter', 'leftIndent', 'rightIndent', 'firstLineIndent', 'textColor', 'alignment', 'bulletIndent', 'wordWrap', 'borderTopStyle', 'borderTopWidth', 'borderTopColor', 'borderBottomStyle', 'borderBottomWidth', 'borderBottomColor', 'borderLeftStyle', 'borderLeftWidth', 'borderLeftColor', 'borderRightStyle', 'borderRightWidth', 'borderRightColor', 'paddingTop', 'paddingBottom', 'paddingLeft', 'paddingRight', 'borderPadding' ) ) style.leading = max( first.leading + first.leadingSpace, first.fontSize * 1.25) style.bulletFontName = first.bulletFontName or first.fontName style.bulletFontSize = first.fontSize # Border handling for Paragraph # Transfer the styles for each side of the border, *not* the whole # border values that reportlab supports. We'll draw them ourselves in # PmlParagraph. # If no border color is given, the text color is used (XXX Tables!) if (style.borderTopColor is None) and style.borderTopWidth: style.borderTopColor = first.textColor if (style.borderBottomColor is None) and style.borderBottomWidth: style.borderBottomColor = first.textColor if (style.borderLeftColor is None) and style.borderLeftWidth: style.borderLeftColor = first.textColor if (style.borderRightColor is None) and style.borderRightWidth: style.borderRightColor = first.textColor style.fontName = tt2ps(first.fontName, first.bold, first.italic) return style
def addFrag(self, text="", frag=None): frag = baseFrag = self.frag.clone() # if sub and super are both on they will cancel each other out if frag.sub == 1 and frag.super == 1: frag.sub = 0 frag.super = 0 # XXX Has to be replaced by CSS styles like vertical-align and font-size if frag.sub: frag.rise = - frag.fontSize * subFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) elif frag.super: frag.rise = frag.fontSize * superFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) # XXX Unused? #if frag.greek: # frag.fontName = 'symbol' # text = _greekConvert(text) # bold, italic, and underline frag.fontName = frag.bulletFontName = tt2ps(frag.fontName, frag.bold, frag.italic) # print frag.bulletFontName # Modify text for optimal whitespace handling # XXX Support Unicode whitespaces? # XXX What about images? # XXX Doesn't work with Reportlab > 2.1 # NBSP = '\xc2\xa0' # u"_" #if REPORTLAB22: # NBSP = u" " # Replace ­ with empty and normalize NBSP text = (text .replace(u"\xad", u"") .replace(u"\xc2\xa0", NBSP) .replace(u"\xa0", NBSP)) # log.debug("> %r", text) if frag.whiteSpace == "pre": # Handle by lines for text in re.split(r'(\r\n|\n|\r)', text): # This is an exceptionally expensive piece of code self.text += text if ("\n" in text) or ("\r" in text): # If EOL insert a linebreak frag = baseFrag.clone() frag.text = "" frag.lineBreak = 1 self._appendFrag(frag) else: # Handle tabs in a simple way text = text.replace(u"\t", 8 * u" ") # Somehow for Reportlab NBSP have to be inserted # as single character fragments for text in re.split(r'(\ )', text): frag = baseFrag.clone() if text == " ": text = NBSP frag.text = text self._appendFrag(frag) else: for text in re.split(u'(' + NBSP + u')', text): frag = baseFrag.clone() if text == NBSP: self.force = True frag.text = NBSP self.text += text self._appendFrag(frag) else: frag.text = " ".join(("x" + text + "x").split())[1: - 1] if self.fragStrip: frag.text = frag.text.lstrip() if frag.text: self.fragStrip = False self.text += frag.text self._appendFrag(frag)
def addFrag(self, text="", frag=None): frag = baseFrag = self.frag.clone() # if sub and super are both on they will cancel each other out if frag.sub == 1 and frag.super == 1: frag.sub = 0 frag.super = 0 # XXX Has to be replaced by CSS styles like vertical-align and font-size if frag.sub: frag.rise = -frag.fontSize * subFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) elif frag.super: frag.rise = frag.fontSize * superFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) # bold, italic, and underline frag.fontName = frag.bulletFontName = tt2ps(frag.fontName, frag.bold, frag.italic) # Replace ­ with empty and normalize NBSP text = (text.replace(u"\xad", u"").replace(u"\xc2\xa0", NBSP).replace(u"\xa0", NBSP)) if frag.whiteSpace == "pre": # Handle by lines for text in re.split(r'(\r\n|\n|\r)', text): # This is an exceptionally expensive piece of code self.text += text if ("\n" in text) or ("\r" in text): # If EOL insert a linebreak frag = baseFrag.clone() frag.text = "" frag.lineBreak = 1 self._appendFrag(frag) else: # Handle tabs in a simple way text = text.replace(u"\t", 8 * u" ") # Somehow for Reportlab NBSP have to be inserted # as single character fragments for text in re.split(r'(\ )', text): frag = baseFrag.clone() if text == " ": text = NBSP frag.text = text self._appendFrag(frag) else: for text in re.split(u'(' + NBSP + u')', text): frag = baseFrag.clone() if text == NBSP: self.force = True frag.text = NBSP self.text += text self._appendFrag(frag) else: frag.text = " ".join(("x" + text + "x").split())[1:-1] if self.fragStrip: frag.text = frag.text.lstrip() if frag.text: self.fragStrip = False self.text += frag.text self._appendFrag(frag)
def addFrag(self, text="", frag=None): frag = baseFrag = self.frag.clone() # if sub and super are both on they will cancel each other out if frag.sub == 1 and frag.super == 1: frag.sub = 0 frag.super = 0 # XXX Has to be replaced by CSS styles like vertical-align and font-size if frag.sub: frag.rise = - frag.fontSize * subFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) elif frag.super: frag.rise = frag.fontSize * superFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) # bold, italic, and underline frag.fontName = frag.bulletFontName = tt2ps(frag.fontName, frag.bold, frag.italic) # Replace ­ with empty and normalize NBSP text = (text .replace("\xad", "") .replace("\xc2\xa0", NBSP) .replace("\xa0", NBSP)) if frag.whiteSpace == "pre": # Handle by lines for text in re.split(r'(\r\n|\n|\r)', text): # This is an exceptionally expensive piece of code self.text += text if ("\n" in text) or ("\r" in text): # If EOL insert a linebreak frag = baseFrag.clone() frag.text = "" frag.lineBreak = 1 self._appendFrag(frag) else: # Handle tabs in a simple way text = text.replace("\t", 8 * " ") # Somehow for Reportlab NBSP have to be inserted # as single character fragments for text in re.split(r'(\ )', text): frag = baseFrag.clone() if text == " ": text = NBSP frag.text = text self._appendFrag(frag) else: for text in re.split('(' + NBSP + ')', text): frag = baseFrag.clone() if text == NBSP: self.force = True frag.text = NBSP self.text += text self._appendFrag(frag) else: frag.text = " ".join(("x" + text + "x").split())[1: - 1] if self.fragStrip: frag.text = frag.text.lstrip() if frag.text: self.fragStrip = False self.text += frag.text self._appendFrag(frag)
def addFrag(self, text="", frag=None): frag = baseFrag = self.frag.clone() # if sub and super are both on they will cancel each other out if frag.sub == 1 and frag.super == 1: frag.sub = 0 frag.super = 0 # XXX Has to be replaced by CSS styles like vertical-align and font-size if frag.sub: frag.rise = -frag.fontSize * subFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) elif frag.super: frag.rise = frag.fontSize * superFraction frag.fontSize = max(frag.fontSize - sizeDelta, 3) # XXX Unused? #if frag.greek: # frag.fontName = 'symbol' # text = _greekConvert(text) # bold, italic, and underline frag.fontName = frag.bulletFontName = tt2ps(frag.fontName, frag.bold, frag.italic) # print frag.bulletFontName # Modify text for optimal whitespace handling # XXX Support Unicode whitespaces? # XXX What about images? # XXX Doesn't work with Reportlab > 2.1 # NBSP = '\xc2\xa0' # u"_" NBSP = u"\u00a0" # Replace ­ with empty and normalize NBSP text = (text.replace(u"\xad", u"").replace(u"\xc2\xa0", NBSP).replace(u"\xa0", NBSP)) # log.debug("> %r", text) if frag.whiteSpace == "pre": # Handle by lines for text in re.split(r'(\r\n|\n|\r)', text): # This is an exceptionally expensive piece of code self.text += text if ("\n" in text) or ("\r" in text): # If EOL insert a linebreak frag = baseFrag.clone() frag.text = "" frag.lineBreak = 1 self._appendFrag(frag) else: # Handle tabs in a simple way text = text.replace(u"\t", 8 * u" ") # Somehow for Reportlab NBSP have to be inserted # as single character fragments for text in re.split(r'(\ )', text): frag = baseFrag.clone() if text == " ": text = NBSP frag.text = text self._appendFrag(frag) else: for text in re.split(u'(' + NBSP + u')', text): frag = baseFrag.clone() if text == NBSP: frag.text = NBSP self.text += text self._appendFrag(frag) else: frag.text = " ".join(("x" + text + "x").split())[1:-1] if self.fragStrip: frag.text = frag.text.lstrip() if frag.text: self.fragStrip = False self.text += frag.text self._appendFrag(frag)
def toParagraphStyle(self, first, full=False): style = ParagraphStyle('default%d' % self.UID(), keepWithNext=first.keepWithNext) style.fontName = first.fontName style.fontSize = first.fontSize style.leading = max(first.leading, first.fontSize * 1.25) style.backColor = first.backColor style.spaceBefore = first.spaceBefore style.spaceAfter = first.spaceAfter style.leftIndent = first.leftIndent style.rightIndent = first.rightIndent style.firstLineIndent = first.firstLineIndent style.textColor = first.textColor style.alignment = first.alignment style.bulletFontName = first.bulletFontName or first.fontName style.bulletFontSize = first.fontSize style.bulletIndent = first.bulletIndent # Border handling for Paragraph # Transfer the styles for each side of the border, *not* the whole # border values that reportlab supports. We'll draw them ourselves in # PmlParagraph. style.borderTopStyle = first.borderTopStyle style.borderTopWidth = first.borderTopWidth style.borderTopColor = first.borderTopColor style.borderBottomStyle = first.borderBottomStyle style.borderBottomWidth = first.borderBottomWidth style.borderBottomColor = first.borderBottomColor style.borderLeftStyle = first.borderLeftStyle style.borderLeftWidth = first.borderLeftWidth style.borderLeftColor = first.borderLeftColor style.borderRightStyle = first.borderRightStyle style.borderRightWidth = first.borderRightWidth style.borderRightColor = first.borderRightColor # If no border color is given, the text color is used (XXX Tables!) if (style.borderTopColor is None) and style.borderTopWidth: style.borderTopColor = first.textColor if (style.borderBottomColor is None) and style.borderBottomWidth: style.borderBottomColor = first.textColor if (style.borderLeftColor is None) and style.borderLeftWidth: style.borderLeftColor = first.textColor if (style.borderRightColor is None) and style.borderRightWidth: style.borderRightColor = first.textColor style.borderPadding = first.borderPadding style.paddingTop = first.paddingTop style.paddingBottom = first.paddingBottom style.paddingLeft = first.paddingLeft style.paddingRight = first.paddingRight # This is the old code replaced by the above, kept for reference #style.borderWidth = 0 #if getBorderStyle(first.borderTopStyle): # style.borderWidth = max(first.borderLeftWidth, first.borderRightWidth, first.borderTopWidth, first.borderBottomWidth) # style.borderPadding = first.borderPadding # + first.borderWidth # style.borderColor = first.borderTopColor # # If no border color is given, the text color is used (XXX Tables!) # if (style.borderColor is None) and style.borderWidth: # style.borderColor = first.textColor if full: style.fontName = tt2ps(first.fontName, first.bold, first.italic) return style