[reportlab-users] cjk word wrapping does not work with <br/> ?

Yuan HOng hongyuan1306 at gmail.com
Thu May 21 03:02:38 EDT 2009


On Wed, May 20, 2009 at 5:10 PM, Robin Becker <robin at reportlab.com> wrote:


> Yuan HOng wrote:

> > I traced the bug to the function cjkFragSplit in module paragraph.py.

> >

> > Attached is my attempted patch, which seems to work. Please review.

> I'll try and take a look at this over the weekend, am very busy right now.

>


For your info, my patch has one problem. All lines broken by <br/> has a
space as the first character and are thus slightly indented to the right
than the first line.

By the way, the following code snippet in cjkFragSplit has modified the loop
variable 'i' as a last statement. This will however not have any effect upon
the loop when using enumerate. So something might be wrong.

for i, u in enumerate(U):
w = u.width
widthUsed += w
lineBreak = hasattr(u.frag,'lineBreak')
endLine = (widthUsed>maxWidth + _FUZZ and widthUsed>0) or lineBreak
if endLine:
if lineBreak: continue
extraSpace = maxWidth - widthUsed + w
#This is the most important of the Japanese typography rules.
#if next character cannot start a line, wrap it up to this line
so it hangs
#in the right margin. We won't do two or more though - that's
unlikely and
#would result in growing ugliness.
nextChar = U[i]
if nextChar in ALL_CANNOT_START:
extraSpace -= w
i += 1

lines.append(makeCJKParaLine(U[lineStartPos:i],extraSpace,calcBounds))
try:
maxWidth = maxWidths[len(lines)]
except IndexError:
maxWidth = maxWidths[-1] # use the last one

lineStartPos = i
widthUsed = w
i -= 1

--
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090521/4404b2e4/attachment.html>


More information about the reportlab-users mailing list