[reportlab-users] WordCount in reportlab paragraph

Harald Armin Massa[legacy] haraldarminmassa at gmail.com
Fri Feb 27 06:10:41 EST 2009


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
if last or not nSpaces or abs(extraSpace)<=1e-8 or line.lineBreak:
_putFragLine(offset, tx, line) #no space modification
else:
#~ print "-"*20
#~ print "wordspace",line.extraSpace,nSpaces ,extraSpace /
float(nSpaces)
#~ print "'"*20
#~ print line
tx.setWordSpace(extraSpace / float(nSpaces))
_putFragLine(offset, tx, line)
tx.setWordSpace(0)
setXPos(tx,-offset)

which gave me the following debug output:

FragLine('lineBreak' False
[yadda yadda yadda]
'text'
'Abgrenzungen und Erweiterungen des'
[yadda yadda yadda]
'extraSpace'
76.078425196850333
'wordCount'
3
) #FragLine


As of documentation within the code:

class FragLine(ABag):
"""
class FragLine contains a styled line (ie a line with more than one
style)::

extraSpace unused space for justification only
* wordCount 1+spaces in line for justification purposes*

"""

Now I was curious: 'Abgrenzungen und Erweiterungen des'
are clearly FOUR words, and 3 Spaces. So 1+3 should be 4; and wordCount 3
(as there is no such concept as a "negative word" which could be further
down the FragLine)


Checking out some more FragLines, I discovered that wordCount allways was
"one less then counted by Harald"

So I removed that "-1" from _justifyDrawParaLineX and everything works
great. (or better, acceptable, as "4 words justified in a line" allways look
cruel)


My fix works; and using Hennings Wordaxe, splitting those words in Fragmens
it even looks fair.

BUT: is my fix correct? If yes, can it please be incorporated in RL 2.4 and
SVN Trunk?

best wishes,

HArald


--
GHUM Harald Massa
persuadere et programmare
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607
no fx, no carrier pigeon
-
EuroPython 2009 will take place in Birmingham - Stay tuned!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090227/8aad2bf8/attachment.html>


More information about the reportlab-users mailing list