diff options
author | Peter Bernard West <pbwest@apache.org> | 2004-09-12 06:57:12 +0000 |
---|---|---|
committer | Peter Bernard West <pbwest@apache.org> | 2004-09-12 06:57:12 +0000 |
commit | 8f509c6a2f422412e4840fc3dc849198295b6aa6 (patch) | |
tree | 8379e18b41c3d671233af0edfcf7725037f42a9e | |
parent | 771029a6e02c396c65f7e09d5ccd667e6cc9e520 (diff) | |
download | xmlgraphics-fop-8f509c6a2f422412e4840fc3dc849198295b6aa6.tar.gz xmlgraphics-fop-8f509c6a2f422412e4840fc3dc849198295b6aa6.zip |
Work in progress
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197942 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/fo/FoRoot.java | 27 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/flow/FoPageSequence.java | 114 |
2 files changed, 110 insertions, 31 deletions
diff --git a/src/java/org/apache/fop/fo/FoRoot.java b/src/java/org/apache/fop/fo/FoRoot.java index ed3b42066..ff24a045b 100644 --- a/src/java/org/apache/fop/fo/FoRoot.java +++ b/src/java/org/apache/fop/fo/FoRoot.java @@ -81,6 +81,25 @@ public class FoRoot extends FONode { /** Offset of first page-sequence child node. */ private int firstPageSeq = -1; + /** The page number of the last laid-out page */ + private int lastPageNumber = 0; + /** + * Gets the last laid-out page number. This is generally set by the + * page-sequence. + * @return the page number + */ + public int getLastPageNumber() { + return lastPageNumber; + } + /** + * Sets the last generated page number. This is generally set from the + * page-sequence processing. + * @param number the last generated number + */ + public void setLastPageNumber(int number) { + lastPageNumber = number; + } + /** * @param foTree the FO tree being built * @param event the <tt>XmlEvent</tt> that triggered the creation of this @@ -159,16 +178,16 @@ public class FoRoot extends FONode { if (ev == null) throw new FOPException("No page-sequence found."); firstPageSeq = numChildren(); - new FoPageSequence( - getFOTree(), this, (FoXmlEvent)ev, layoutMasters); + new FoPageSequence(getFOTree(), this, (FoXmlEvent)ev, + layoutMasters.getPageSequenceMasters()); ev = xmlevents.getEndElement(XmlEventReader.DISCARD_EV, ev); namespaces.relinquishEvent(ev); while ((ev = xmlevents.expectStartElement (FObjectNames.PAGE_SEQUENCE, XmlEvent.DISCARD_W_SPACE)) != null) { // Loop over remaining fo:page-sequences - new FoPageSequence( - getFOTree(), this, (FoXmlEvent)ev, layoutMasters); + new FoPageSequence(getFOTree(), this, (FoXmlEvent)ev, + layoutMasters.getPageSequenceMasters()); ev = xmlevents.getEndElement(XmlEventReader.DISCARD_EV, ev); namespaces.relinquishEvent(ev); } diff --git a/src/java/org/apache/fop/fo/flow/FoPageSequence.java b/src/java/org/apache/fop/fo/flow/FoPageSequence.java index fb3201203..d17e7c7c5 100644 --- a/src/java/org/apache/fop/fo/flow/FoPageSequence.java +++ b/src/java/org/apache/fop/fo/flow/FoPageSequence.java @@ -36,17 +36,19 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.area.Area; import org.apache.fop.area.Page; import org.apache.fop.area.PageList; -import org.apache.fop.area.PageListElement; -import org.apache.fop.area.PageSet; -import org.apache.fop.area.PageSetElement; import org.apache.fop.datastructs.TreeException; +import org.apache.fop.datatypes.EnumType; +import org.apache.fop.datatypes.IntegerType; +import org.apache.fop.datatypes.Numeric; +import org.apache.fop.datatypes.PropertyValue; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FOPageSeqNode; import org.apache.fop.fo.FOTree; import org.apache.fop.fo.FObjectNames; +import org.apache.fop.fo.FoRoot; import org.apache.fop.fo.PropNames; import org.apache.fop.fo.expr.PropertyException; -import org.apache.fop.fo.pagination.FoLayoutMasterSet; +import org.apache.fop.fo.properties.InitialPageNumber; import org.apache.fop.xml.FoXmlEvent; import org.apache.fop.xml.XmlEvent; import org.apache.fop.xml.XmlEventReader; @@ -129,6 +131,7 @@ public class FoPageSequence extends FONode { private int flowChild = -1; /** The page currently being processed by this page-sequence */ private Page page = null; + /** * Gets the current page of this page-sequence * @return the page @@ -137,22 +140,30 @@ public class FoPageSequence extends FONode { return page; } - /** The <code>PageList</code> for this page-sequence */ - private PageList pagelist = null; - /** The index of the current element in the pagelist */ + /** The <code>PageList</code> containing the flattened + * <code>pageTree</code> for this page-sequence. This PageList contains + * only <code>Page</code> elements. */ + private ArrayList pageArray = new ArrayList(); + /** The index of the current element in the pageList */ private int pgListIndex = -1; + /** The tree of all layout attempts for this page-sequence */ + private PageList pageList = null; + /** An array of indicies mapping the path through the + * <code>pageTree</code> to the current element */ + private ArrayList pageTreeMap = null; + /** - * @return the pagelist + * @return the pageList */ - public PageList getPagelist() { - return pagelist; + public PageList getPageList() { + return pageList; } /** - * @param pagelist to set + * @param pageList to set */ - public void setPagelist(PageList pagelist) { - this.pagelist = pagelist; + public void setPagelist(PageList pageList) { + this.pageList = pageList; } /** * @return the pgListIndex @@ -167,22 +178,69 @@ public class FoPageSequence extends FONode { this.pgListIndex = pgListIndex; } + public Page getCurr1stPage() { + if (pageArray == null) { + return null; + } + return (Page)(pageArray.get(0)); + } + /** - * Gets the current first page - * @return the first page + * The number of the page being laid out */ - public Page getCurr1stPage() { - PageListElement firstPage = pagelist.get(0); - while (firstPage.isPageSet()) { - PageSet pageset = (PageSet)firstPage; - PageSetElement setEl = pageset.get(pageset.getCurrentElement()); - if (setEl.isPageList()) { - firstPage = ((PageList)setEl).get(0); + private int currPageNumber = 0; + + private FoRoot root; + + private void getInitialPageNumber() { + PropertyValue pv; + try { + pv = getPropertyValue(PropNames.INITIAL_PAGE_NUMBER); + } catch (PropertyException e) { + throw new RuntimeException( + "Unable to obtain InitialPageNumber value"); + } + int i = 0; + int lastnum = root.getLastPageNumber(); + switch (pv.getType()) { + case PropertyValue.AUTO: + currPageNumber = lastnum + 1; + break; + case PropertyValue.ENUM: + i = ((EnumType)pv).getEnumValue(); + switch (i) { + case InitialPageNumber.AUTO_ODD: + currPageNumber = + ((lastnum % 2 == 0) ? lastnum + 1 : lastnum + 2); + break; + case InitialPageNumber.AUTO_EVEN: + currPageNumber = + ((lastnum % 2 == 0) ? lastnum + 2 : lastnum + 1); + break; + default: + throw new RuntimeException( + "Unknown InitialPageNumber enum value: " + i); + } + case PropertyValue.INTEGER: + i = ((IntegerType)pv).getInt(); + if (i < 0) { + currPageNumber = 1; + } else { + currPageNumber = i; + } + break; + case PropertyValue.NUMERIC: + i = ((Numeric)pv).asInt(); + if (i < 0) { + currPageNumber = 1; } else { - firstPage = (Page)setEl; + currPageNumber = i; } + break; + default: + throw new RuntimeException("Invalid property value type " + + PropertyValue.propertyTypes.get(pv.getType())); } - return (Page)firstPage; } /** Maps flownames to fo:flow and fo:static-content objects */ @@ -233,14 +291,16 @@ public class FoPageSequence extends FONode { * @param parent the parent FONode of this node * @param event the <tt>XmlEvent</tt> that triggered the creation of * this node - * @param layoutMasters the layout master set + * @param pageSeqMasters a <code>Map</code> of the page sequence masters + * from the layout master set */ public FoPageSequence(FOTree foTree, FONode parent, FoXmlEvent event, - FoLayoutMasterSet layoutMasters) + Map pageSeqMasters) throws TreeException, FOPException { super(foTree, FObjectNames.PAGE_SEQUENCE, parent, event, FONode.PAGESEQ_SET, sparsePropsMap, sparseIndices); + root = (FoRoot)parent; // Set up the graphics environment pageSpread = new BufferedImage(20*72, 12*72, BufferedImage.TYPE_INT_RGB); @@ -306,7 +366,7 @@ public class FoPageSequence extends FONode { // Generate a null page for the flow(s) page = Page.setupNullPage(this, foTree.getNextPageId()); // Intialize the PageList for this page-sequence - pagelist = new PageList(page); + pageList = new PageList(page); pgListIndex = 0; // Look for one or more fo:flow |