Bug 40798 - page-position="last" doesn't work for 1 page document
page-position="last" doesn't work for 1 page document
Status: CLOSED FIXED
Product: Fop - Now in Jira
Classification: Unclassified
Component: page-master/layout
0.92
Other Windows 2000
: P2 major
: ---
Assigned To: fop-dev
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2006-10-19 05:46 UTC by Michael V
Modified: 2012-04-01 06:47 UTC (History)
1 user (show)



Attachments
Test whether a 'first' page can also be a 'last' page (3.92 KB, text/plain)
2008-07-08 14:02 UTC, Dave Gerdt
Details
Changes necessary to implement page-position="last" (3.19 KB, patch)
2008-09-20 06:40 UTC, Andreas L. Delmelle
Details | Diff
Path including a bit more refactoring (14.65 KB, patch)
2008-09-20 10:47 UTC, Andreas L. Delmelle
Details | Diff
Same as the previous, but with two added testcases (27.73 KB, patch)
2008-09-21 03:09 UTC, Andreas L. Delmelle
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael V 2006-10-19 05:46:18 UTC
I have two page-masters defined, with one having a different footer than the 
other.

When this renders to a 2+ page document, the last page gets the last footer 
and the other pages get the other footer.

When it renders to a 1 page document, I get the "any" page footer, even though 
the the page is the last page....

I've posted on nabble.com, and gotten replies that it is possibly a bug.

This is used to create business forms (like an order), so the total number of 
pages is unknown. The last footer is used to display a Sub-Total, Tax and 
Grand Total.

Snippet of the code:

<fo:layout-master-set> 
  <fo:simple-page-master master-name="default-page" 
                         page-height="11in" 
                         page-width="8.50in" 
                         margin-top="0.25in" 
                         margin-left="0.25in" 
                         margin-right="0.25in" 
                         margin-bottom="0.25in"> 
<!-- space needed for header & footer tables --> 
  <fo:region-body           
   region-name="body" 
   margin-top="0in" 
                         margin-bottom="1.50in"/> 
  <fo:region-before region-name="header" extent="10.0in"/> <!-- space needed 
for header table --> 
  <fo:region-after region-name="footer" extent="1.50in"/> <!-- space needed 
for footer table --> 
  <fo:region-start  extent="0.00in"/> 
  <fo:region-end    extent="0.00in"/> 
  </fo:simple-page-master> 
  
  
  <fo:simple-page-master master-name="last-page" 
   page-height="11in" 
   page-width="8.50in" 
   margin-top="0.25in" 
   margin-left="0.25in" 
   margin-right="0.25in" 
   margin-bottom="0.25in"> 
   <!-- space needed for header & footer tables --> 
   <fo:region-body           
    region-name="body" 
    margin-top="0in" 
    margin-bottom="1.50in"/> 
   <fo:region-before region-name="header" extent="10.0in"/> <!-- space needed 
for header table --> 
   <fo:region-after  region-name="last-footer" extent="1.50in"/> <!-- space 
needed for footer table --> 
   <fo:region-start  extent="0.00in"/> 
   <fo:region-end    extent="0.00in"/> 
  </fo:simple-page-master> 
  
  
  <fo:page-sequence-master master-name="all"> 
   <fo:repeatable-page-master-alternatives> 

    <fo:conditional-page-master-reference 
     page-position="last" master-reference="last-page"/> 
    
    <fo:conditional-page-master-reference 
     page-position="any" master-reference="default-page" /> 

   </fo:repeatable-page-master-alternatives> 
  </fo:page-sequence-master> 
 </fo:layout-master-set>
Comment 1 Simon Pepping 2006-12-21 04:43:04 UTC
The problem is in
ConditionalPageMasterReference.isValid(isOddPage, isFirstPage, isLastPage,
isBlankPage), which says explicitly that a conditional pagemaster reference with
page-position="last" is not valid for a first page. I do not know at this moment
if that is correct in view of the FO spec.
Comment 2 ccardelli 2007-01-18 09:29:26 UTC
I am having this same problem in fop on windows.
If you do not know if that is correct in view of the FO spec, you may 
leave 'last' as is and support the 'only' trait (both first and last) as 
specified in XSL-FO 1.1 Recommendation.
So, the example stated would work as:
<fo:conditional-page-master-reference 
     page-position="only" master-reference="last-page"/> 
