pbwest 2004/09/11 23:57:12 Modified: src/java/org/apache/fop/fo/flow Tag: FOP_0-20-0_Alt-Design FoPageSequence.java src/java/org/apache/fop/fo Tag: FOP_0-20-0_Alt-Design FoRoot.java Log: Work in progress Revision Changes Path No revision No revision 1.1.2.19 +90 -30 xml-fop/src/java/org/apache/fop/fo/flow/Attic/FoPageSequence.java Index: FoPageSequence.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/Attic/FoPageSequence.java,v retrieving revision 1.1.2.18 retrieving revision 1.1.2.19 diff -u -r1.1.2.18 -r1.1.2.19 --- FoPageSequence.java 3 Jun 2004 13:28:47 -0000 1.1.2.18 +++ FoPageSequence.java 12 Sep 2004 06:57:12 -0000 1.1.2.19 @@ -36,17 +36,19 @@ 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 @@ 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 @@ 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 @@ 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 @@ * @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 @@ // 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 No revision No revision 1.1.2.14 +26 -7 xml-fop/src/java/org/apache/fop/fo/Attic/FoRoot.java Index: FoRoot.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/Attic/FoRoot.java,v retrieving revision 1.1.2.13 retrieving revision 1.1.2.14 diff -u -r1.1.2.13 -r1.1.2.14 --- FoRoot.java 18 May 2004 23:05:27 -0000 1.1.2.13 +++ FoRoot.java 12 Sep 2004 06:57:12 -0000 1.1.2.14 @@ -81,6 +81,25 @@ /** 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 @@ 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); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]