[reportlab-users] Understanding Wordwrap, esp. in tables

Robin Becker robin at reportlab.com
Wed Nov 14 10:04:02 EST 2007


Andrew Smart wrote:

>> what is left oriented wordwrapping are we talking bidi etc etc.

>

> "Left"-oriented wordwrapping:

> -----------------------

> This is a long sentence

> which has a left

> oriented word wrapping.

> -----------------------

>

> "Block"-oriented wordwrapping:

> -----------------------

> This is a long sentence

> Which has a left

> Oriented word wrapping.

> -----------------------

>

> The difference is how the left-over space is spent: between the

> words or at the end of the line.

>

>> Table cells know nothing about wrapping; they know about text

>> lines and flowables (but not simultaneously. Paragraphs just

>> about know how to break lines at spaces or at <br/> tags. We

>> don't split inside words and I don't think we do right to

>> left although others have done both.

>

> Ok, understood.

>

> Regards,

> Andrew

......

Paragraphs can do both the above. The attributes values in the styles are rather
old fashioned though.

from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY

I think the TA stands for "text align", but it's pretty stupid to have these
numeric constants rather than some sensible string values. If you set a
paragraphs style alignment attribute to one of these you'll get differing behaviour.

Again be aware that everything in python is by reference so if you do

sty=ParagraphStyle(......,alignment=TA_LEFT)
P0 = Paragraph('aaaa',style=sty)

sty.alignment=TA_RIGHT
P1=Paragraph('bbbbb',style=sty)

then it's highly likely both paragraphs will get right aligned since both have a
reference to the same style. Instead of re-use just make a new style with the
first as parent ie

sty = ParagraphStyle(parent=sty,.......,alignment=TA_RIGHT)

etc etc
--
Robin Becker


More information about the reportlab-users mailing list