<fo:conditional-page-master-reference 
     page-position="last" master-reference="last-page"/> 
<fo:conditional-page-master-reference 
     page-position="any" master-reference="default-page" /> 
Comment 3 reick 2007-12-26 12:17:53 UTC
I have the same problem and I don´t know the solution for this problem or bug. 
Can you help me?
I have tried use: page-position="only" but it doesn`t work, I have the next 
error:

org.apache.fop.fo.PropertyList convertAttributeToProperty
GRAVE: Ignoring property: page-position="only" <No conversion defined only; 
property: 'page-position'>
Comment 4 Jeremias Maerki 2007-12-27 00:34:49 UTC
Indeed, page-position="only" (which is a XSL 1.1 feature) hasn't been
implemented, yet.
Comment 5 reick 2007-12-27 02:11:39 UTC
I think must be another solution to get the same thing:

- the last page have a footer (last_footer).
- the other pages don´t have a footer.

When it renders to a 1 page document, I want this page have a footer
(last_footer).

¿How can I get this?¿Can you help me? I have tried other things, such as use a 
footnote at the end of the body but when the body is filled the footnote is 
placed at the beginnig of the page (not at the end) or the footnote is cut.
 <fo:block>text of the body</fo:block>
 <fo:block>text of the body</fo:block>
 <fo:block>text of the body</fo:block>
 <fo:block>text of the body</fo:block>
 <fo:block>	
  <fo:footnote >
	 <fo:inline></fo:inline>
	 <fo:footnote-body>
	     <xsl:call-template name="last_footer"></xsl:call-template>
	 </fo:footnote-body> 
  </fo:footnote>
</fo:block>



Comment 6 reick 2008-01-03 06:18:20 UTC
Hi,

I have been searching a solution for this bug but it's impossible!!! I think 
the only solution will be implement page-position="only" (which is a XSL 1.1 
feature)in the next version of FOP.



Comment 7 Dave Gerdt 2008-07-08 13:59:23 UTC
Looking for a solution to this first page/last page problem I found a potential solution written by Ken Holman [1]. I assumed because he used it (and he seems to know a little about the subject ;)  ) I had found my solution. (I hadn't discovered this bug yet...)

However, the solution he provides doesn't work with FOP because as Simon points out above "ConditionalPageMasterReference.isValid(isOddPage, isFirstPage, isLastPage,isBlankPage) ... says explicitly that a conditional pagemaster reference with page-position="last" is not valid for a first page." Looking at the spec [2][3] I can't see any reason why that should be the case, though I'm no expert in the spec, to be sure. Can one of the devs comment on this?

As a fix, I reordered the if statement in ConditionalPageMasterReference.isValid so that the block for isLastPage comes before the block for isFirstPage and removed 'return false' when pagePosition == EN_FIRST in the isLastPage block (see code below). This appears to fix the problem, at least for Ken's test file. Anyone see where this might blow up in my face somewhere else? I ran the test suite and everything seemed to come out fine.

The test case is attached.

[1] http://services.renderx.com/lists/xep-support/3856.html
[2] http://www.w3.org/TR/2001/REC-xsl-20011015/slice6.html#fo_repeatable-page-master-alternatives
[3] http://www.w3.org/TR/2001/REC-xsl-20011015/slice7.html#page-position

Reordered 'if' from ConditionalPageMasterReference.isValid:
==================
if (isOnlyPage) {
    if (pagePosition != EN_ONLY) {
	return false;
    }
} else if (isLastPage) {
    if (pagePosition == EN_REST) {
	return false;
    } else if (pagePosition == EN_FIRST) {
	//return false;
    }
} else if (isFirstPage) {
    if (pagePosition == EN_REST) {
	return false;
    } else if (pagePosition == EN_LAST) {
	return false;
    }
} else {
    if (pagePosition == EN_FIRST) {
	return false;
    } else if (pagePosition == EN_LAST) {
	return false;
    }
}
Comment 8 Dave Gerdt 2008-07-08 14:02:49 UTC
Created attachment 22237 [details]
Test whether a 'first' page can also be a 'last' page

Test case for last page as first page bug.
Comment 9 Andreas L. Delmelle 2008-09-20 06:40:26 UTC
Created attachment 22617 [details]
Changes necessary to implement page-position="last"

Just thought I'd have a look into this, and AFAICT, implementing page-position="only" would not really be that complex. Parts of it already have, but org.apache.fop.layoutmgr.PageProvider always passes false for the 'isOnlyPage' parameter.

Now, I'm wondering whether this should be a parameter at all... If we pass isFirstPage and isLastPage, then isOnlyPage is always implied (?)

Looking at the tests in ConditionalPageMasterReference.isValid() a little closer, this also needed some work to /properly/ take into account page-position="only". Before the patch, a master-reference with this attribute-value will make isValid() always return true, even if isOnlyPage is set to false.

The small patch in attach fixes the issue in PageProvider (but does not yet eliminate the superfluous parameter). The changes in ConditionalPageMasterReference, IMO, perfectly reflect the definition of the values in the XSL-FO 1.1 Rec 6.4.12: ... "first", "last", "only" (both first and last), "rest" (not first nor last) or "any" (all of the previous).

So, it does not really 'fix' the issue of not being able to use a 'last' page-master-reference for a first page. The only ones eligible in that case are those with page-position 'only' or 'any'.

The correct specification for the document in attachment 22237 [details] would be (IIC):

...
   <page-sequence-master master-name="whatever">
     <repeatable-page-master-alternatives maximum-repeats="no-limit">
       <conditional-page-master-reference master-reference="only-page-layout"
                                          page-position="only"/>
       <conditional-page-master-reference master-reference="first-page-layout"
                                          page-position="first"/>
       <conditional-page-master-reference master-reference="last-page-layout"
                                          page-position="last"/>
       <conditional-page-master-reference master-reference="rest-page-layout"
                                          page-position="rest"/>
     </repeatable-page-master-alternatives>
   </page-sequence-master>
...

This works perfectly after applying the patch, and breaks no other testcases, so I'm contemplating a commit.
Comment 10 Andreas L. Delmelle 2008-09-20 07:02:28 UTC
(In reply to comment #9)
> So, it does not really 'fix' the issue of not being able to use a 'last'
> page-master-reference for a first page. The only ones eligible in that case are
> those with page-position 'only' or 'any'.
> 
> The correct specification for the document in attachment 22237 [details] would be (IIC):

OTOH, just tested some more, and the workaround with using multiple repeatable page-master-alternatives also works correctly after the patch.
Comment 11 Andreas L. Delmelle 2008-09-20 10:47:44 UTC
Created attachment 22619 [details]
Path including a bit more refactoring

A more invasive patch, basically with the same result. 
The isOnlyPage parameter has been removed from the picture. This affects a handful of classes in the org.apache.fop.fo.pagination package and the RTFHandler. 
The isValid() method has been rewritten entirely as one compact boolean expression, clearly reflecting when a the conditional-page-master is considered valid (at least to me... :-/)

If no one objects, I'll commit those changes along with some testcases somewhere next week.
Comment 12 Andreas L. Delmelle 2008-09-21 03:09:17 UTC
Created attachment 22621 [details]
Same as the previous, but with two added testcases
Comment 13 Andreas L. Delmelle 2008-09-23 11:50:55 UTC
Patch in attachment 22621 [details] applied to FOP Trunk.

see: http://svn.apache.org/viewvc?rev=698280&view=rev

Apologies for the rather long delay...

Thanks for reporting, and for the input/feedback!
Comment 14 Dave Gerdt 2008-10-03 11:48:13 UTC
(In reply to comment #13)
> Patch in attachment 22621 [details] applied to FOP Trunk.
> 
> see: http://svn.apache.org/viewvc?rev=698280&view=rev
> 
> Apologies for the rather long delay...
> 
> Thanks for reporting, and for the input/feedback!
> 

Thanks for this work, Andreas! This means I can now use an unmodified version of FOP. Very helpful.
Comment 15 Mark Anderson 2010-03-09 15:09:18 UTC
Hi Guys

I'm using FOP 0.95 and page-properties="only" doesn't seem to work. (Every page is treated as an only page.) It's working OK in several other FO Processors so I assume my FO is OK.

if it's fixed in 0.92 shouldn't it work in 0.95?

Regards

Mark
Comment 16 Glenn Adams 2012-04-01 06:47:15 UTC
batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed