diff options
author | Jeremias Maerki <jeremias@apache.org> | 2006-02-26 11:35:52 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2006-02-26 11:35:52 +0000 |
commit | bc0dbc50ea511849c4a8d865d034103b4c0d1b5f (patch) | |
tree | 878ca0b7af25f089d85d1e083fccf5118f7ec041 | |
parent | 3511a16d374bfda66bdbd0e96144fb4687793bb9 (diff) | |
download | xmlgraphics-fop-bc0dbc50ea511849c4a8d865d034103b4c0d1b5f.tar.gz xmlgraphics-fop-bc0dbc50ea511849c4a8d865d034103b4c0d1b5f.zip |
Added support for page sequence title in AreaTreeParser (IF). Fixes problems in intermediate format test suite.
Introduced a PageSequence area tree object to achieve the proper sequence of Renderer.startPageSequence() calls and Renderer.renderPage() calls. Otherwise, the pageSequence elements are not properly placed in the intermediate format. Doesn't really affect the other renderers because they don't really care.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@381080 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/area/AreaTreeModel.java | 22 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/AreaTreeParser.java | 26 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/PageSequence.java | 78 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/PageViewport.java | 15 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/RenderPagesModel.java | 10 | ||||
-rw-r--r-- | test/layoutengine/standard-testcases/page-number-citation_basic.xml | 25 |
6 files changed, 152 insertions, 24 deletions
diff --git a/src/java/org/apache/fop/area/AreaTreeModel.java b/src/java/org/apache/fop/area/AreaTreeModel.java index 75783def8..74e2eb562 100644 --- a/src/java/org/apache/fop/area/AreaTreeModel.java +++ b/src/java/org/apache/fop/area/AreaTreeModel.java @@ -39,7 +39,8 @@ import org.apache.commons.logging.LogFactory; public class AreaTreeModel { private List pageSequenceList = null; private int currentPageSequenceIndex = -1; - private List currentPageSequencePageList; + /** the current page sequence */ + protected PageSequence currentPageSequence; private List offDocumentItems = new java.util.ArrayList(); protected static Log log = LogFactory.getLog(AreaTreeModel.class); @@ -56,8 +57,8 @@ public class AreaTreeModel { * @param title the title of the new page sequence */ public void startPageSequence(LineArea title) { - currentPageSequencePageList = new java.util.ArrayList(); - pageSequenceList.add(currentPageSequencePageList); + currentPageSequence = new PageSequence(title); + pageSequenceList.add(currentPageSequence); currentPageSequenceIndex = pageSequenceList.size() - 1; } @@ -66,13 +67,14 @@ public class AreaTreeModel { * @param page the page to add to the model. */ public void addPage(PageViewport page) { - currentPageSequencePageList.add(page); + currentPageSequence.addPage(page); int pageIndex = 0; for (int i = 0; i < currentPageSequenceIndex; i++) { - pageIndex += ((List)pageSequenceList.get(i)).size(); + pageIndex += ((PageSequence)pageSequenceList.get(i)).getPageCount(); } - pageIndex += currentPageSequencePageList.size() - 1; + pageIndex += currentPageSequence.getPageCount() - 1; page.setPageIndex(pageIndex); + page.setPageSequence(currentPageSequence); } /** @@ -101,8 +103,8 @@ public class AreaTreeModel { * @return returns the number of pages in a page sequence */ public int getPageCount(int seq) { - List sequence = (List) pageSequenceList.get(seq - 1); - return sequence.size(); + PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1); + return sequence.getPageCount(); } /** @@ -112,7 +114,7 @@ public class AreaTreeModel { * @return the PageViewport for the particular page */ public PageViewport getPage(int seq, int count) { - List sequence = (List) pageSequenceList.get(seq - 1); - return (PageViewport) sequence.get(count); + PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1); + return sequence.getPage(count); } } diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java index 13643f5ef..e4f1292d2 100644 --- a/src/java/org/apache/fop/area/AreaTreeParser.java +++ b/src/java/org/apache/fop/area/AreaTreeParser.java @@ -55,7 +55,6 @@ import org.apache.fop.fo.ElementMappingRegistry; import org.apache.fop.fo.extensions.ExtensionAttachment; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; import org.apache.fop.image.FopImage; import org.apache.fop.image.ImageFactory; import org.apache.fop.traits.BorderProps; @@ -127,6 +126,7 @@ public class AreaTreeParser { private PageViewport currentPageViewport; private Stack areaStack = new Stack(); private boolean firstFlow; + private boolean pendingStartPageSequence; private Stack delegateStack = new Stack(); private ContentHandler delegate; @@ -141,6 +141,7 @@ public class AreaTreeParser { makers.put("areaTree", new AreaTreeMaker()); makers.put("page", new PageMaker()); makers.put("pageSequence", new PageSequenceMaker()); + makers.put("title", new TitleMaker()); makers.put("pageViewport", new PageViewportMaker()); makers.put("regionViewport", new RegionViewportMaker()); makers.put("regionBefore", new RegionBeforeMaker()); @@ -324,13 +325,34 @@ public class AreaTreeParser { private class PageSequenceMaker extends AbstractMaker { public void startElement(Attributes attributes) { - treeModel.startPageSequence(null); + pendingStartPageSequence = true; + //treeModel.startPageSequence(null); Done after title or on the first viewport } } + private class TitleMaker extends AbstractMaker { + + public void startElement(Attributes attributes) { + LineArea line = new LineArea(); + areaStack.push(line); + } + + public void endElement() { + LineArea line = (LineArea)areaStack.pop(); + treeModel.startPageSequence(line); + pendingStartPageSequence = false; + } + + + } + private class PageViewportMaker extends AbstractMaker { public void startElement(Attributes attributes) { + if (pendingStartPageSequence) { + treeModel.startPageSequence(null); + pendingStartPageSequence = false; + } if (currentPageViewport != null) { throw new IllegalStateException("currentPageViewport must be null"); } diff --git a/src/java/org/apache/fop/area/PageSequence.java b/src/java/org/apache/fop/area/PageSequence.java new file mode 100644 index 000000000..39cb72214 --- /dev/null +++ b/src/java/org/apache/fop/area/PageSequence.java @@ -0,0 +1,78 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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$ */ + +package org.apache.fop.area; + +import java.util.List; + +/** + * Represents a page sequence in the area tree. + */ +public class PageSequence { + + private List pages = new java.util.ArrayList(); + private LineArea title; + + /** + * Main constructor + * @param title the title for the page-sequence, may be null + */ + public PageSequence(LineArea title) { + this.title = title; + } + + /** + * @return the title of the page sequence in form of a line area, or null if there's no title + */ + public LineArea getTitle() { + return this.title; + } + + /** + * Adds a new page to the page sequence + * @param page the page to be added + */ + public void addPage(PageViewport page) { + this.pages.add(page); + } + + /** + * @return the number of pages currently in this page sequence + */ + public int getPageCount() { + return this.pages.size(); + } + + /** + * Returns the page at the given index. + * @param idx the index of the requested page + * @return the requested page or null if it was not found + */ + public PageViewport getPage(int idx) { + return (PageViewport)this.pages.get(idx); + } + + /** + * Indicates whether a page is the first in this page sequence. + * @param page the page to be inspected + * @return true if the page is the first in this page sequence, false otherwise + */ + public boolean isFirstPage(PageViewport page) { + return page.equals(getPage(0)); + } +} diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java index f1c12495d..f2fbd0555 100644 --- a/src/java/org/apache/fop/area/PageViewport.java +++ b/src/java/org/apache/fop/area/PageViewport.java @@ -52,6 +52,8 @@ public class PageViewport implements Resolvable, Cloneable { private String pageNumberString = null; private int pageIndex = -1; //-1 = undetermined private boolean blank; + + private transient PageSequence pageSequence; // list of id references and the rectangle on the page //private Map idReferences = null; @@ -134,6 +136,19 @@ public class PageViewport implements Resolvable, Cloneable { } /** + * Sets the page sequence this page belongs to + * @param seq the page sequence + */ + public void setPageSequence(PageSequence seq) { + this.pageSequence = seq; + } + + /** @return the page sequence this page belongs to */ + public PageSequence getPageSequence() { + return this.pageSequence; + } + + /** * Get the view area rectangle of this viewport. * @return the rectangle for this viewport */ diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java index f4ae85fe7..afb55e22e 100644 --- a/src/java/org/apache/fop/area/RenderPagesModel.java +++ b/src/java/org/apache/fop/area/RenderPagesModel.java @@ -90,7 +90,9 @@ public class RenderPagesModel extends AreaTreeModel { */ public void startPageSequence(LineArea title) { super.startPageSequence(title); - renderer.startPageSequence(title); + if (renderer.supportsOutOfOrder()) { + renderer.startPageSequence(title); + } } /** @@ -110,6 +112,9 @@ public class RenderPagesModel extends AreaTreeModel { // could be referenced boolean ready = renderer.supportsOutOfOrder() && page.isResolved(); if (ready) { + if (!renderer.supportsOutOfOrder() && page.getPageSequence().isFirstPage(page)) { + renderer.startPageSequence(this.currentPageSequence.getTitle()); + } try { renderer.renderPage(page); } catch (Exception e) { @@ -149,6 +154,9 @@ public class RenderPagesModel extends AreaTreeModel { for (Iterator iter = prepared.iterator(); iter.hasNext();) { PageViewport p = (PageViewport)iter.next(); if (p.isResolved() || renderUnresolved) { + if (!renderer.supportsOutOfOrder() && p.getPageSequence().isFirstPage(p)) { + renderer.startPageSequence(this.currentPageSequence.getTitle()); + } try { renderer.renderPage(p); if (!p.isResolved()) { diff --git a/test/layoutengine/standard-testcases/page-number-citation_basic.xml b/test/layoutengine/standard-testcases/page-number-citation_basic.xml index e481a86ac..786603e34 100644 --- a/test/layoutengine/standard-testcases/page-number-citation_basic.xml +++ b/test/layoutengine/standard-testcases/page-number-citation_basic.xml @@ -55,19 +55,22 @@ </fo:root> </fo> <checks> - <eval expected="page: 1 of 2" xpath="//pageViewport[1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/lineArea"/> - <eval expected="page: 1, bof1 is on page 1" xpath="//pageViewport[1]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/lineArea"/> - <eval expected="page: 1, bof2 is on page 11" xpath="//pageViewport[1]/page/regionViewport/regionBody/mainReference/span/flow/block[3]/lineArea"/> + <eval expected="2" xpath="count(//pageSequence)"/> + <eval expected="2" xpath="count(//pageSequence[1]/pageViewport)"/> + <eval expected="2" xpath="count(//pageSequence[2]/pageViewport)"/> + <eval expected="page: 1 of 2" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/lineArea"/> + <eval expected="page: 1, bof1 is on page 1" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/lineArea"/> + <eval expected="page: 1, bof2 is on page 11" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[3]/lineArea"/> - <eval expected="page: 2" xpath="//pageViewport[2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/lineArea"/> - <eval expected="page: 2" xpath="//pageViewport[2]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/lineArea"/> - <eval expected="page: 2 of 2" xpath="//pageViewport[2]/page/regionViewport/regionBody/mainReference/span/flow/block[3]/lineArea"/> + <eval expected="page: 2" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/lineArea"/> + <eval expected="page: 2" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/lineArea"/> + <eval expected="page: 2 of 2" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[3]/lineArea"/> - <eval expected="page: 11 of 12" xpath="//pageViewport[3]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/lineArea"/> - <eval expected="page: 11" xpath="//pageViewport[3]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/lineArea"/> + <eval expected="page: 11 of 12" xpath="//pageViewport[@nr=11]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/lineArea"/> + <eval expected="page: 11" xpath="//pageViewport[@nr=11]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/lineArea"/> - <eval expected="page: 12, bof1 is on page 1" xpath="//pageViewport[4]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/lineArea"/> - <eval expected="page: 12, bof2 is on page 11" xpath="//pageViewport[4]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/lineArea"/> - <eval expected="page: 12 of 12" xpath="//pageViewport[4]/page/regionViewport/regionBody/mainReference/span/flow/block[3]/lineArea"/> + <eval expected="page: 12, bof1 is on page 1" xpath="//pageViewport[@nr=12]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/lineArea"/> + <eval expected="page: 12, bof2 is on page 11" xpath="//pageViewport[@nr=12]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/lineArea"/> + <eval expected="page: 12 of 12" xpath="//pageViewport[@nr=12]/page/regionViewport/regionBody/mainReference/span/flow/block[3]/lineArea"/> </checks> </testcase> |