Fop
  1. Fop
  2. FOP-1264

page-position="last" doesn't work for 1 page document

    Details

    • Type: Bug Bug
    • Status: Closed
    • Resolution: Fixed
    • Affects Version/s: 0.92
    • Fix Version/s: None
    • Component/s: page-master/layout
    • Labels:
      None
    • Environment:
      Operating System: Windows 2000
      Platform: Other
    • External issue ID:
      40798

      Description

      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>

      1. bugzilla40798.diff
        28 kB
        Andreas L. Delmelle
      2. bugzilla40798.diff
        15 kB
        Andreas L. Delmelle
      3. patch_page-position-fix.diff
        3 kB
        Andreas L. Delmelle
      4. page-position-last-test.fo
        4 kB
        Dave Gerdt

        Activity

        Hide
        Simon Pepping added a comment -

        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.

        Show
        Simon Pepping added a comment - 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.
        Hide
        ccardelli added a comment -

        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" />

        Show
        ccardelli added a comment - 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" />
        Hide
        reick added a comment -

        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'>

        Show
        reick added a comment - 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'>
        Hide
        Jeremias Maerki added a comment -

        Indeed, page-position="only" (which is a XSL 1.1 feature) hasn't been
        implemented, yet.

        Show
        Jeremias Maerki added a comment - Indeed, page-position="only" (which is a XSL 1.1 feature) hasn't been implemented, yet.
        Hide
        reick added a comment -

        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>

        Show
        reick added a comment - 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>
        Hide
        reick added a comment -

        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.

        Show
        reick added a comment - 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.
        Hide
        Dave Gerdt added a comment -

        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; }

        }

        Show
        Dave Gerdt added a comment - 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; } }
        Hide
        Dave Gerdt added a comment -

        Attachment page-position-last-test.fo has been added with description: Test whether a 'first' page can also be a 'last' page

        Show
        Dave Gerdt added a comment - Attachment page-position-last-test.fo has been added with description: Test whether a 'first' page can also be a 'last' page
        Hide
        Dave Gerdt added a comment -

        Test case for last page as first page bug.

        Show
        Dave Gerdt added a comment - Test case for last page as first page bug.
        Hide
        Andreas L. Delmelle added a comment -

        Attachment patch_page-position-fix.diff has been added with description: Changes necessary to implement page-position="last"

        Show
        Andreas L. Delmelle added a comment - Attachment patch_page-position-fix.diff has been added with description: Changes necessary to implement page-position="last"
        Hide
        Andreas L. Delmelle added a comment -

        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 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.

        Show
        Andreas L. Delmelle added a comment - 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 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.
        Hide
        Andreas L. Delmelle added a comment -

        (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.

        Show
        Andreas L. Delmelle added a comment - (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.
        Hide
        Andreas L. Delmelle added a comment -

        Attachment bugzilla40798.diff has been added with description: Path including a bit more refactoring

        Show
        Andreas L. Delmelle added a comment - Attachment bugzilla40798.diff has been added with description: Path including a bit more refactoring
        Hide
        Andreas L. Delmelle added a comment -

        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.

        Show
        Andreas L. Delmelle added a comment - 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.
        Hide
        Andreas L. Delmelle added a comment -

        Attachment bugzilla40798.diff has been added with description: Same as the previous, but with two added testcases

        Show
        Andreas L. Delmelle added a comment - Attachment bugzilla40798.diff has been added with description: Same as the previous, but with two added testcases
        Hide
        Andreas L. Delmelle added a comment -

        Patch in attachment 22621 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!

        Show
        Andreas L. Delmelle added a comment - Patch in attachment 22621 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!
        Hide
        Dave Gerdt added a comment -

        (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.

        Show
        Dave Gerdt added a comment - (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.
        Hide
        Mark Anderson added a comment -

        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

        Show
        Mark Anderson added a comment - 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
        Hide
        Glenn Adams added a comment -

        batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed

        Show
        Glenn Adams added a comment - batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed

          People

          • Assignee:
            fop-dev
            Reporter:
            Michael V
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development