[reportlab-users] WordCount in reportlab paragraph

Robin Becker robin at reportlab.com
Fri Feb 27 06:53:51 EST 2009


Harald Armin Massa[legacy] wrote:

> Hello,

>

> I am creating long insurance documents with reportlab. I use a

> 2-column-layout on DIN-A4, so the lines are rather shortish (<9cm)

>

> And, as it is Liability Insurance AND German language, it is rather layers

> talk with VERY long words.

>

> To add insult, those are expected to be justified. Many times it works. BUT

> ... then I had lines with only 4 words in them.

>

> 'Abgrenzungen und Erweiterungen des'

>

> and they "crossed the border", that is: they were drawn outside the Column.

>

>

> Tracking it down, I guessed the culprit withing: _justifyDrawParaLineX

> ofparagraph.py

>

> def _justifyDrawParaLineX( tx, offset, line, last=0):

> setXPos(tx,offset)

> extraSpace = line.extraSpace

> #~ nSpaces = line.wordCount - 1

> nSpaces = line.wordCount # This is my fix

........-

Harald, thanks for the report. Unfortunately I think the problem lies elsewhere

.......

When I run this script

from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate,
Indenter, SimpleDocTemplate
doc = SimpleDocTemplate('test_platypus_just.pdf')
doc.rightMargin=3*72
styleSheet = getSampleStyleSheet()
bt = styleSheet['BodyText']
btj = ParagraphStyle('bodyText1j',parent=bt,alignment=TA_JUSTIFY)
story=[Paragraph("""<a name='top'/>Subsequent pages test pageBreakBefore,
frameBreakBefore and
keepTogether attributes. Generated at 1111. The number in brackets
at the end of each paragraph is its position in the story.
llllllllllllllllllllllllll bbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccc
ddddddddddddddddddddd eeee""",btj)]
doc.build(story)


I see this output if I put a print line.wordCount in _justifyDrawParaLineX
C:\Tmp>tparajust.py
5
10
12
2
2


And the split then looks like

Subsequent pages test pageBreakBefore, frameBreakBefore and (6)

keepTogether attributes. Generated at 1111. The number in brackets at (10)

the end of each paragraph is its position in the story.
llllllllllllllllllllllllll (12)

bbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccc (2)
ddddddddddddddddddddd eeee (2)

so all the counts are right except the first. I suspect something in the break
is improperly incrementing the count (or not decrementing it). I'll take a look
today.
--
Robin Becker


More information about the reportlab-users mailing list