Bug 46489 - page-position="last" can cause an extra blank page.
Summary: page-position="last" can cause an extra blank page.
Status: CLOSED FIXED
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: page-master/layout (show other bugs)
Version: all
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-07 05:38 UTC by Chris Bowditch
Modified: 2012-04-01 06:35 UTC (History)
0 users



Attachments
Sample FO to reproduce bug (49.82 KB, application/octet-stream)
2009-01-07 05:38 UTC, Chris Bowditch
Details
modified sample; demonstrating the influence of tables (2.86 KB, text/plain)
2009-03-22 02:57 UTC, Andreas L. Delmelle
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Bowditch 2009-01-07 05:38:05 UTC
Created attachment 23092 [details]
Sample FO to reproduce bug

FO has been checked for obvious causes why blank page is added at the end of the document, i.e. not caused by space-after, break-* properties or force-page-count. Removing the fo:repeatable-page-master-alternatives element in favour of a single repeating page master avoids the blank page. Sample FO that reproduces the problem in trunk has been attached.
Comment 1 Andreas L. Delmelle 2009-03-22 02:20:45 UTC
Some initial observations:
The issue is again with the last page-master. Commenting out only that one, also produces the expected result. This time, it's the combination with the last break-before in the document. Another way to avoid the issue for the moment, is by moving that as a break-after to the last preceding block.
Comment 2 Andreas L. Delmelle 2009-03-22 02:57:24 UTC
Created attachment 23396 [details]
modified sample; demonstrating the influence of tables


If we remove tables from the picture, the issue disappears as well.
Comment 3 Andreas L. Delmelle 2009-03-22 04:16:03 UTC
Upon checking closer: the difference between the scenario with and without tables is that, without tables the break-before has already triggered addAreas() for the preceding parts. With tables, the forced break is included in the complete list, but is preceded by another penalty which seems to confuse things... The restartPoint is set to the point *between* the two penalties, so when we restart the algorithm for the last page, it will encounter the forced break too, as a first element, and produces two pages instead of only one.

I managed to hack the issue away locally by a adding a small check for this in PageBreaker.doPhase3WithLastPage():

...
            newStartPos = pbp.getLeafPos();
            /* hack to avoid producing an extra page after the last */
            if (((KnuthElement)effectiveList.get(newStartPos)).isForcedBreak()) {
                newStartPos++;
            }
...
Comment 4 Andreas L. Delmelle 2009-03-22 11:52:36 UTC
In the meantime, I tracked the origin of the superfluous penalty to BlockStackingLM.getNextKnuthElements() (line 350). Avoiding its creation and insertion into the result list does not solve the matter, although we might fare better in general if we only call addInBetweenBreak() in case the returnedList, whose elements will be appended after that call, does not itself already start with a forced break. (A similar thing happens in FlowLM, by the way...)

The real issue is that the restarting point is set to the index of the penalty representing the last page-break. Better put: the restarting point is always set to right *before* the last page-break, instead of the immediately *after*. 
No problem for a regular break-possibility, but this generates the side-effect of the extra page if the break was forced. 
Therefore, I'm thinking that the newStartPos variable in PageBreaker.doPhase3WithLastPage() should unconditionally be set to (pb.getLeafPos() + 1).
Comment 5 Andreas L. Delmelle 2009-03-22 12:22:55 UTC
(In reply to comment #4)
> Therefore, I'm thinking that the newStartPos variable in
> PageBreaker.doPhase3WithLastPage() should unconditionally be set to
> (pb.getLeafPos() + 1).

This has been committed with r757239.

Thanks for reporting!
Comment 6 Glenn Adams 2012-04-01 06:35:49 UTC
batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed