[reportlab-users] Release notes on the website

Marius Gedminas marius at gedmin.as
Thu May 21 07:39:36 EDT 2009

On Thu, May 14, 2009 at 08:25:48PM +0300, Marius Gedminas wrote:

> On Thu, May 14, 2009 at 04:34:04PM +0100, Andy Robinson wrote:

> > In any event, if upgrading I would recommend to go for the latest

> > release version (2.3).


> Unfortunately 2.2 changes vertical positioning of paragraphs in a way

> that breaks out reports. Compare:


> http://mg.pov.lt/reportlab/2.1/test-empty-pdr-0.png

> http://mg.pov.lt/reportlab/2.2/test-empty-pdr-0.png

> http://mg.pov.lt/reportlab/diff-2.1-vs-2.2/test-empty-pdr-0.png


> 2.3 produces the same output as 2.2. I haven't figured out yet whether

> the bug is in our code, or in ReportLab. The text that remains in the

> same position is drawn with


> canvas.drawString(x, y, "string")


> The large title text that is now shifted up is drawn with


> para = Paragraph("string", style)

> para.wrap(PAGE_WIDTH - x * 2, PAGE_HEIGHT)

> y -= para.height/2

> para.drawOn(canvas, x, y)


> The same vertical shift up happens everywhere Paragraphs are used, e.g.

> tables containing Paragraphs inside table cells (also visible in that

> image). It also happens to flowables added to the story, i.e. the first

> paragraph on every page is shifted up:


> http://mg.pov.lt/reportlab/2.1/test-empty-pdr-1.png

> http://mg.pov.lt/reportlab/2.2/test-empty-pdr-1.png

> http://mg.pov.lt/reportlab/diff-2.1-vs-2.2/test-empty-pdr-1.png

This is caused by the following change in Paragraph.drawPara between
ReportLab 2.1 and 2.2:

reportlab_2_1/reportlab/platypus/paragraph.py, line 993:

cur_y = self.height - f.fontSize

ReportLab_2_2/src/reportlab/platypus/paragraph.py, line 1276:

cur_y = self.height - getattr(f,'ascent',f.fontSize) #TODO fix XPreformatted to remove this hack

The font in question (Times New Roman) has fontSize=10 and ascent=6.83
(height=12) in one of our unit tests that I'm looking at now.

The change was made in r3192 by rgbecker with "fix simple paragraph
vertical position" as the commit message.

I'm in a bit of a quandary now. Is it the font metrics that are
incorrect, or is it the layout code? If you look at the table example


the vertical positioning is clearly incorrect: the bottom padding inside
the table cells should *not* be three times as large as the top padding.

The code that draws it does the following (slightly paraphrased):

normal_style = ParagraphStyle('normal')
normal_style.firstLineIndent = 0
normal_style.spaceBefore = 6
normal_style.fontName = 'Times_New_Roman'
normal_style.fontSize = 11.0
normal_style.alignment = TA_JUSTIFY

cell_style = ParagraphStyle('cell_text', parent=normal_style)
cell_style.alignment = TA_LEFT

table_style = TableStyle([
('GRID', (0, 0), (-1, -1), 0.25, colors.black),

rows = [[Paragraph(cgi.escape(value), cell_style) for value in row]
for row in data_rows]
table = Table(rows, style=table_style)

So, is the bug

(1) in the font metrics,

(2) in Table layout code,


(3) in Paragraph drawing code, i.e. the change made in r3192?

Marius Gedminas
In order to get a loan you must first prove you don't need it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090521/4bb7e9c9/attachment.pgp>

More information about the reportlab-users mailing list