Browse Source

Bugzilla #42576

Fix bug in force-page-count
Submitted by Adrian Cumiskey <dev.at.cumiskey.com>

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@549767 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_94
Chris Bowditch 17 years ago
parent
commit
f0654579fb

+ 0
- 2
src/java/org/apache/fop/fo/pagination/PageSequence.java View File

@@ -127,8 +127,6 @@ public class PageSequence extends FObj {
throw new ValidationException("master-reference '" + masterReference
+ "' for fo:page-sequence matches no"
+ " simple-page-master or page-sequence-master", locator);
} else {
pageSequenceMaster.reset();
}
}


+ 5
- 3
src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java View File

@@ -43,7 +43,7 @@ public class PageSequenceMaster extends FObj {
private LayoutMasterSet layoutMasterSet;
private List subSequenceSpecifiers;
private SubSequenceSpecifier currentSubSequence;
private int currentSubSequenceNumber;
private int currentSubSequenceNumber = -1;

// The terminology may be confusing. A 'page-sequence-master' consists
// of a sequence of what the XSL spec refers to as
@@ -135,8 +135,10 @@ public class PageSequenceMaster extends FObj {
public void reset() {
currentSubSequenceNumber = -1;
currentSubSequence = null;
for (int i = 0; i < subSequenceSpecifiers.size(); i++) {
((SubSequenceSpecifier)subSequenceSpecifiers.get(i)).reset();
if (subSequenceSpecifiers != null) {
for (int i = 0; i < subSequenceSpecifiers.size(); i++) {
((SubSequenceSpecifier)subSequenceSpecifiers.get(i)).reset();
}
}
}


+ 24
- 9
src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java View File

@@ -40,6 +40,7 @@ import org.apache.fop.fo.flow.RetrieveMarker;

import org.apache.fop.fo.pagination.Flow;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.pagination.PageSequenceMaster;
import org.apache.fop.fo.pagination.Region;
import org.apache.fop.fo.pagination.RegionBody;
import org.apache.fop.fo.pagination.SideRegion;
@@ -143,10 +144,11 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
}

areaTreeHandler.getAreaTreeModel().startPageSequence(title);
log.debug("Starting layout");
if (log.isDebugEnabled()) {
log.debug("Starting layout");
}

curPage = makeNewPage(false, false);

Flow mainFlow = pageSeq.getMainFlow();
childFLM = getLayoutManagerMaker().
@@ -172,7 +174,19 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
areaTreeHandler.notifyPageSequenceFinished(pageSeq,
(currentPageNum - startPageNum) + 1);
pageSeq.releasePageSequence();
log.debug("Ending layout");
// If this sequence has a page sequence master so we must reset
// it in preparation for the next sequence
String masterReference = pageSeq.getMasterReference();
PageSequenceMaster pageSeqMaster
= pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(masterReference);
if (pageSeqMaster != null) {
pageSeqMaster.reset();
}

if (log.isDebugEnabled()) {
log.debug("Ending layout");
}
}


@@ -772,7 +786,9 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
}

