def _initial_frag(self,attr,attrMap,bullet=0): style = self._style if attr!={}: style = copy.deepcopy(style) _applyAttributes(style,self.getAttributes(attr,attrMap)) self._style = style # initialize semantic values frag = ParaFrag() frag.sub = 0 frag.super = 0 frag.rise = 0 frag.underline = 0 frag.strike = 0 frag.greek = 0 frag.link = None if bullet: frag.fontName, frag.bold, frag.italic = ps2tt(style.bulletFontName) frag.fontSize = style.bulletFontSize frag.textColor = hasattr(style,'bulletColor') and style.bulletColor or style.textColor else: frag.fontName, frag.bold, frag.italic = ps2tt(style.fontName) frag.fontSize = style.fontSize frag.textColor = style.textColor return frag
def _initial_frag(self, attr, attrMap, bullet=0): style = self._style if attr != {}: style = copy.deepcopy(style) _applyAttributes(style, self.getAttributes(attr, attrMap)) self._style = style # initialize semantic values frag = ParaFrag() frag.sub = 0 frag.super = 0 frag.rise = 0 frag.underline = 0 frag.strike = 0 frag.greek = 0 frag.link = None if bullet: frag.fontName, frag.bold, frag.italic = ps2tt(style.bulletFontName) frag.fontSize = style.bulletFontSize frag.textColor = hasattr( style, 'bulletColor') and style.bulletColor or style.textColor else: frag.fontName, frag.bold, frag.italic = ps2tt(style.fontName) frag.fontSize = style.fontSize frag.textColor = style.textColor return frag
def elem2frags(self, elem, style): #print "elem2frags(%s)" % elem frag = ParaFrag() frag.text = '' frag.fontName = style.fontName frag.fontSize = style.fontSize frag.textColor = style.textColor frag.rise = style.rise frag.underline = style.underline frag.strike = 0 # added for reportlab 2.0 frag.link = None # added for reportlab 2.0 if elem.__class__ == html.CDATA: frag.text = " ".join(elem.text.split()) if elem.text.startswith(" "): frag.text = " " + frag.text if elem.text.endswith(" "): frag.text += " " #frag.text=elem.text yield frag return if elem.__class__ == html.BR: #frag.text='\n' frag.lineBreak = True yield frag return assert hasattr(elem, 'content') if elem.__class__ in (html.EM, html.I): family, bold, italic = ps2tt(frag.fontName) frag.fontName = tt2ps(family, bold, 1) #frag.fontName=frag.fontName+"-Italic" elif elem.__class__ == html.TT: family, bold, italic = ps2tt(frag.fontName) frag.fontName = tt2ps("Courier", bold, italic) elif elem.__class__ == html.B: family, bold, italic = ps2tt(frag.fontName) frag.fontName = tt2ps(family, 1, italic) elif elem.__class__ == html.U: frag.underline = True elif elem.__class__ == html.SUP: frag.rise = True else: raise "Cannot handle <%s> inside a paragraph" \ % elem.tag() ## for e in elem.content: ## if e.__class__ == html.CDATA: ## frag.text += e.text ## else: ## for ee in elem.content: ## for f in self.elem2frags(ee,frag): ## yield f for e in elem.content: for f in self.elem2frags(e, frag): yield f yield frag
def elem2frags(self, elem, style): # print "elem2frags(%s)" % elem frag = ParaFrag() frag.text = "" frag.fontName = style.fontName frag.fontSize = style.fontSize frag.textColor = style.textColor frag.rise = style.rise frag.underline = style.underline frag.strike = 0 # added for reportlab 2.0 frag.link = None # added for reportlab 2.0 if elem.__class__ == html.CDATA: frag.text = " ".join(elem.text.split()) if elem.text.startswith(" "): frag.text = " " + frag.text if elem.text.endswith(" "): frag.text += " " # frag.text=elem.text yield frag return if elem.__class__ == html.BR: # frag.text='\n' frag.lineBreak = True yield frag return assert hasattr(elem, "content") if elem.__class__ in (html.EM, html.I): family, bold, italic = ps2tt(frag.fontName) frag.fontName = tt2ps(family, bold, 1) # frag.fontName=frag.fontName+"-Italic" elif elem.__class__ == html.TT: family, bold, italic = ps2tt(frag.fontName) frag.fontName = tt2ps("Courier", bold, italic) elif elem.__class__ == html.B: family, bold, italic = ps2tt(frag.fontName) frag.fontName = tt2ps(family, 1, italic) elif elem.__class__ == html.U: frag.underline = True elif elem.__class__ == html.SUP: frag.rise = True else: raise "Cannot handle <%s> inside a paragraph" % elem.tag() ## for e in elem.content: ## if e.__class__ == html.CDATA: ## frag.text += e.text ## else: ## for ee in elem.content: ## for f in self.elem2frags(ee,frag): ## yield f for e in elem.content: for f in self.elem2frags(e, frag): yield f yield frag
def start_span(self, attr): A = self.getAttributes(attr, _spanAttrMap) if 'style' in A: style = self.findSpanStyle(A.pop('style')) D = {} for k in 'fontName fontSize textColor backColor'.split(): v = getattr(style, k, self) if v is self: continue D[k] = v D.update(A) A = D if 'fontName' in A: A['fontName'], A['bold'], A['italic'] = ps2tt(A['fontName']) self._push('span', **A)
def start_span(self,attr): A = self.getAttributes(attr,_spanAttrMap) if 'style' in A: style = self.findSpanStyle(A.pop('style')) D = {} for k in 'fontName fontSize textColor backColor'.split(): v = getattr(style,k,self) if v is self: continue D[k] = v D.update(A) A = D if 'fontName' in A: A['fontName'], A['bold'], A['italic'] = ps2tt(A['fontName']) self._push('span',**A)
def start_span(self, attr): A = self.getAttributes(attr, _spanAttrMap) if "style" in A: style = self.findSpanStyle(A.pop("style")) D = {} for k in "fontName fontSize textColor backColor".split(): v = getattr(style, k, self) if v is self: continue D[k] = v D.update(A) A = D if "fontName" in A: A["fontName"], A["bold"], A["italic"] = ps2tt(A["fontName"]) self._push("span", **A)
import common from common.reportlab_styles import extend_style, extend_table_style from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_JUSTIFY from reportlab.lib.fonts import ps2tt from reportlab.lib.styles import ParagraphStyle from reportlab.pdfbase.pdfmetrics import registerFont, registerFontFamily from reportlab.pdfbase.ttfonts import TTFont from reportlab.platypus import TableStyle import os FONT_DIR = os.path.join(os.path.dirname(common.__file__), "fonts") try: ps2tt("LiberationSerif") except ValueError: registerFont(TTFont("LiberationSerif", os.path.join(FONT_DIR, "LiberationSerif-Regular.ttf"))) registerFont(TTFont("LiberationSerif-Bold", os.path.join(FONT_DIR, "LiberationSerif-Bold.ttf"))) registerFont(TTFont("LiberationSerif-Italic", os.path.join(FONT_DIR, "LiberationSerif-Italic.ttf"))) registerFont(TTFont("LiberationSerif-BoldItalic", os.path.join(FONT_DIR, "LiberationSerif-BoldItalic.ttf"))) registerFontFamily( "LiberationSerif", normal="LiberationSerif", bold="LiberationSerif-Bold", italic="LiberationSerif-Italic", boldItalic="LiberationSerif-BoldItalic", ) styles = dict() styles["main"] = ParagraphStyle( "main", fontSize=10,
def start_font(self, attr): A = self.getAttributes(attr, _spanAttrMap) if 'fontName' in A: A['fontName'], A['bold'], A['italic'] = ps2tt(A['fontName']) self._push('font', **A)
parent=styles["il-citation-main-nt"], fontName="Times-Bold", fontSize=8, leading=10, ) styles["il-citation-instructions-nt"] = ParagraphStyle( "il-citation-instructions-nt", parent=styles["il-citation-main-nt"], fontName="Times-Bold", fontSize=9, leading=12) # END ILLINOIS CITATION REPORT # START ROCKDALE COURT REPORT try: ps2tt("Times-Roman") except ValueError: pdfmetrics.registerFont( TTFont("Times-Roman", os.path.join(os.getcwd(), "fonts", "times.ttf"))) pdfmetrics.registerFont( TTFont("Times-Bold", os.path.join(os.getcwd(), "fonts", "timesbd.ttf"))) pdfmetrics.registerFont( TTFont("Times-Italic", os.path.join(os.getcwd(), "fonts", "timesi.ttf"))) pdfmetrics.registerFont( TTFont("Times-BoldItalic", os.path.join(os.getcwd(), "fonts", "timesbi.ttf"))) pdfmetrics.registerFontFamily("Times-Roman", normal="Times-Roman", bold="Times-Bold",
def start_font(self,attr): A = self.getAttributes(attr,_spanAttrMap) if 'fontName' in A: A['fontName'], A['bold'], A['italic'] = ps2tt(A['fontName']) self._push('font',**A)
import common from common.reportlab_styles import extend_style, extend_table_style from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT from reportlab.lib.fonts import ps2tt from reportlab.lib.styles import ParagraphStyle from reportlab.pdfbase.pdfmetrics import registerFont, registerFontFamily from reportlab.pdfbase.ttfonts import TTFont from reportlab.platypus import TableStyle import os FONT_DIR = os.path.join(os.path.dirname(common.__file__), "fonts") try: ps2tt("LiberationSans") except ValueError: registerFont(TTFont("LiberationSans", os.path.join(FONT_DIR, "LiberationSans-Regular.ttf"))) registerFont(TTFont("LiberationSans-Bold", os.path.join(FONT_DIR, "LiberationSans-Bold.ttf"))) registerFont(TTFont("LiberationSans-Italic", os.path.join(FONT_DIR, "LiberationSans-Italic.ttf"))) registerFont(TTFont("LiberationSans-BoldItalic", os.path.join(FONT_DIR, "LiberationSans-BoldItalic.ttf"))) registerFontFamily( "LiberationSans", normal="LiberationSans", bold="LiberationSans-Bold", italic="LiberationSans-Italic", boldItalic="LiberationSans-BoldItalic", ) try: ps2tt("LiberationSansNarrow") except ValueError: registerFont(TTFont("LiberationSansNarrow", os.path.join(FONT_DIR, "LiberationSansNarrow-Regular.ttf")))
def start_font(self, attr): A = self.getAttributes(attr, _spanAttrMap) if "fontName" in A: A["fontName"], A["bold"], A["italic"] = ps2tt(A["fontName"]) self._push("font", **A)