]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Further decoupling the area tree from the FO tree.
authorJeremias Maerki <jeremias@apache.org>
Wed, 21 Dec 2005 10:20:56 +0000 (10:20 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 21 Dec 2005 10:20:56 +0000 (10:20 +0000)
Created a new class org.apache.fop.layoutmgr.Page that holds a reference to the generating SimplePageMaster and the PageViewport. A deserialized area tree doesn't need a reference to the SimplePageMaster.
Renamed PageViewportProvider to PageProvider as it now returns Page instances, not (directly) PageViewports.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@358254 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/area/Page.java
src/java/org/apache/fop/area/PageViewport.java
src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
src/java/org/apache/fop/layoutmgr/Page.java [new file with mode: 0644]
src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
src/java/org/apache/fop/render/ps/PSRenderer.java

index 3f03bfa8a00dc4e86378abd47da5db52f276bc2f..cc920b993b0883f25c61a1c958020e8f6be17e4a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 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.
  * limitations under the License.
  */
 
-/* $Id: Page.java,v 1.4 2004/02/27 17:41:26 jeremias Exp $ */
+/* $Id$ */
 
 package org.apache.fop.area;
 
 import java.awt.Rectangle;
 import java.awt.geom.Rectangle2D;
 import java.io.Serializable;
-import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.fop.datatypes.FODimension;
 import org.apache.fop.datatypes.LengthBase;
@@ -54,7 +54,7 @@ public class Page implements Serializable, Cloneable {
     private RegionViewport regionAfter = null;
 
     // temporary map of unresolved objects used when serializing the page
-    private HashMap unresolved = null;
+    private Map unresolved = null;
 
     /** Set to true to make this page behave as if it were not empty. */
     private boolean fakeNonEmpty = false;
@@ -269,9 +269,9 @@ public class Page implements Serializable, Cloneable {
     /**
      * Set the unresolved references on this page for serializing.
      *
-     * @param unres the HashMap of unresolved objects
+     * @param unres the Map of unresolved objects
      */
-    public void setUnresolvedReferences(HashMap unres) {
+    public void setUnresolvedReferences(Map unres) {
         unresolved = unres;
     }
 
@@ -282,7 +282,7 @@ public class Page implements Serializable, Cloneable {
      *
      * @return the de-serialized HashMap of unresolved objects
      */
-    public HashMap getUnresolvedReferences() {
+    public Map getUnresolvedReferences() {
         return unresolved;
     }
 
index 2cced4a5f2557d72e837ef24a34568cae50b34ae..f1daaa2f1e099d809c472fc596b6a7981a79caa0 100644 (file)
@@ -46,19 +46,18 @@ public class PageViewport implements Resolvable, Cloneable {
 
     private Page page;
     private Rectangle2D viewArea;
-    private boolean clip = false;
+    private String simplePageMasterName;
     private String pageNumberString = null;
     private int pageIndex = -1; //-1 = undetermined
-    private SimplePageMaster spm = null;
     private boolean blank;
 
     // list of id references and the rectangle on the page
-    private Map idReferences = null;
+    //private Map idReferences = null;
 
     // this keeps a list of currently unresolved areas or extensions
     // once an idref is resolved it is removed
     // when this is empty the page can be rendered
-    private HashMap unresolvedIDRefs = new HashMap();
+    private Map unresolvedIDRefs = new java.util.HashMap();
 
     private Map pendingResolved = null;
 
@@ -69,6 +68,10 @@ public class PageViewport implements Resolvable, Cloneable {
     private Map markerFirstAny = null;
     private Map markerLastEnd = null;
     private Map markerLastAny = null;
+    
+    //Arbitrary attachments to the page from extensions that need to pass information
+    //down to the renderers.
+    private List extensionAttachments = null;
 
     /**
      * logging instance
@@ -82,7 +85,8 @@ public class PageViewport implements Resolvable, Cloneable {
      * @param blank true if this is a blank page
      */
     public PageViewport(SimplePageMaster spm, String pageStr, boolean blank) {
-        this.spm = spm;
+        this.simplePageMasterName = spm.getMasterName();
+        this.extensionAttachments = spm.getExtensionAttachments();
         this.blank = blank;
         int pageWidth = spm.getPageWidth().getValue();
         int pageHeight = spm.getPageHeight().getValue();
@@ -93,25 +97,14 @@ public class PageViewport implements Resolvable, Cloneable {
     }
 
     /**
-     * Create a page viewport 
-     * @param spm SimplePageMaster indicating the page and region dimensions
-     * @param pageStr the page number as string.
-     * @param p Page Reference Area
-     * @param bounds Page Viewport dimensions
+     * Copy constructor. 
+     * @param original the original PageViewport to copy from
      */
-    public PageViewport(SimplePageMaster spm, String pageStr, Page p, Rectangle2D bounds) {
-        this.spm = spm;
-        this.pageNumberString = pageStr;
-        this.page = p;
-        this.viewArea = bounds;
-    }
-
-    /**
-     * Set if this viewport should clip.
-     * @param c true if this viewport should clip
-     */
-    public void setClip(boolean c) {
-        clip = c;
+    public PageViewport(PageViewport original) {
+        this.extensionAttachments = new java.util.ArrayList(original.extensionAttachments);
+        this.pageNumberString = original.pageNumberString;
+        this.page = (Page)original.page.clone();
+        this.viewArea = (Rectangle2D)original.viewArea.clone();
     }
 
     /**
@@ -280,11 +273,17 @@ public class PageViewport implements Resolvable, Cloneable {
                     Object key = iter.next();
                     if (!markerFirstStart.containsKey(key)) {
                         markerFirstStart.put(key, marks.get(key));
-                        log.trace("page " + pageNumberString + ": " + "Adding marker " + key + " to FirstStart");
+                        if (log.isTraceEnabled()) {
+                            log.trace("page " + pageNumberString + ": " 
+                                    + "Adding marker " + key + " to FirstStart");
+                        }
                     }
                     if (!markerFirstAny.containsKey(key)) {
                         markerFirstAny.put(key, marks.get(key));
-                        log.trace("page " + pageNumberString + ": " + "Adding marker " + key + " to FirstAny");
+                        if (log.isTraceEnabled()) {
+                            log.trace("page " + pageNumberString + ": " 
+                                    + "Adding marker " + key + " to FirstAny");
+                        }
                     }
                 }
                 if (markerLastStart == null) {
@@ -292,7 +291,10 @@ public class PageViewport implements Resolvable, Cloneable {
                 }
                 // last on page: replace all
                 markerLastStart.putAll(marks);
-                log.trace("page " + pageNumberString + ": " + "Adding all markers to LastStart");
+                if (log.isTraceEnabled()) {
+                    log.trace("page " + pageNumberString + ": " 
+                            + "Adding all markers to LastStart");
+                }
             } else {
                 if (markerFirstAny == null) {
                     markerFirstAny = new HashMap();
@@ -302,7 +304,10 @@ public class PageViewport implements Resolvable, Cloneable {
                     Object key = iter.next();
                     if (!markerFirstAny.containsKey(key)) {
                         markerFirstAny.put(key, marks.get(key));
-                        log.trace("page " + pageNumberString + ": " + "Adding marker " + key + " to FirstAny");
+                        if (log.isTraceEnabled()) {
+                            log.trace("page " + pageNumberString + ": " 
+                                    + "Adding marker " + key + " to FirstAny");
+                        }
                     }
                 }
             }
@@ -314,14 +319,20 @@ public class PageViewport implements Resolvable, Cloneable {
                 }
                 // last on page: replace all
                 markerLastEnd.putAll(marks);
-                log.trace("page " + pageNumberString + ": " + "Adding all markers to LastEnd");
+                if (log.isTraceEnabled()) {
+                    log.trace("page " + pageNumberString + ": " 
+                            + "Adding all markers to LastEnd");
+                }
             }
             if (markerLastAny == null) {
                 markerLastAny = new HashMap();
             }
             // last on page: replace all
             markerLastAny.putAll(marks);
-            log.trace("page " + pageNumberString + ": " + "Adding all markers to LastAny");
+            if (log.isTraceEnabled()) {
+                log.trace("page " + pageNumberString + ": " 
+                        + "Adding all markers to LastAny");
+            }
         }
     }
 
@@ -436,11 +447,7 @@ public class PageViewport implements Resolvable, Cloneable {
      * @return a copy of this page and associated viewports
      */
     public Object clone() {
-        Page p = (Page)page.clone();
-        PageViewport ret = new PageViewport(spm, pageNumberString, 
-                p, (Rectangle2D)viewArea.clone());
-        ret.pageNumberString = pageNumberString;
-        return ret;
+        return new PageViewport(this);
     }
 
     /**
@@ -461,11 +468,15 @@ public class PageViewport implements Resolvable, Cloneable {
         sb.append(getPageNumberString());
         return sb.toString();
     }
-    /**
-     * @return Returns the spm.
-     */
-    public SimplePageMaster getSPM() {
-        return spm;
+    
+    /** @return the name of the simple-page-master that created this page */
+    public String getSimplePageMasterName() {
+        return this.simplePageMasterName;
+    }
+    
+    /** @return the list of extension attachments for this page */
+    public List getExtensionAttachments() {
+        return this.extensionAttachments;
     }
     
     /** @return True if this is a blank page. */
index 7b5eae9417b3d8fbdb4a11db9e967677c98d003c..630d73ecf641a366cbbee3fa09934becdc945d8b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 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.
@@ -30,11 +30,14 @@ import java.util.List;
  * from an id reference.
  */
 public class UnresolvedPageNumber extends TextArea implements Resolvable {
+
     private boolean resolved = false;
     private String pageIDRef;
-    private Font font;
     private String text;
 
+    //Transient fields
+    private transient Font font;
+    
     /**
      * Create a new unresolvable page number.
      *
@@ -74,7 +77,7 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable {
             removeText();
             addWord(page.getPageNumberString(), 0);
             // update ipd
-            updateIPD(getStringWidth(text));
+            updateIPD(font.getWordWidth(text));
             // set the Font object to null, as we don't need it any more
             font = null;
         }
@@ -101,15 +104,4 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable {
         return true;
     }
 
-    /**
-     * @param str string to be measured
-     * @return width of the string
-     */
-    private int getStringWidth(String str) {
-        int width = 0;
-        for (int count = 0; count < str.length(); count++) {
-            width += font.getCharWidth(str.charAt(count));
-        }
-        return width;
-    }
 }
index 83f3c3afb149a25c592e5537d0b3a3f77e9d1c39..729f153f11fe9b8b3be02076f276597c36b697c8 100644 (file)
@@ -115,12 +115,12 @@ public abstract class AbstractBreaker {
     }
 
     /**
-     * Returns the PageViewportProvider if any. PageBreaker overrides this method because each
+     * Returns the PageProvider if any. PageBreaker overrides this method because each
      * page may have a different available BPD which needs to be accessible to the breaking
      * algorithm.
-     * @return the applicable PageViewportProvider, or null if not applicable
+     * @return the applicable PageProvider, or null if not applicable
      */
-    protected PageSequenceLayoutManager.PageViewportProvider getPageViewportProvider() {
+    protected PageSequenceLayoutManager.PageProvider getPageProvider() {
         return null;
     }
     
@@ -222,7 +222,7 @@ public abstract class AbstractBreaker {
                 log.debug("PLM> start of algorithm (" + this.getClass().getName() 
                         + "), flow BPD =" + flowBPD);
                 PageBreakingAlgorithm alg = new PageBreakingAlgorithm(getTopLevelLM(),
-                        getPageViewportProvider(),
+                        getPageProvider(),
                         alignment, alignmentLast, footnoteSeparatorLength,
                         isPartOverflowRecoveryActivated());
                 int iOptPageCount;
index 80b49aafbc4061754f48c725fb8b60ba2ba58916..085fe9a69e4ddc4bd79d8db21529fb39437d40e0 100644 (file)
@@ -264,10 +264,15 @@ public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager
     }
     
     /**
-     * @see org.apache.fop.layoutmgr.PageSequenceLayoutManager#getCurrentPV
+     * @see org.apache.fop.layoutmgr.PageSequenceLayoutManager#getCurrentPage
      */
+    public Page getCurrentPage() {
+        return getPSLM().getCurrentPage();
+    }  
+    
+    /** @return the current page viewport */
     public PageViewport getCurrentPV() {
-        return getPSLM().getCurrentPV();
+        return getPSLM().getCurrentPage().getPageViewport();
     }  
     
     /**
index 77c8b43c4e87e5ca288090b97dc27ed1cef5a31a..944ba9da4ebdf6f4a2daf8fefa3592d0979164e6 100644 (file)
@@ -35,12 +35,12 @@ public class BalancingColumnBreakingAlgorithm extends PageBreakingAlgorithm {
     private int idealPartLen;\r
     \r
     public BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM,\r
-            PageSequenceLayoutManager.PageViewportProvider pvProvider,\r
+            PageSequenceLayoutManager.PageProvider pageProvider,\r
             int alignment, int alignmentLast,\r
             MinOptMax footnoteSeparatorLength,\r
             boolean partOverflowRecovery,\r
             int columnCount) {\r
-        super(topLevelLM, pvProvider, alignment, alignmentLast, \r
+        super(topLevelLM, pageProvider, alignment, alignmentLast, \r
                 footnoteSeparatorLength, partOverflowRecovery);\r
         this.columnCount = columnCount;\r
         this.considerTooShort = true; //This is important!\r
index 3ec814bd2faf961059bda98232faa222a7bf5b56..70da380fc48b7b74a4a2aee0762004176d085558 100644 (file)
@@ -92,7 +92,7 @@ public class FlowLayoutManager extends BlockStackingLayoutManager
             LayoutContext childLC = new LayoutContext(0);
             childLC.setStackLimit(context.getStackLimit());
             childLC.setRefIPD(context.getRefIPD());
-            childLC.setWritingMode(getCurrentPV().getSPM().getWritingMode());
+            childLC.setWritingMode(getCurrentPage().getSimplePageMaster().getWritingMode());
             
             // get elements from curLM
             returnedList = curLM.getNextKnuthElements(childLC, alignment);
diff --git a/src/java/org/apache/fop/layoutmgr/Page.java b/src/java/org/apache/fop/layoutmgr/Page.java
new file mode 100644 (file)
index 0000000..568defb
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2005 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.layoutmgr;
+
+import org.apache.fop.area.PageViewport;
+import org.apache.fop.fo.pagination.SimplePageMaster;
+
+/**
+ * This object is used by the layout engine to represent a page. It provides access to the
+ * simple-page-master that was used as a template for this page and it provides access to the
+ * PageViewport which is the top-level area tree element. This class helps to decouple the
+ * FO tree from the area tree to make the latter easily serializable.
+ */
+public class Page {
+
+    private SimplePageMaster spm;
+    private PageViewport pageViewport;
+    
+    public Page(SimplePageMaster spm, String pageStr, boolean blank) {
+        this.spm = spm;
+        this.pageViewport = new PageViewport(spm, pageStr, blank);
+    }
+    
+    public SimplePageMaster getSimplePageMaster() {
+        return this.spm;
+    }
+    
+    public PageViewport getPageViewport() {
+        return this.pageViewport;
+    }
+    
+}
index ced5d620a08c9008099b2a6f74d149433d7da251..ec456c0302eadeda7870c3352b1b169e0f79db36 100644 (file)
@@ -31,7 +31,7 @@ import org.apache.fop.traits.MinOptMax;
 class PageBreakingAlgorithm extends BreakingAlgorithm {
 
     private LayoutManager topLevelLM;
-    private PageSequenceLayoutManager.PageViewportProvider pageViewportProvider;
+    private PageSequenceLayoutManager.PageProvider pageProvider;
     private LinkedList pageBreaks = null;
 
     private ArrayList footnotesList = null;
@@ -66,13 +66,13 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
     private boolean storedValue = false;
 
     public PageBreakingAlgorithm(LayoutManager topLevelLM,
-                                 PageSequenceLayoutManager.PageViewportProvider pageViewportProvider,
+                                 PageSequenceLayoutManager.PageProvider pageProvider,
                                  int alignment, int alignmentLast,
                                  MinOptMax footnoteSeparatorLength,
                                  boolean partOverflowRecovery) {
         super(alignment, alignmentLast, true, partOverflowRecovery, 0);
         this.topLevelLM = topLevelLM;
-        this.pageViewportProvider = pageViewportProvider;
+        this.pageProvider = pageProvider;
         best = new BestPageRecords();
         this.footnoteSeparatorLength = (MinOptMax) footnoteSeparatorLength.clone();
         // add some stretch, to avoid a restart for every page containing footnotes
@@ -798,8 +798,8 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
     /** @see org.apache.fop.layoutmgr.BreakingAlgorithm#getLineWidth(int) */
     protected int getLineWidth(int line) {
         int bpd;
-        if (pageViewportProvider != null) {
-            bpd = pageViewportProvider.getAvailableBPD(line);
+        if (pageProvider != null) {
+            bpd = pageProvider.getAvailableBPD(line);
         } else {
             bpd = super.getLineWidth(line);
         }
index 4e7b1af92fc58c2509ca5d2cc754bb39b43e86e4..b5f69f613412912daa0534a69f71367043b9ef68 100644 (file)
@@ -69,13 +69,13 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
      */
     private PageSequence pageSeq;
 
-    private PageViewportProvider pvProvider;
+    private PageProvider pageProvider;
     
     /** 
-     * Current page-viewport-area being filled by
+     * Current page with page-viewport-area being filled by
      * the PSLM.
      */
-    private PageViewport curPV = null;
+    private Page curPage = null;
 
     /**
      * The FlowLayoutManager object, which processes
@@ -98,7 +98,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         super(pseq);
         this.areaTreeHandler = ath;
         this.pageSeq = pseq;
-        this.pvProvider = new PageViewportProvider(this.pageSeq);
+        this.pageProvider = new PageProvider(this.pageSeq);
     }
 
     /**
@@ -109,9 +109,9 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         return areaTreeHandler.getLayoutManagerMaker();
     }
 
-    /** @return the PageViewportProvider applicable to this page-sequence. */
-    public PageViewportProvider getPageViewportProvider() {
-        return this.pvProvider;
+    /** @return the PageProvider applicable to this page-sequence. */
+    public PageProvider getPageProvider() {
+        return this.pageProvider;
     }
     
     /**
@@ -135,7 +135,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         areaTreeHandler.getAreaTreeModel().startPageSequence(title);
         log.debug("Starting layout");
 
-        curPV = makeNewPage(false, false);
+        curPage = makeNewPage(false, false);
 
         addIDToPage(pageSeq.getId());
         Flow mainFlow = pageSeq.getMainFlow();
@@ -143,7 +143,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
             makeFlowLayoutManager(this, mainFlow);
 
         PageBreaker breaker = new PageBreaker(this);
-        int flowBPD = (int) curPV.getBodyRegion().getRemainingBPD();
+        int flowBPD = (int)getCurrentPV().getBodyRegion().getRemainingBPD();
         breaker.doLayout(flowBPD);
         
         finishPage();
@@ -169,7 +169,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         
         /** @see org.apache.fop.layoutmgr.AbstractBreaker */
         protected void updateLayoutContext(LayoutContext context) {
-            int flowIPD = curPV.getCurrentSpan().getColumnWidth();
+            int flowIPD = getCurrentPV().getCurrentSpan().getColumnWidth();
             context.setRefIPD(flowIPD);
         }
         
@@ -177,9 +177,9 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
             return null;  // unneeded for PSLM
         }
         
-        /** @see org.apache.fop.layoutmgr.AbstractBreaker#getPageViewportProvider() */
-        protected PageSequenceLayoutManager.PageViewportProvider getPageViewportProvider() {
-            return pvProvider;
+        /** @see org.apache.fop.layoutmgr.AbstractBreaker#getPageProvider() */
+        protected PageSequenceLayoutManager.PageProvider getPageProvider() {
+            return pageProvider;
         }
         
         /** @see org.apache.fop.layoutmgr.AbstractBreaker */
@@ -210,8 +210,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
             }
             firstPart = false;
             pageBreakHandled = true;
-            pvProvider.setStartOfNextElementList(currentPageNum, 
-                    curPV.getCurrentSpan().getCurrentFlowIndex());
+            pageProvider.setStartOfNextElementList(currentPageNum, 
+                    getCurrentPV().getCurrentSpan().getCurrentFlowIndex());
             return super.getNextBlockList(childLC, nextSequenceStartsOn, blockLists);
         }
         
@@ -280,7 +280,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         }
         
         protected int getCurrentDisplayAlign() {
-            return curPV.getSPM().getRegion(Constants.FO_REGION_BODY).getDisplayAlign();
+            return curPage.getSimplePageMaster().getRegion(
+                    Constants.FO_REGION_BODY).getDisplayAlign();
         }
         
         protected boolean hasMoreContent() {
@@ -293,7 +294,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
                         "xsl-footnote-separator");
                 // create a Block area that will contain the separator areas
                 separatorArea = new Block();
-                separatorArea.setIPD(curPV.getRegionReference(Constants.FO_REGION_BODY).getIPD());
+                separatorArea.setIPD(
+                        getCurrentPV().getRegionReference(Constants.FO_REGION_BODY).getIPD());
                 // create a StaticContentLM for the footnote separator
                 footnoteSeparatorLM = (StaticContentLayoutManager)
                     getLayoutManagerMaker().makeStaticContentLayoutManager(
@@ -309,7 +311,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
             if (needColumnBalancing) {
                 AbstractBreaker.log.debug("Column balancing now!!!");
                 AbstractBreaker.log.debug("===================================================");
-                int restartPoint = pvProvider.getStartingPartIndexForLastPage(partCount);
+                int restartPoint = pageProvider.getStartingPartIndexForLastPage(partCount);
                 if (restartPoint > 0) {
                     addAreas(alg, restartPoint, originalList, effectiveList);
                 }
@@ -331,13 +333,13 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
                 }
                 pageBreakHandled = true;
                 //Update so the available BPD is reported correctly
-                pvProvider.setStartOfNextElementList(currentPageNum, 
-                        curPV.getCurrentSpan().getCurrentFlowIndex());
+                pageProvider.setStartOfNextElementList(currentPageNum, 
+                        getCurrentPV().getCurrentSpan().getCurrentFlowIndex());
 
                 //Restart last page
                 PageBreakingAlgorithm algRestart = new BalancingColumnBreakingAlgorithm(
                         getTopLevelLM(),
-                        getPageViewportProvider(),
+                        getPageProvider(),
                         alignment, Constants.EN_START, footnoteSeparatorLength,
                         isPartOverflowRecoveryActivated(),
                         getCurrentPV().getBodyRegion().getColumnCount());
@@ -367,8 +369,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         
         protected void startPart(BlockSequence list, int breakClass) {
             AbstractBreaker.log.debug("startPart() breakClass=" + breakClass);
-            if (curPV == null) {
-                throw new IllegalStateException("curPV must not be null");
+            if (curPage == null) {
+                throw new IllegalStateException("curPage must not be null");
             }
             if (!pageBreakHandled) {
                 
@@ -382,8 +384,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
                     // otherwise, we may simply need a new page
                     handleBreakTrait(breakClass);
                 }
-                pvProvider.setStartOfNextElementList(currentPageNum, 
-                        curPV.getCurrentSpan().getCurrentFlowIndex());
+                pageProvider.setStartOfNextElementList(currentPageNum, 
+                        getCurrentPV().getCurrentSpan().getCurrentFlowIndex());
             }
             pageBreakHandled = false;
             // add static areas and resolve any new id areas
@@ -393,7 +395,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         
         /** @see org.apache.fop.layoutmgr.AbstractBreaker#handleEmptyContent() */
         protected void handleEmptyContent() {
-            curPV.getPage().fakeNonEmpty();
+            getCurrentPV().getPage().fakeNonEmpty();
         }
         
         protected void finishPart(PageBreakingAlgorithm alg, PageBreakPosition pbp) {
@@ -417,7 +419,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
                 }
                 // set the offset from the top margin
                 Footnote parentArea = (Footnote) getCurrentPV().getBodyRegion().getFootnote();
-                int topOffset = (int) curPV.getBodyRegion().getBPD() - parentArea.getBPD();
+                int topOffset = (int) getCurrentPV().getBodyRegion().getBPD() - parentArea.getBPD();
                 if (separatorArea != null) {
                     topOffset -= separatorArea.getBPD();
                 }
@@ -441,12 +443,20 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
     
     /**
      * Provides access to the current page.
-     * @return the current PageViewport
+     * @return the current Page
      */
-    public PageViewport getCurrentPV() {
-        return curPV;
+    public Page getCurrentPage() {
+        return curPage;
     }
 
+    /**
+     * Provides access to the current page viewport.
+     * @return the current PageViewport
+     *//*
+    public PageViewport getCurrentPageViewport() {
+        return curPage.getPageViewport();
+    }*/
+
     /**
      * Provides access to this object
      * @return this PageSequenceLayoutManager instance
@@ -480,7 +490,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
      */
     public void addIDToPage(String id) {
         if (id != null && id.length() > 0) {
-            areaTreeHandler.associateIDWithPageViewport(id, curPV);
+            areaTreeHandler.associateIDWithPageViewport(id, curPage.getPageViewport());
         }
     }
 
@@ -501,8 +511,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
      * @param res the resolvable object that needs resolving
      */
     public void addUnresolvedArea(String id, Resolvable res) {
-        curPV.addUnresolvedIDRef(id, res);
-        areaTreeHandler.addUnresolvedIDRef(id, curPV);
+        curPage.getPageViewport().addUnresolvedIDRef(id, res);
+        areaTreeHandler.addUnresolvedIDRef(id, curPage.getPageViewport());
     }
 
     /**
@@ -529,7 +539,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         int boundary = rm.getRetrieveBoundary();               
         
         // get marker from the current markers on area tree
-        Marker mark = (Marker)curPV.getMarker(name, pos);
+        Marker mark = (Marker)getCurrentPV().getMarker(name, pos);
         if (mark == null && boundary != EN_PAGE) {
             // go back over pages until mark found
             // if document boundary then keep going
@@ -563,24 +573,25 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         }
     }
 
-    private PageViewport makeNewPage(boolean bIsBlank, boolean bIsLast) {
-        if (curPV != null) {
+    private Page makeNewPage(boolean bIsBlank, boolean bIsLast) {
+        if (curPage != null) {
             finishPage();
         }
 
         currentPageNum++;
 
-        curPV = pvProvider.getPageViewport(bIsBlank,
-                currentPageNum, PageViewportProvider.RELTO_PAGE_SEQUENCE);
+        curPage = pageProvider.getPage(bIsBlank,
+                currentPageNum, PageProvider.RELTO_PAGE_SEQUENCE);
 
         if (log.isDebugEnabled()) {
-            log.debug("[" + curPV.getPageNumberString() + (bIsBlank ? "*" : "") + "]");
+            log.debug("[" + curPage.getPageViewport().getPageNumberString() 
+                    + (bIsBlank ? "*" : "") + "]");
         }
-        return curPV;
+        return curPage;
     }
 
     private void layoutSideRegion(int regionID) {
-        SideRegion reg = (SideRegion)curPV.getSPM().getRegion(regionID);
+        SideRegion reg = (SideRegion)curPage.getSimplePageMaster().getRegion(regionID);
         if (reg == null) {
             return;
         }
@@ -596,7 +607,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
     }
 
     private void finishPage() {
-        curPV.dumpMarkers();
+        curPage.getPageViewport().dumpMarkers();
         // Layout side regions
         layoutSideRegion(FO_REGION_BEFORE); 
         layoutSideRegion(FO_REGION_AFTER);
@@ -605,14 +616,14 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         
         // Try to resolve any unresolved IDs for the current page.
         // 
-        areaTreeHandler.tryIDResolution(curPV);
+        areaTreeHandler.tryIDResolution(curPage.getPageViewport());
         // Queue for ID resolution and rendering
-        areaTreeHandler.getAreaTreeModel().addPage(curPV);
+        areaTreeHandler.getAreaTreeModel().addPage(curPage.getPageViewport());
         if (log.isDebugEnabled()) {
-            log.debug("page finished: " + curPV.getPageNumberString() 
+            log.debug("page finished: " + curPage.getPageViewport().getPageNumberString() 
                     + ", current num: " + currentPageNum);
         }
-        curPV = null;
+        curPage = null;
     }
     
     /**
@@ -624,26 +635,26 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
     private void handleBreakTrait(int breakVal) {
         if (breakVal == Constants.EN_ALL) {
             //break due to span change in multi-column layout
-            curPV.createSpan(true);
+            curPage.getPageViewport().createSpan(true);
             return;
         } else if (breakVal == Constants.EN_NONE) {
-            curPV.createSpan(false);
+            curPage.getPageViewport().createSpan(false);
             return;
         } else if (breakVal == Constants.EN_COLUMN || breakVal <= 0) {
-            if (curPV.getCurrentSpan().hasMoreFlows()) {
-                curPV.getCurrentSpan().moveToNextFlow();
+            if (curPage.getPageViewport().getCurrentSpan().hasMoreFlows()) {
+                curPage.getPageViewport().getCurrentSpan().moveToNextFlow();
             } else {
-                curPV = makeNewPage(false, false);
+                curPage = makeNewPage(false, false);
             }
             return;
         }
         log.debug("handling break-before after page " + currentPageNum 
             + " breakVal=" + breakVal);
         if (needBlankPageBeforeNew(breakVal)) {
-            curPV = makeNewPage(true, false);
+            curPage = makeNewPage(true, false);
         }
         if (needNewPage(breakVal)) {
-            curPV = makeNewPage(false, false);
+            curPage = makeNewPage(false, false);
         }
     }
 
@@ -653,7 +664,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
      * @param breakVal - value of break-before or break-after trait.
      */
     private boolean needBlankPageBeforeNew(int breakVal) {
-        if (breakVal == Constants.EN_PAGE || (curPV.getPage().isEmpty())) {
+        if (breakVal == Constants.EN_PAGE || (curPage.getPageViewport().getPage().isEmpty())) {
             // any page is OK or we already have an empty page
             return false;
         } else {
@@ -671,7 +682,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
      * @param breakVal - value of break-before or break-after trait.
      */
     private boolean needNewPage(int breakVal) {
-        if (curPV.getPage().isEmpty()) {
+        if (curPage.getPageViewport().getPage().isEmpty()) {
             if (breakVal == Constants.EN_PAGE) {
                 return false;
             } else if (currentPageNum % 2 == 0) { // even page
@@ -686,7 +697,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
     
     
     /**
-     * <p>This class delivers PageViewport instances. It also caches them as necessary.
+     * <p>This class delivers Page instances. It also caches them as necessary.
      * </p>
      * <p>Additional functionality makes sure that surplus instances that are requested by the
      * page breaker are properly discarded, especially in situations where hard breaks cause
@@ -694,9 +705,9 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
      * additional pages since it doesn't know exactly until the end how many pages it really needs.
      * </p>
      */
-    public class PageViewportProvider {
+    public class PageProvider {
         
-        private Log log = LogFactory.getLog(PageViewportProvider.class);
+        private Log log = LogFactory.getLog(PageProvider.class);
 
         /** Indices are evaluated relative to the first page in the page-sequence. */
         public static final int RELTO_PAGE_SEQUENCE = 0;
@@ -706,7 +717,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         private int startPageOfPageSequence;
         private int startPageOfCurrentElementList;
         private int startColumnOfCurrentElementList;
-        private List cachedPageViewports = new java.util.ArrayList();
+        private List cachedPages = new java.util.ArrayList();
         
         //Cache to optimize getAvailableBPD() calls
         private int lastRequestedIndex = -1;
@@ -716,7 +727,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
          * Main constructor.
          * @param ps The page-sequence the provider operates on
          */
-        public PageViewportProvider(PageSequence ps) {
+        public PageProvider(PageSequence ps) {
             this.startPageOfPageSequence = ps.getStartingPageNumber();
         }
         
@@ -754,20 +765,20 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
             int c = index;
             int pageIndex = 0;
             int colIndex = startColumnOfCurrentElementList;
-            PageViewport pv = getPageViewport(
+            Page page = getPage(
                     false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
             while (c > 0) {
                 colIndex++;
-                if (colIndex >= pv.getCurrentSpan().getColumnCount()) {
+                if (colIndex >= page.getPageViewport().getCurrentSpan().getColumnCount()) {
                     colIndex = 0;
                     pageIndex++;
-                    pv = getPageViewport(
+                    page = getPage(
                             false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
                 }
                 c--;
             }
             this.lastRequestedIndex = index;
-            this.lastReportedBPD = pv.getBodyRegion().getRemainingBPD();
+            this.lastReportedBPD = page.getPageViewport().getBodyRegion().getRemainingBPD();
             if (log.isTraceEnabled()) {
                 log.trace("getAvailableBPD(" + index + ") -> " + lastReportedBPD);
             }
@@ -785,13 +796,13 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
             int idx = 0;
             int pageIndex = 0;
             int colIndex = startColumnOfCurrentElementList;
-            PageViewport pv = getPageViewport(
+            Page page = getPage(
                     false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
             while (idx < partCount) {
-                if ((colIndex >= pv.getCurrentSpan().getColumnCount())) {
+                if ((colIndex >= page.getPageViewport().getCurrentSpan().getColumnCount())) {
                     colIndex = 0;
                     pageIndex++;
-                    pv = getPageViewport(
+                    page = getPage(
                             false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
                     result = idx;
                 }
@@ -802,29 +813,29 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         }
 
         /**
-         * Returns a PageViewport.
+         * Returns a Page.
          * @param bIsBlank true if this page is supposed to be blank.
          * @param index Index of the page (see relativeTo)
          * @param relativeTo Defines which value the index parameter should be evaluated relative 
-         * to. (One of PageViewportProvider.RELTO_*)
-         * @return the requested PageViewport
+         * to. (One of PageProvider.RELTO_*)
+         * @return the requested Page
          */
-        public PageViewport getPageViewport(boolean bIsBlank, int index, int relativeTo) {
+        public Page getPage(boolean bIsBlank, int index, int relativeTo) {
             if (relativeTo == RELTO_PAGE_SEQUENCE) {
-                return getPageViewport(bIsBlank, index);
+                return getPage(bIsBlank, index);
             } else if (relativeTo == RELTO_CURRENT_ELEMENT_LIST) {
                 int effIndex = startPageOfCurrentElementList + index;
                 effIndex += startPageOfPageSequence - 1;
-                return getPageViewport(bIsBlank, effIndex);
+                return getPage(bIsBlank, effIndex);
             } else {
                 throw new IllegalArgumentException(
                         "Illegal value for relativeTo: " + relativeTo);
             }
         }
         
-        private PageViewport getPageViewport(boolean bIsBlank, int index) {
+        private Page getPage(boolean bIsBlank, int index) {
             if (log.isTraceEnabled()) {
-                log.trace("getPageViewport(" + index + " " + bIsBlank);
+                log.trace("getPage(" + index + " " + bIsBlank);
             }
             int intIndex = index - startPageOfPageSequence;
             if (log.isTraceEnabled()) {
@@ -832,27 +843,27 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
                     log.trace("blank page requested: " + index);
                 }
             }
-            while (intIndex >= cachedPageViewports.size()) {
+            while (intIndex >= cachedPages.size()) {
                 if (log.isTraceEnabled()) {
                     log.trace("Caching " + index);
                 }
-                cacheNextPageViewport(index, bIsBlank);
+                cacheNextPage(index, bIsBlank);
             }
-            PageViewport pv = (PageViewport)cachedPageViewports.get(intIndex);
-            if (pv.isBlank() != bIsBlank) {
+            Page page = (Page)cachedPages.get(intIndex);
+            if (page.getPageViewport().isBlank() != bIsBlank) {
                 log.debug("blank condition doesn't match. Replacing PageViewport.");
-                while (intIndex < cachedPageViewports.size()) {
-                    this.cachedPageViewports.remove(cachedPageViewports.size() - 1);
+                while (intIndex < cachedPages.size()) {
+                    this.cachedPages.remove(cachedPages.size() - 1);
                     if (!pageSeq.goToPreviousSimplePageMaster()) {
                         log.warn("goToPreviousSimplePageMaster() on the first page called!");
                     }
                 }
-                cacheNextPageViewport(index, bIsBlank);
+                cacheNextPage(index, bIsBlank);
             }
-            return pv;
+            return page;
         }
         
-        private void cacheNextPageViewport(int index, boolean bIsBlank) {
+        private void cacheNextPage(int index, boolean bIsBlank) {
             try {
                 String pageNumberString = pageSeq.makeFormattedPageNumber(index);
                 SimplePageMaster spm = pageSeq.getNextSimplePageMaster(
@@ -867,8 +878,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
                         + spm.getMasterName() + "'.  FOP presently "
                         + "does not support this.");
                 }
-                PageViewport pv = new PageViewport(spm, pageNumberString, bIsBlank);
-                cachedPageViewports.add(pv);
+                Page page = new Page(spm, pageNumberString, bIsBlank);
+                cachedPages.add(page);
             } catch (FOPException e) {
                 //TODO Maybe improve. It'll mean to propagate this exception up several
                 //methods calls.
index 39ce0c9b7493001f215524b9d6315863ec1bf5fc..8d7dfd207e1fc59c4ab087f5b3d195b856b49be9 100644 (file)
@@ -721,14 +721,14 @@ public class PSRenderer extends AbstractPathOrientedRenderer {
         }
         gen.writeDSCComment(DSCConstants.PAGE_RESOURCES, 
                 new Object[] {PSGenerator.ATEND});
-        gen.commentln("%FOPSimplePageMaster: " + page.getSPM().getMasterName());
+        gen.commentln("%FOPSimplePageMaster: " + page.getSimplePageMasterName());
         gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);
         
         //Handle PSSetupCode instances on simple-page-master
-        if (page.getSPM().getExtensionAttachments().size() > 0) {
+        if (page.getExtensionAttachments().size() > 0) {
             List list = new java.util.ArrayList();
             //Extract all PSSetupCode instances from the attachment list on the s-p-m
-            Iterator i = page.getSPM().getExtensionAttachments().iterator();
+            Iterator i = page.getExtensionAttachments().iterator();
             while (i.hasNext()) {
                 ExtensionAttachment attachment = (ExtensionAttachment)i.next();
                 if (PSSetupCode.CATEGORY.equals(attachment.getCategory())) {