private void finishPage() {
curPage.getPageViewport().dumpMarkers();
if (log.isTraceEnabled()) {
curPage.getPageViewport().dumpMarkers();
}
// Layout side regions
layoutSideRegion(FO_REGION_BEFORE);
layoutSideRegion(FO_REGION_AFTER);
@@ -1123,7 +1139,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
// If there is no next page-sequence
// or if the value of its initial-page-number is "auto" do not force any page.

// if force-page-count is auto then set the value of forcePageCount
// depending on the initial-page-number of the next page-sequence
if (nextPageSeqInitialPageNumber != null && forcePageCount == Constants.EN_AUTO) {
@@ -1150,19 +1165,19 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
}

if (forcePageCount == Constants.EN_EVEN) {
if ((currentPageNum - startPageNum + 1) % 2 != 0) { // we have a odd number of pages
if ((currentPageNum - startPageNum + 1) % 2 != 0) { // we have an odd number of pages
curPage = makeNewPage(true, false);
}
} else if (forcePageCount == Constants.EN_ODD) {
if ((currentPageNum - startPageNum + 1) % 2 == 0) { // we have a even number of pages
if ((currentPageNum - startPageNum + 1) % 2 == 0) { // we have an even number of pages
curPage = makeNewPage(true, false);
}
} else if (forcePageCount == Constants.EN_END_ON_EVEN) {
if (currentPageNum % 2 != 0) { // we are now on a odd page
if (currentPageNum % 2 != 0) { // we are now on an odd page
curPage = makeNewPage(true, false);
}
} else if (forcePageCount == Constants.EN_END_ON_ODD) {
if (currentPageNum % 2 == 0) { // we are now on a even page
if (currentPageNum % 2 == 0) { // we are now on an even page
curPage = makeNewPage(true, false);
}
} else if (forcePageCount == Constants.EN_NO_FORCE) {

+ 152
- 0
test/layoutengine/standard-testcases/page-sequence-force-page-count_bug42576.xml View File

@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- $Id$ -->
<testcase>
<info>
<p>
This test checks the force-page-count property
using three identical page sequences refering to the same
page sequence master, odd pages should be blank.
</p>
</info>
<variables>
<img>../../resources/images/bgimg300dpi.jpg</img>
</variables>
<fo>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="first" page-height="297mm" page-width="210mm" margin-top="20mm" margin-bottom="20mm" margin-left="25mm" margin-right="25mm">
<fo:region-body margin-bottom="20mm"/>
<fo:region-before region-name="header-first" extent="10mm"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="normal" page-height="297mm" page-width="210mm" margin-top="20mm" margin-bottom="20mm" margin-left="25mm" margin-right="25mm">
<fo:region-body margin-bottom="20mm"/>
<fo:region-before region-name="header-normal" extent="10mm"/>
<fo:region-after region-name="footer-normal" extent="10mm"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="blank" page-height="297mm" page-width="210mm" margin-top="20mm" margin-bottom="20mm" margin-left="25mm" margin-right="25mm">
<fo:region-body/>
<fo:region-before region-name="header-blank" extent="297mm"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="document">
<fo:single-page-master-reference master-reference="first"/>
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference blank-or-not-blank="not-blank" master-reference="normal"/>
<fo:conditional-page-master-reference blank-or-not-blank="blank" master-reference="blank"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="document" force-page-count="end-on-even">
<fo:static-content flow-name="footer-normal">
<fo:block text-align="center">Normal footer</fo:block>
</fo:static-content>
<fo:static-content flow-name="header-first">
<fo:block text-align="center">FIRST PAGE OF SEQUENCE</fo:block>
</fo:static-content>
<fo:static-content flow-name="header-normal">
<fo:block text-align="center">Normal Non-blank page</fo:block>
</fo:static-content>
<fo:static-content flow-name="header-blank">
<fo:block space-before="100mm" text-align-last="center">
Intentionally left blank.</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block break-after="page">
TEST PAGE 1
</fo:block>
<fo:block break-after="page">
TEST PAGE 2
</fo:block>
<fo:block>
TEST PAGE 3
</fo:block>
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="document" force-page-count="end-on-even">
<fo:static-content flow-name="footer-normal">
<fo:block text-align="center">Normal footer</fo:block>
</fo:static-content>
<fo:static-content flow-name="header-first">
<fo:block text-align="center">FIRST PAGE OF SEQUENCE</fo:block>
</fo:static-content>
<fo:static-content flow-name="header-normal">
<fo:block text-align="center">Normal Non-blank page</fo:block>
</fo:static-content>
<fo:static-content flow-name="header-blank">
<fo:block space-before="100mm" text-align-last="center">
Intentionally left blank.</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block break-after="page">
TEST PAGE 1
</fo:block>
<fo:block break-after="page">
TEST PAGE 2
</fo:block>
<fo:block>
TEST PAGE 3
</fo:block>
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="document" force-page-count="end-on-even">
<fo:static-content flow-name="footer-normal">
<fo:block text-align="center">Normal footer</fo:block>
</fo:static-content>
<fo:static-content flow-name="header-first">
<fo:block text-align="center">FIRST PAGE OF SEQUENCE</fo:block>
</fo:static-content>
<fo:static-content flow-name="header-normal">
<fo:block text-align="center">Normal Non-blank page</fo:block>
</fo:static-content>
<fo:static-content flow-name="header-blank">
<fo:block space-before="100mm" text-align-last="center">
Intentionally left blank.</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block break-after="page">
TEST PAGE 1
</fo:block>
<fo:block break-after="page">
TEST PAGE 2
</fo:block>
<fo:block>
TEST PAGE 3
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</fo>
<checks>
<eval expected="3" xpath="count(//pageSequence)"/>
<eval expected="3" xpath="count(//pageSequence/pageViewport[@simple-page-master-name='first'])"/>
<eval expected="6" xpath="count(//pageSequence/pageViewport[@simple-page-master-name='normal'])"/>
<eval expected="3" xpath="count(//pageSequence/pageViewport[@simple-page-master-name='blank'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=1 and @simple-page-master-name='first'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=2 and @simple-page-master-name='normal'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=3 and @simple-page-master-name='normal'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=4 and @simple-page-master-name='blank'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=5 and @simple-page-master-name='first'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=6 and @simple-page-master-name='normal'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=7 and @simple-page-master-name='normal'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=8 and @simple-page-master-name='blank'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=9 and @simple-page-master-name='first'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=10 and @simple-page-master-name='normal'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=11 and @simple-page-master-name='normal'])"/>
<eval expected="1" xpath="count(//pageSequence/pageViewport[@nr=12 and @simple-page-master-name='blank'])"/>
</checks>
</testcase>

Loading…
Cancel
Save