def start_index(self,attr): attr=self.getAttributes(attr,_indexAttrMap) defn = ABag() if 'item' in attr: label = attr['item'] else: self._syntax_error('<index> needs at least an item attribute') if 'name' in attr: name = attr['name'] else: name = DEFAULT_INDEX_NAME format = attr.get('format',None) if format is not None and format not in ('123','I','i','ABC','abc'): raise ValueError('index tag format is %r not valid 123 I i ABC or abc' % offset) offset = attr.get('offset',None) if offset is not None: try: offset = int(offset) except: raise ValueError('index tag offset is %r not an int' % offset) defn.label = encode_label([label,format,offset]) defn.name = name defn.kind='index' self._push(cbDefn=defn) self.handle_data('') self._pop()
def start_index(self, attr): attr = self.getAttributes(attr, _indexAttrMap) defn = ABag() if 'item' in attr: label = attr['item'] else: self._syntax_error('<index> needs at least an item attribute') if 'name' in attr: name = attr['name'] else: name = DEFAULT_INDEX_NAME format = attr.get('format', None) if format is not None and format not in ('123', 'I', 'i', 'ABC', 'abc'): raise ValueError( 'index tag format is %r not valid 123 I i ABC or abc' % offset) offset = attr.get('offset', None) if offset is not None: try: offset = int(offset) except: raise ValueError('index tag offset is %r not an int' % offset) defn.label = base64.encodestring(pickle.dumps( (label, format, offset))).strip() defn.name = name defn.kind = 'index' self._push(cbDefn=defn) self.handle_data('') self._pop()
def start_index(self, attr): attr = self.getAttributes(attr, _indexAttrMap) defn = ABag() if "item" in attr: label = attr["item"] else: self._syntax_error("<index> needs at least an item attribute") if "name" in attr: name = attr["name"] else: name = DEFAULT_INDEX_NAME format = attr.get("format", None) if format is not None and format not in ("123", "I", "i", "ABC", "abc"): raise ValueError("index tag format is %r not valid 123 I i ABC or abc" % offset) offset = attr.get("offset", None) if offset is not None: try: offset = int(offset) except: raise ValueError("index tag offset is %r not an int" % offset) defn.label = base64.encodestring(pickle.dumps((label, format, offset))).strip() defn.name = name defn.kind = "index" self._push(cbDefn=defn) self.handle_data("") self._pop()
def start_onDraw(self, attr): defn = ABag() if 'name' in attr: defn.name = attr['name'] else: self._syntax_error('<onDraw> needs at least a name attribute') if 'label' in attr: defn.label = attr['label'] defn.kind = 'onDraw' self._push(cbDefn=defn) self.handle_data('') self._pop()
def start_onDraw(self,attr): defn = ABag() if 'name' in attr: defn.name = attr['name'] else: self._syntax_error('<onDraw> needs at least a name attribute') if 'label' in attr: defn.label = attr['label'] defn.kind='onDraw' self._push(cbDefn=defn) self.handle_data('') self._pop()
def start_onDraw(self, attr): defn = ABag() if "name" in attr: defn.name = attr["name"] else: self._syntax_error("<onDraw> needs at least a name attribute") if "label" in attr: defn.label = attr["label"] defn.kind = "onDraw" self._push(cbDefn=defn) self.handle_data("") self._pop()
def end_img(self): frag = self._stack[-1] assert getattr(frag, '_selfClosingTag', ''), 'Parser failure in <img/>' defn = frag.cbDefn = ABag() defn.kind = 'img' defn.src = getattr(frag, 'src', None) defn.image = ImageReader(defn.src) size = defn.image.getSize() defn.width = getattr(frag, 'width', size[0]) defn.height = getattr(frag, 'height', size[1]) defn.valign = getattr(frag, 'valign', 'bottom') del frag._selfClosingTag self.handle_data('') self._pop()
def end_a(self): frag = self._stack[-1] sct = getattr(frag, '_selfClosingTag', '') if sct: assert sct == 'anchor' and frag.name, 'Parser failure in <a/>' defn = frag.cbDefn = ABag() defn.label = defn.kind = 'anchor' defn.name = frag.name del frag.name, frag._selfClosingTag self.handle_data('') self._pop() else: del self._stack[-1] assert frag.link != None
def end_a(self): frag = self._stack[-1] sct = getattr(frag, '_selfClosingTag', '') if sct: if not (sct == 'anchor' and frag.name): raise ValueError('Parser failure in <a/>') defn = frag.cbDefn = ABag() defn.label = defn.kind = 'anchor' defn.name = frag.name del frag.name, frag._selfClosingTag self.handle_data('') self._pop('a') else: if self._pop('a').link is None: raise ValueError('<link> has no href')
def drawPara(self, debug=0): """Draws a paragraph according to the given style. Returns the final y position at the bottom. Not safe for paragraphs without spaces e.g. Japanese; wrapping algorithm will go infinite.""" #stash the key facts locally for speed canvas = self.canv style = self.style blPara = self.blPara lines = blPara.lines #work out the origin for line 1 leftIndent = style.leftIndent cur_x = leftIndent if debug: bw = 0.5 bc = Color(1, 1, 0) bg = Color(0.9, 0.9, 0.9) else: bw = getattr(style, 'borderWidth', None) bc = getattr(style, 'borderColor', None) bg = style.backColor #if has a background or border, draw it if bg or (bc and bw): canvas.saveState() op = canvas.rect kwds = dict(fill=0, stroke=0) if bc and bw: canvas.setStrokeColor(bc) canvas.setLineWidth(bw) kwds['stroke'] = 1 br = getattr(style, 'borderRadius', 0) if br and not debug: op = canvas.roundRect kwds['radius'] = br if bg: canvas.setFillColor(bg) kwds['fill'] = 1 bp = getattr(style, 'borderPadding', 0) op(leftIndent - bp, -bp, self.width - (leftIndent + style.rightIndent) + 2 * bp, self.height + 2 * bp, **kwds) canvas.restoreState() nLines = len(lines) bulletText = self.bulletText if nLines > 0: _offsets = getattr(self, '_offsets', [0]) _offsets += (nLines - len(_offsets)) * [_offsets[-1]] canvas.saveState() #canvas.addLiteral('%% %s.drawPara' % _className(self)) alignment = style.alignment offset = style.firstLineIndent + _offsets[0] lim = nLines - 1 noJustifyLast = not (hasattr(self, '_JustifyLast') and self._JustifyLast) if blPara.kind == 0: if alignment == TA_LEFT: dpl = _leftDrawParaLine elif alignment == TA_CENTER: dpl = _centerDrawParaLine elif self.style.alignment == TA_RIGHT: dpl = _rightDrawParaLine elif self.style.alignment == TA_JUSTIFY: dpl = _justifyDrawParaLine f = blPara cur_y = self.height - f.fontSize if bulletText <> None: offset = _drawBullet(canvas, offset, cur_y, bulletText, style) #set up the font etc. canvas.setFillColor(f.textColor) tx = self.beginText(cur_x, cur_y) #now the font for the rest of the paragraph tx.setFont(f.fontName, f.fontSize, style.leading) ws = lines[0][0] t_off = dpl(tx, offset, ws, lines[0][1], noJustifyLast and nLines == 1) if f.underline or f.link or f.strike: xs = tx.XtraState = ABag() xs.cur_y = cur_y xs.f = f xs.style = style xs.lines = lines xs.underlines = [] xs.underlineColor = None xs.strikes = [] xs.strikeColor = None xs.links = [] xs.link = f.link canvas.setStrokeColor(f.textColor) dx = t_off + leftIndent if dpl != _justifyDrawParaLine: ws = 0 if f.underline: _do_under_line(0, dx, ws, tx) if f.strike: _do_under_line(0, dx, ws, tx, lm=0.125) if f.link: _do_link_line(0, dx, ws, tx) #now the middle of the paragraph, aligned with the left margin which is our origin. for i in xrange(1, nLines): ws = lines[i][0] t_off = dpl(tx, _offsets[i], ws, lines[i][1], noJustifyLast and i == lim) if dpl != _justifyDrawParaLine: ws = 0 if f.underline: _do_under_line(i, t_off + leftIndent, ws, tx) if f.strike: _do_under_line(i, t_off + leftIndent, tx, ws, lm=0.125) if f.link: _do_link_line(i, t_off + leftIndent, ws, tx) else: for i in xrange(1, nLines): dpl(tx, _offsets[i], lines[i][0], lines[i][1], noJustifyLast and i == lim) else: f = lines[0] cur_y = self.height - f.fontSize # default? dpl = _leftDrawParaLineX if bulletText <> None: offset = _drawBullet(canvas, offset, cur_y, bulletText, style) if alignment == TA_LEFT: dpl = _leftDrawParaLineX elif alignment == TA_CENTER: dpl = _centerDrawParaLineX elif self.style.alignment == TA_RIGHT: dpl = _rightDrawParaLineX elif self.style.alignment == TA_JUSTIFY: dpl = _justifyDrawParaLineX else: raise ValueError, "bad align %s" % repr(alignment) #set up the font etc. tx = self.beginText(cur_x, cur_y) xs = tx.XtraState = ABag() xs.textColor = None xs.rise = 0 xs.underline = 0 xs.underlines = [] xs.underlineColor = None xs.strike = 0 xs.strikes = [] xs.strikeColor = None xs.links = [] xs.link = None tx.setLeading(style.leading) xs.cur_y = cur_y xs.f = f xs.style = style tx._fontname, tx._fontsize = None, None t_off = dpl(tx, offset, lines[0], noJustifyLast and nLines == 1) _do_post_text(0, t_off + leftIndent, tx) #now the middle of the paragraph, aligned with the left margin which is our origin. for i in range(1, nLines): f = lines[i] t_off = dpl(tx, _offsets[i], f, noJustifyLast and i == lim) _do_post_text(i, t_off + leftIndent, tx) canvas.drawText(tx) canvas.restoreState()
def test0(self): """Test... The story should contain... Features to be visually confirmed by a human being are: 1. ... 2. ... 3. ... """ story = [] SA = story.append #need a style styNormal = ParagraphStyle('normal') styGreen = ParagraphStyle('green',parent=styNormal,textColor=green) styDots = ParagraphStyle('styDots',parent=styNormal,endDots='.') styDots1 = ParagraphStyle('styDots1',parent=styNormal,endDots=ABag(text=' -',dy=2,textColor='red')) styDotsR = ParagraphStyle('styDotsR',parent=styNormal,alignment=TA_RIGHT,endDots=' +') styDotsC = ParagraphStyle('styDotsC',parent=styNormal,alignment=TA_CENTER,endDots=' *') styDotsJ = ParagraphStyle('styDotsJ',parent=styNormal,alignment=TA_JUSTIFY,endDots=' =') istyDots = ParagraphStyle('istyDots',parent=styNormal,firstLineIndent=12,leftIndent=6,endDots='.') istyDots1 = ParagraphStyle('istyDots1',parent=styNormal,firstLineIndent=12,leftIndent=6,endDots=ABag(text=' -',dy=2,textColor='red')) istyDotsR = ParagraphStyle('istyDotsR',parent=styNormal,firstLineIndent=12,leftIndent=6,alignment=TA_RIGHT,endDots=' +') istyDotsC = ParagraphStyle('istyDotsC',parent=styNormal,firstLineIndent=12,leftIndent=6,alignment=TA_CENTER,endDots=' *') istyDotsJ = ParagraphStyle('istyDotsJ',parent=styNormal,firstLineIndent=12,leftIndent=6,alignment=TA_JUSTIFY,endDots=' =') # some to test stySpaced = ParagraphStyle('spaced', parent=styNormal, spaceBefore=12, spaceAfter=12) SA(Paragraph("This is a normal paragraph. "+ randomText(), styNormal)) SA(Paragraph("There follows a paragraph with only \"<br/>\"", styNormal)) SA(Paragraph("<br/>", styNormal)) SA(Paragraph("This has 12 points space before and after, set in the style. " + randomText(), stySpaced)) SA(Paragraph("This is normal. " + randomText(), styNormal)) SA(Paragraph("""<para spacebefore="12" spaceafter="12"> This has 12 points space before and after, set inline with XML tag. It works too.""" + randomText() + "</para", styNormal)) SA(Paragraph("This is normal. " + randomText(), styNormal)) styBackground = ParagraphStyle('MyTitle', fontName='Helvetica-Bold', fontSize=24, leading=28, textColor=white, backColor=navy) SA(Paragraph("This is a title with a background. ", styBackground)) SA(Paragraph("""<para backcolor="pink">This got a background from the para tag</para>""", styNormal)) SA(Paragraph("""<para>\n\tThis has newlines and tabs on the front but inside the para tag</para>""", styNormal)) SA(Paragraph("""<para> This has spaces on the front but inside the para tag</para>""", styNormal)) SA(Paragraph("""\n\tThis has newlines and tabs on the front but no para tag""", styNormal)) SA(Paragraph(""" This has spaces on the front but no para tag""", styNormal)) SA(Paragraph("""This has <font color=blue>blue text</font> here.""", styNormal)) SA(Paragraph("""This has <i>italic text</i> here.""", styNormal)) SA(Paragraph("""This has <b>bold text</b> here.""", styNormal)) SA(Paragraph("""This has <u>underlined text</u> here.""", styNormal)) SA(Paragraph("""This has <font color=blue><u>blue and <font color=red>red</font> underlined text</u></font> here.""", styNormal)) SA(Paragraph("""<u>green underlining</u>""", styGreen)) SA(Paragraph("""<u>green <font size=+4><i>underlining</font></i></u>""", styGreen)) SA(Paragraph("""This has m<super>2</super> a superscript.""", styNormal)) SA(Paragraph("""This has m<sub>2</sub> a subscript. Like H<sub>2</sub>O!""", styNormal)) SA(Paragraph("""This has a font change to <font name=Helvetica>Helvetica</font>.""", styNormal)) #This one fails: #SA(Paragraph("""This has a font change to <font name=Helvetica-Oblique>Helvetica-Oblique</font>.""", styNormal)) SA(Paragraph("""This has a font change to <font name=Helvetica><i>Helvetica in italics</i></font>.""", styNormal)) SA(Paragraph('''This one uses upper case tags and has set caseSensitive=0: Here comes <FONT FACE="Helvetica" SIZE="14pt">Helvetica 14</FONT> with <STRONG>strong</STRONG> <EM>emphasis</EM>.''', styNormal, caseSensitive=0)) SA(Paragraph('''The same as before, but has set not set caseSensitive, thus the tags are ignored: Here comes <FONT FACE="Helvetica" SIZE="14pt">Helvetica 14</FONT> with <STRONG>strong</STRONG> <EM>emphasis</EM>.''', styNormal)) SA(Paragraph('''This one uses fonts with size "14pt" and also uses the em and strong tags: Here comes <font face="Helvetica" size="14pt">Helvetica 14</font> with <Strong>strong</Strong> <em>emphasis</em>.''', styNormal, caseSensitive=0)) SA(Paragraph('''This uses a font size of 3cm: Here comes <font face="Courier" size="3cm">Courier 3cm</font> and normal again.''', styNormal, caseSensitive=0)) SA(Paragraph('''This is just a very long silly text to see if the <FONT face="Courier">caseSensitive</FONT> flag also works if the paragraph is <EM>very</EM> long. '''*20, styNormal, caseSensitive=0)) SA(Paragraph('''Simple paragraph with dots''', styDots)) SA(Paragraph('''Simple indented paragraph with dots''', istyDots)) SA(Paragraph('''Simple centred paragraph with stars''', styDotsC)) SA(Paragraph('''Simple centred indented paragraph with stars''', istyDotsC)) SA(Paragraph('''Simple right justified paragraph with pluses, but no pluses''', styDotsR)) SA(Paragraph('''Simple right justified indented paragraph with pluses, but no pluses''', istyDotsR)) SA(Paragraph('''Simple justified paragraph with equals''', styDotsJ)) SA(Paragraph('''Simple justified indented paragraph with equals''', istyDotsJ)) SA(Paragraph('''A longer simple paragraph with dots''', styDots)) SA(Paragraph('''A longer simple indented paragraph with dots''', istyDots)) SA(Paragraph('A very much' +50*' longer'+' simple paragraph with dots', styDots)) SA(Paragraph('A very much' +50*' longer'+' simple indented paragraph with dots', istyDots)) SA(Paragraph('A very much' +50*' longer'+' centred simple paragraph with stars', styDotsC)) SA(Paragraph('A very much' +50*' longer'+' centred simple indented paragraph with stars', istyDotsC)) SA(Paragraph('A very much' +50*' longer'+' right justified simple paragraph with pluses, but no pluses', styDotsR)) SA(Paragraph('A very much' +50*' longer'+' right justified simple indented paragraph with pluses, but no pluses', istyDotsR)) SA(Paragraph('A very much' +50*' longer'+' justified simple paragraph with equals', styDotsJ)) SA(Paragraph('A very much' +50*' longer'+' justified simple indented paragraph with equals', istyDotsJ)) SA(Paragraph('''Simple paragraph with dashes that have a dy and a textColor.''', styDots1)) SA(Paragraph('''Simple indented paragraph with dashes that have a dy and a textColor.''', istyDots1)) SA(Paragraph('''Complex <font color="green">paragraph</font> with dots''', styDots)) SA(Paragraph('''Complex <font color="green">indented paragraph</font> with dots''', istyDots)) SA(Paragraph('''Complex centred <font color="green">paragraph</font> with stars''', styDotsC)) SA(Paragraph('''Complex centred <font color="green">indented paragraph</font> with stars''', istyDotsC)) SA(Paragraph('''Complex right justfied <font color="green">paragraph</font> with pluses, but no pluses''', styDotsR)) SA(Paragraph('''Complex right justfied <font color="green">indented paragraph</font> with pluses, but no pluses''', istyDotsR)) SA(Paragraph('''Complex justfied <font color="green">paragraph</font> with equals''', styDotsJ)) SA(Paragraph('''Complex justfied <font color="green">indented paragraph</font> with equals''', istyDotsJ)) SA(Paragraph('''A longer complex <font color="green">paragraph</font> with dots''', styDots)) SA(Paragraph('''A longer complex <font color="green">indented paragraph</font> with dots''', istyDots)) SA(Paragraph('A very much' +50*' longer'+' complex <font color="green">paragraph</font> with dots', styDots)) SA(Paragraph('A very much' +50*' longer'+' complex <font color="green">indented paragraph</font> with dots', istyDots)) SA(Paragraph('''Complex <font color="green">paragraph</font> with dashes that have a dy and a textColor.''', styDots1)) SA(Paragraph('''Complex <font color="green">indented paragraph</font> with dashes that have a dy and a textColor.''', istyDots1)) SA(Paragraph('A very much' +50*' longer'+' centred complex <font color="green">paragraph</font> with stars', styDotsC)) SA(Paragraph('A very much' +50*' longer'+' centred complex <font color="green">indented paragraph</font> with stars', istyDotsC)) SA(Paragraph('A very much' +50*' longer'+' right justified <font color="green">complex</font> paragraph with pluses, but no pluses', styDotsR)) SA(Paragraph('A very much' +50*' longer'+' right justified <font color="green">complex</font> indented paragraph with pluses, but no pluses', istyDotsR)) SA(Paragraph('A very much' +50*' longer'+' justified complex <font color="green">paragraph</font> with equals', styDotsJ)) SA(Paragraph('A very much' +50*' longer'+' justified complex <font color="green">indented paragraph</font> with equals', istyDotsJ)) SA(Indenter("1cm")) SA(Paragraph("<para><bullet bulletIndent='-1cm' bulletOffsetY='2'><seq id='s0'/>)</bullet>Indented list bulletOffsetY=2. %s</para>" % randomText(), styNormal)) SA(Paragraph("<para><bullet bulletIndent='-1cm'><seq id='s0'/>)</bullet>Indented list. %s</para>" % randomText(), styNormal)) SA(Paragraph("<para><bullet bulletIndent='-1cm'><seq id='s0'/>)</bullet>Indented list. %s</para>" % randomText(), styNormal)) SA(Indenter("1cm")) SA(XPreformatted("<para leftIndent='0.5cm' backcolor=pink><bullet bulletIndent='-1cm'><seq id='s1'/>)</bullet>Indented list.</para>", styNormal)) SA(XPreformatted("<para leftIndent='0.5cm' backcolor=palegreen><bullet bulletIndent='-1cm'><seq id='s1'/>)</bullet>Indented list.</para>", styNormal)) SA(Indenter("-1cm")) SA(Paragraph("<para><bullet bulletIndent='-1cm'><seq id='s0'/>)</bullet>Indented list. %s</para>" % randomText(), styNormal)) SA(Indenter("-1cm")) SA(Paragraph("<para>Indented list using seqChain/Format<seqChain order='s0 s1 s2 s3 s4'/><seqReset id='s0'/><seqFormat id='s0' value='1'/><seqFormat id='s1' value='a'/><seqFormat id='s2' value='i'/><seqFormat id='s3' value='A'/><seqFormat id='s4' value='I'/></para>", stySpaced)) SA(Indenter("1cm")) SA(Paragraph("<para><bullet bulletIndent='-1cm'><seq id='s0'/>)</bullet>Indented list. %s</para>" % randomText(), styNormal)) SA(Paragraph("<para><bullet bulletIndent='-1cm'><seq id='s0'/>)</bullet>Indented list. %s</para>" % randomText(), styNormal)) SA(Paragraph("<para><bullet bulletIndent='-1cm'><seq id='s0'/>)</bullet>Indented list. %s</para>" % randomText(), styNormal)) SA(Indenter("1cm")) SA(XPreformatted("<para backcolor=pink boffsety='-3'><bullet bulletIndent='-1cm'><seq id='s1'/>)</bullet>Indented list bulletOffsetY=-3.</para>", styNormal)) SA(XPreformatted("<para backcolor=pink><bullet bulletIndent='-1cm'><seq id='s1'/>)</bullet>Indented list.</para>", styNormal)) SA(Indenter("-1cm")) SA(Paragraph("<para><bullet bulletIndent='-1cm'><seq id='s0'/>)</bullet>Indented list. %s</para>" % randomText(), styNormal)) SA(Indenter("1cm")) SA(XPreformatted("<para backcolor=palegreen><bullet bulletIndent='-1cm'><seq id='s1'/>)</bullet>Indented list.</para>", styNormal)) SA(Indenter("1cm")) SA(XPreformatted("<para><bullet bulletIndent='-1cm'><seq id='s2'/>)</bullet>Indented list. line1</para>", styNormal)) SA(XPreformatted("<para><bullet bulletIndent='-1cm'><seq id='s2'/>)</bullet>Indented list. line2</para>", styNormal)) SA(Indenter("-1cm")) SA(XPreformatted("<para backcolor=palegreen><bullet bulletIndent='-1cm'><seq id='s1'/>)</bullet>Indented list.</para>", styNormal)) SA(Indenter("-1cm")) SA(Indenter("-1cm")) template = SimpleDocTemplate(outputfile('test_paragraphs.pdf'), showBoundary=1) template.build(story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)
def drawPara(self, debug=0): """Draws a paragraph according to the given style. Returns the final y position at the bottom. Not safe for paragraphs without spaces e.g. Japanese; wrapping algorithm will go infinite.""" #stash the key facts locally for speed canvas = self.canv style = self.style blPara = self.blPara lines = blPara.lines leading = style.leading autoLeading = getattr(self, 'autoLeading', getattr(style, 'autoLeading', '')) #work out the origin for line 1 leftIndent = style.leftIndent cur_x = leftIndent if debug: bw = 0.5 bc = Color(1, 1, 0) bg = Color(0.9, 0.9, 0.9) else: bw = getattr(style, 'borderWidth', None) bc = getattr(style, 'borderColor', None) bg = style.backColor #if has a background or border, draw it if bg or (bc and bw): canvas.saveState() op = canvas.rect kwds = dict(fill=0, stroke=0) if bc and bw: canvas.setStrokeColor(bc) canvas.setLineWidth(bw) kwds['stroke'] = 1 br = getattr(style, 'borderRadius', 0) if br and not debug: op = canvas.roundRect kwds['radius'] = br if bg: canvas.setFillColor(bg) kwds['fill'] = 1 bp = getattr(style, 'borderPadding', 0) tbp, rbp, bbp, lbp = normalizeTRBL(bp) op(leftIndent - lbp, -bbp, self.width - (leftIndent + style.rightIndent) + lbp + rbp, self.height + tbp + bbp, **kwds) canvas.restoreState() nLines = len(lines) bulletText = self.bulletText if nLines > 0: _offsets = getattr(self, '_offsets', [0]) _offsets += (nLines - len(_offsets)) * [_offsets[-1]] canvas.saveState() #canvas.addLiteral('%% %s.drawPara' % _className(self)) alignment = style.alignment offset = style.firstLineIndent + _offsets[0] lim = nLines - 1 noJustifyLast = not (hasattr(self, '_JustifyLast') and self._JustifyLast) if blPara.kind == 0: if alignment == TA_LEFT: dpl = _leftDrawParaLine elif alignment == TA_CENTER: dpl = _centerDrawParaLine elif self.style.alignment == TA_RIGHT: dpl = _rightDrawParaLine elif self.style.alignment == TA_JUSTIFY: dpl = _justifyDrawParaLine f = blPara if rl_config.paraFontSizeHeightOffset: cur_y = self.height - f.fontSize else: cur_y = self.height - getattr(f, 'ascent', f.fontSize) if bulletText: offset = _drawBullet(canvas, offset, cur_y, bulletText, style) #set up the font etc. canvas.setFillColor(f.textColor) tx = self.beginText(cur_x, cur_y) if autoLeading == 'max': leading = max(leading, blPara.ascent - blPara.descent) elif autoLeading == 'min': leading = blPara.ascent - blPara.descent #now the font for the rest of the paragraph #----------------------DAVID ADDDED THESE LINES------------------------ if not self.firstLineSpace is None: tx.setFont(f.fontName, f.fontSize, leading + self.firstLineSpace) else: tx.setFont(f.fontName, f.fontSize, leading) #---------------------------------------------------------------------- ws = lines[0][0] t_off = dpl(tx, offset, ws, lines[0][1], noJustifyLast and nLines == 1) #----------------------DAVID ADDDED THESE LINES------------------------ tx.setFont(f.fontName, f.fontSize, leading) #---------------------------------------------------------------------- if f.underline or f.link or f.strike or style.endDots: xs = tx.XtraState = ABag() xs.cur_y = cur_y xs.f = f xs.style = style xs.lines = lines xs.underlines = [] xs.underlineColor = None xs.strikes = [] xs.strikeColor = None xs.links = [] xs.link = f.link xs.textColor = f.textColor xs.backColors = [] canvas.setStrokeColor(f.textColor) dx = t_off + leftIndent if dpl != _justifyDrawParaLine: ws = 0 underline = f.underline or (f.link and platypus_link_underline) strike = f.strike link = f.link if underline: _do_under_line(0, dx, ws, tx) if strike: _do_under_line(0, dx, ws, tx, lm=0.125) if link: _do_link_line(0, dx, ws, tx) if noJustifyLast and nLines == 1 and style.endDots and dpl != _rightDrawParaLine: _do_dots(0, dx, ws, xs, tx, dpl) #now the middle of the paragraph, aligned with the left margin which is our origin. for i in xrange(1, nLines): ws = lines[i][0] t_off = dpl(tx, _offsets[i], ws, lines[i][1], noJustifyLast and i == lim) dx = t_off + leftIndent if dpl != _justifyDrawParaLine: ws = 0 if underline: _do_under_line(i, dx, ws, tx) if strike: _do_under_line(i, dx, ws, tx, lm=0.125) if link: _do_link_line(i, dx, ws, tx) if noJustifyLast and i == lim and style.endDots and dpl != _rightDrawParaLine: _do_dots(i, dx, ws, xs, tx, dpl) else: for i in xrange(1, nLines): dpl(tx, _offsets[i], lines[i][0], lines[i][1], noJustifyLast and i == lim) else: f = lines[0] if rl_config.paraFontSizeHeightOffset: cur_y = self.height - f.fontSize else: cur_y = self.height - getattr(f, 'ascent', f.fontSize) # default? dpl = _leftDrawParaLineX if bulletText: oo = offset offset = _drawBullet(canvas, offset, cur_y, bulletText, style) if alignment == TA_LEFT: dpl = _leftDrawParaLineX elif alignment == TA_CENTER: dpl = _centerDrawParaLineX elif self.style.alignment == TA_RIGHT: dpl = _rightDrawParaLineX elif self.style.alignment == TA_JUSTIFY: dpl = _justifyDrawParaLineX else: raise ValueError("bad align %s" % repr(alignment)) #set up the font etc. tx = self.beginText(cur_x, cur_y) xs = tx.XtraState = ABag() xs.textColor = None xs.backColor = None xs.rise = 0 xs.underline = 0 xs.underlines = [] xs.underlineColor = None xs.strike = 0 xs.strikes = [] xs.strikeColor = None xs.backColors = [] xs.links = [] xs.link = None #----------------------DAVID ADDDED THESE LINES------------------------ if not self.firstLineSpace is None: xs.leading = style.leading + self.firstLineSpace else: xs.leading = style.leading #---------------------------------------------------------------------- xs.leftIndent = leftIndent tx._leading = None tx._olb = None xs.cur_y = cur_y xs.f = f xs.style = style xs.autoLeading = autoLeading tx._fontname, tx._fontsize = None, None dpl(tx, offset, lines[0], noJustifyLast and nLines == 1) _do_post_text(tx) #----------------------DAVID ADDDED THESE LINES------------------------ xs.leading = style.leading #---------------------------------------------------------------------- #now the middle of the paragraph, aligned with the left margin which is our origin. for i in xrange(1, nLines): f = lines[i] dpl(tx, _offsets[i], f, noJustifyLast and i == lim) _do_post_text(tx) canvas.drawText(tx) canvas.restoreState()