#26 wordaxe's Paragraph.split() works different

closed-fixed
nobody
None
5
2009-09-20
2009-08-31
No

Consider this sample program:

p1 = Paragraph('This is a paragraph\n'*10, styles['Normal'])
print len(p1.split(200,100))

If this is reportlab's paragraph class, the output is 2.
With wordaxe's paragraph class, the output is 0 because split() alwys returns []

This is a rather small problem for me, because it only hurts rst2pdf when there are list items which contain a paragraph that is longer than a page, but I am curious ;-)

Discussion

  • H. von Bargen

    H. von Bargen - 2009-09-01

    See the source for the split method in NewParagraph.py:
    avail = self._cache.get('avail')
    if avail is None or avail is not True and (
    availWidth < avail[0] or availHeight < avail[1]):
    # This can only happen when split has been called
    # without a previous wrap for this Paragraph.
    # From looking at doctemplate.py and frames.py,
    # I assume this is only the case if the free space
    # in the frame is not even enough for getSpaceBefore.
    # Thus we can safely return []

    #print "split without previous wrap"
    return []

    As a workaround, you can call wrap before split.

     
  • Roberto Alsina

    Roberto Alsina - 2009-09-01

    ok, will do.

     
  • Roberto Alsina

    Roberto Alsina - 2009-09-02

    wrap() didn't make any difference.
    I am now debugging into wordaxe, and here's a funny bit.

    Here's what avail contains when I get to split() this paragraph:

    >>> avail
    (443.88976377952741, 268435455)

    Of course, availHeight is smaller than 58.8426485 miles (thanks google ;-)

    Now, I will try to figure out how avail got that way. While this is a very long paragraph, because I am testing corner cases (it's a list item that's over a page long), it's not THAT long.

     
  • Roberto Alsina

    Roberto Alsina - 2009-09-02

    Found it, it's because I am using _listWrapOn on a list of flowables to find the height they require.
    Full test program here: http://pastebin.ca/1551494

     
  • Roberto Alsina

    Roberto Alsina - 2009-09-02

    Here's some more info:

    If you wrap(w,h1) and then split(w,h2) where h2<h1 split() will return [], even if the paragraph fits inside both h1 and h2!

    For example:

    p1 = Paragraph('This is a paragraph', style )
    print p1.wrap(500,701)
    print p1._cache['avail']
    print len(p1.split(500,701))
    print len(p1.split(500,700))

    Prints this:

    (500, 12)
    (500, 701)
    1
    0

     
  • H. von Bargen

    H. von Bargen - 2009-09-02

    I just found the same:
    I think it's this line:
    if avail is None or avail is not True and (
    availWidth < avail[0] or availHeight < avail[1]):

    This code comes from a patch from Christoph Zwerschke.
    I have to admit that I didn't understand it then and I still don't...
    Right now I have no clue how to fix it - maybe Christoph can help?

     
  • H. von Bargen

    H. von Bargen - 2009-09-02

    Please take a look at revision 91. However, it's more or less untested.

     
  • Christoph Zwerschke

    The "if avail is None ..." just checked whether wrap has been called. I have now checked in a much simpler solution in r93. This will also work if wrap() has not been called, like Henning's fix r91, but much simpler.

     
  • Roberto Alsina

    Roberto Alsina - 2009-09-03

    Looks fixed in r94.

     
  • Roberto Alsina

    Roberto Alsina - 2009-09-03

    I still have a related problem.

    It seems that some state is kept in the flowable, and wrapping it more than once causes this:

    File "/usr/lib/python2.6/site-packages/wordaxe/rl/NewParagraph.py", line 527, in wrap
    return self.i_wrap(availW, availH, max_widths)
    File "/usr/lib/python2.6/site-packages/wordaxe/rl/NewParagraph.py", line 668, in i_wrap
    assert lines

    I can try to create another test program, but not until monday.

     
  • Christoph Zwerschke

    Yes, I also noticed problems with the latest fix, obviously caused by the auto wrapping when multi builds are used. I will need to check this more thoroughly and create another test so we can solve this properly.

    So please keep this issue open. I will try to work on this next week.

     
  • Christoph Zwerschke

    Just checked in a test case (test_multibuild3) using rst2pdf that fails with the latest fix r93, but works with the fixes r91 and r92. This will help creating a proper fix - I will work on this later this weekend.

     
  • Christoph Zwerschke

    Improved the last fix in r96 so that est_multibuild3 works again. The original problem has been solved as well. I think we can close this now.

     
  • Christoph Zwerschke

    • status: open --> open-fixed
     
  • H. von Bargen

    H. von Bargen - 2009-09-20
    • status: open-fixed --> closed-fixed
     
  • H. von Bargen

    H. von Bargen - 2009-09-20

    I added an additional test case where the paragraph splits with the second frame being narrower than the first one.
    I'll close this bug as fixed now.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks