[reportlab-users] Vertical table alignment change in ReportLab 3.5.44

Robin Becker robin at reportlab.com
Thu Dec 12 11:39:09 EST 2024


Hi Marius,

I think I found the problem cause using this code

if __name__=='__main__':
	import os
	from reportlab import Version as rlVersion
	from subprocess import check_output
	hgidnum = check_output(["hg", "id", "--num"]).decode('ascii').strip()
	from reportlab.pdfgen.canvas import Canvas
	from reportlab.lib.styles import ParagraphStyle
	from reportlab.platypus.paragraph import Paragraph
	from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY, TA_LEFT
	from reportlab.pdfbase.pdfmetrics import stringWidth
	sty = ParagraphStyle('normal',firstLineIndent=0,spaceBefore=6,fontSize=10,alignment=TA_LEFT)
	txt = os.environ.get('A','A')
	p = Paragraph(f'<font color="0xff0000">{txt}</font>', sty)
	slen = stringWidth(txt,sty.fontName,sty.fontSize)
	aW = float(os.environ.get('aW','4'))
	aH = 71994
	canv = Canvas('dummy.pdf')
	w, h = p.wrapOn(canv, aW, aH)
	print(f'reportlab.Version={rlVersion} hg id --num={hgidnum} len({txt=})={slen} p.wrapOn(canv,{aW=},{aH=}) --> {w=} {h=}')


It seems that your first column width was too small. In rev >= 4587 I see these results

> $ aW=6.67 python devel/tparah.py 
> reportlab.Version=3.5.43 hg id --num=4587 len(txt='A')=6.67 p.wrapOn(canv,aW=6.67,aH=71994) --> w=6.67 h=12

if we reduce the available width then the paragraph wants to wrap to the next line and gives a height that is too large

> $ aW=6.66 python devel/tparah.py 
> reportlab.Version=3.5.43 hg id --num=4587 len(txt='A')=6.67 p.wrapOn(canv,aW=6.66,aH=71994) --> w=6.66 h=24

we cannot split the single 'A' so it seems we have an issue with the reported height and the actual drawing.

Probably the Paragraph height computation needs looking at at least for this specific case where it seems the wrap 
height differs from the drawn height.
-- 
Robin Becker


More information about the reportlab-users mailing list