Discussion:
[reportlab-users] Understanding Wordwrap, esp. in tables
Andrew Smart
2007-11-14 13:32:07 UTC
Permalink
Hi,

I'm trying to understand word wrapping in Platypus, especially the behaviour
inside tables.

I've a quite simple table which alings the text "left". The word wrapping
seems to try to fill out the whole line, which is commonly adressed as
"block" formatting where spaces are inserted between the words to fill up
the whole line.

I would like to use a "left" oriented word wrapping. The style parameter
"wordWrap" doesn't know anything other than 'CFK' if I look at the source:

if self.style.wordWrap == 'CJK':
#use Asian text wrap algorithm to break characters
self.blPara = self.breakLinesCJK([first_line_width,
later_widths])
else:
self.blPara = self.breakLines([first_line_width, later_widths])

Do I have to implement a left-oriented word wrapping routine by myself or is
any other option avaiable?

If so, anyone interested into the final code?

Regards,
Andrew
Andrew Smart
2007-11-14 13:49:02 UTC
Permalink
After playing around a bit with the word wrapping I see a quite erratic
behaviour
for the wrapping, and I remembered that the calculation of table widths may
be
Influenced by the wrapping and vica versa.

I changed the table width from "automatic" into a fixed width. Now the
overall
word wrap behaviour is more deterministic, but still tends to "block" word
wrapping.

I can help myself with adding "- " at the corresponding text parts, but the
basic
question is still open: is a left-oriented word wrapping possible?

Regards,
Andrew
Robin Becker
2007-11-14 14:09:46 UTC
Permalink
Post by Andrew Smart
Hi,
I'm trying to understand word wrapping in Platypus, especially the behaviour
inside tables.
I've a quite simple table which alings the text "left". The word wrapping
seems to try to fill out the whole line, which is commonly adressed as
"block" formatting where spaces are inserted between the words to fill up
the whole line.
I would like to use a "left" oriented word wrapping. The style parameter
#use Asian text wrap algorithm to break characters
self.blPara = self.breakLinesCJK([first_line_width,
later_widths])
self.blPara = self.breakLines([first_line_width, later_widths])
Do I have to implement a left-oriented word wrapping routine by myself or is
any other option avaiable?
........
what is left oriented wordwrapping are we talking bidi etc etc.

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.
--
Robin Becker
Andrew Smart
2007-11-14 14:39:17 UTC
Permalink
Post by Robin Becker
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.
Post by Robin Becker
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
Robin Becker
2007-11-14 15:04:02 UTC
Permalink
Post by Andrew Smart
Post by Robin Becker
what is left oriented wordwrapping are we talking bidi etc etc.
-----------------------
This is a long sentence
which has a left
oriented word wrapping.
-----------------------
-----------------------
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.
Post by Robin Becker
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
Andrew Smart
2007-11-14 17:25:05 UTC
Permalink
Von: reportlab-users-bounces at reportlab.com
[mailto:reportlab-users-bounces at reportlab.com] Im Auftrag von
Robin Becker
Gesendet: Mittwoch, 14. November 2007 16:04
An: Support list for users of Reportlab software
Betreff: Re: [reportlab-users] Understanding Wordwrap, esp. in tables
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
Hmmm... I think this was the right pointer. I do a Table() call
with a sequence of sequences which are a mix of unicode strings
and paragraphs.

To be able to use TA_LEFT I'll have to convert the relevant
strings to Paragraphs with a corresponding style.
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)
Thanks for the hint. I'm already having a good set of partly independent
style objects, so this kind of error won't happen.

Thanks!

Andrew
Robin Becker
2007-11-14 18:17:05 UTC
Permalink
...... TA_RIGHT, TA_CENTER,
Post by Robin Becker
TA_JUSTIFY
Hmmm... I think this was the right pointer. I do a Table() call
with a sequence of sequences which are a mix of unicode strings
and paragraphs.
To be able to use TA_LEFT I'll have to convert the relevant
strings to Paragraphs with a corresponding style.
......
yes we allow a list of flowable type objects or strings/unicode as cell values.

Using flowables which have ill defined width eg tables/paragraphs makes the
automatic width feature go fairly daft. Unfortunately we don't have any idea of
soft widths.
--
Robin Becker
Loading...