]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
AHS: continued work on fo:marker support
authorarved <arved@unknown>
Mon, 23 Jul 2001 02:00:37 +0000 (02:00 +0000)
committerarved <arved@unknown>
Mon, 23 Jul 2001 02:00:37 +0000 (02:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194364 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/fo/flow/RetrieveMarker.java
src/org/apache/fop/fo/pagination/PageSequence.java
src/org/apache/fop/layout/AreaTree.java
src/org/apache/fop/layout/Page.java

index c1e092eaebfcae9be2f91835c076380f4c40cfb8..10e1300c7954d94e96c4a1b3e78d51d6050d2251 100644 (file)
@@ -48,44 +48,72 @@ public class RetrieveMarker extends FObjMixed {
                // 'retrieve-boundary'. Initially we will always check
                // the containing page
                Page containingPage = area.getPage();
-               Marker bestMarker = searchPage(containingPage);
+               Marker bestMarker = searchPage(containingPage, true);
                
                // if marker not yet found, and 'retrieve-boundary' permits,
                // search forward by Page
-               /* insert code for searching forward by Page, if allowed */
+               if ((null == bestMarker) && (retrieveBoundary != RetrieveBoundary.PAGE)) {
+                       // System.out.println("Null bestMarker and searching...");
+                       Page currentPage = containingPage;
+                       boolean isFirstCall = true;
+                       while (bestMarker == null) {
+                               Page previousPage =
+                                       locatePreviousPage(currentPage, retrieveBoundary, isFirstCall);
+                               isFirstCall = false;
+                               // System.out.println("Previous page = '" + previousPage + "'");
+                               bestMarker = searchPage(previousPage, false);
+                               currentPage = previousPage;
+                       }
+               }
                
                Status status = new Status(Status.AREA_FULL_NONE);
                if (null != bestMarker) {
-                       // System.out.println("Laying out marker in area '" + area + "'");
+                       // System.out.println("Laying out marker '" + bestMarker + "' in area '" + area + "'");
+                       // the 'markers' referred to in this method are internal; they have
+                       // nothing to do with fo:marker
+                       bestMarker.resetMarker();
                        status = bestMarker.layoutMarker(area);
                }
                
                return status;
        }
        
-       private Marker searchPage(Page page) throws FOPException {
+       private Marker searchPage(Page page, boolean isContainingPage)
+               throws FOPException {
                Vector pageMarkers = page.getMarkers();
-               if (pageMarkers.isEmpty())
+               if (pageMarkers.isEmpty()) {
+                       // System.out.println("No markers on page");
                        return null;
-                       
+               }
+               
+               // if no longer the containing page (fo:retrieve-marker, or the page
+               // being processed), grab the last qualifying marker on this one
+               if (!isContainingPage) {
+                       for (int c = pageMarkers.size(); c > 0; c--) {
+                               Marker currentMarker = (Marker)pageMarkers.elementAt(c-1);
+                               if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
+                                       return currentMarker;
+                               }
+                       }       
+               }
+               
                // search forward if 'first-starting-within-page' or
                // 'first-including-carryover'
-               Marker fallback = null;
                if (retrievePosition == RetrievePosition.FIC) {
                        for (int c = 0; c < pageMarkers.size(); c++) {
                                Marker currentMarker = (Marker)pageMarkers.elementAt(c);
-                               if (currentMarker.getMarkerClassName().equals(retrieveClassName))
+                               if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
                                        return currentMarker;
+                               }
                        }
                        
                } else if (retrievePosition == RetrievePosition.FSWP) {
                        for (int c = 0; c < pageMarkers.size(); c++) {
                                Marker currentMarker = (Marker)pageMarkers.elementAt(c);
                                if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
-                                       if (currentMarker.getRegistryArea().isFirst)
+                                       if (currentMarker.getRegistryArea().isFirst) {
                                                return currentMarker;
-                                       else if (null == fallback)
-                                               fallback = currentMarker;
+                                       }
                                }
                        }
                        
@@ -93,10 +121,9 @@ public class RetrieveMarker extends FObjMixed {
                        for (int c = pageMarkers.size(); c > 0; c--) {
                                Marker currentMarker = (Marker)pageMarkers.elementAt(c-1);
                                if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
-                                       if (currentMarker.getRegistryArea().isFirst)
+                                       if (currentMarker.getRegistryArea().isFirst) {
                                                return currentMarker;
-                                       else if (null == fallback)
-                                               fallback = currentMarker;
+                                       }
                                }
                        }       
                        
@@ -104,16 +131,24 @@ public class RetrieveMarker extends FObjMixed {
                        for (int c = pageMarkers.size(); c > 0; c--) {
                                Marker currentMarker = (Marker)pageMarkers.elementAt(c-1);
                                if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
-                                       if (currentMarker.getRegistryArea().isLast)
+                                       if (currentMarker.getRegistryArea().isLast) {
                                                return currentMarker;
-                                       else if (null == fallback)
-                                               fallback = currentMarker;
+                                       }
                                }
                        }       
                        
                } else {
                        throw new FOPException("Illegal 'retrieve-position' value");
                }
-               return fallback;
+               return null;
+       }
+       
+       private Page locatePreviousPage(Page page, int retrieveBoundary,
+               boolean isFirstCall) {
+               boolean pageWithinSequence = true;
+               if (retrieveBoundary == RetrieveBoundary.DOCUMENT)
+                       pageWithinSequence = false;
+               return page.getAreaTree().getPreviousPage(page, pageWithinSequence,
+                       isFirstCall);
        }
 }
index 6e5cd65e86b572a5faebc90f315b18b3fc8da231..de8e731be2d94b1a2a1ab419f2a651305cd2aabb 100644 (file)
@@ -264,7 +264,9 @@ public class PageSequence extends FObj {
 
             }
 
-                       // because of markers, do after fo:flow
+                       // because of markers, do after fo:flow (likely also
+                       // justifiable because of spec)
+                       currentPage.setPageSequence(this);
             formatStaticContent(areaTree);
 
             MessageHandler.log("]");
@@ -627,6 +629,7 @@ public class PageSequence extends FObj {
                        String formattedPageNumber =
                                pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber);
                        currentPage.setFormattedNumber(formattedPageNumber);
+                       currentPage.setPageSequence(this);
                        formatStaticContent(areaTree);
                        MessageHandler.log("[forced-" + firstAvailPageNumber + "]");
                        areaTree.addPage(currentPage);
index a0195082df35c10afe0e6e629a50f4da2d956f0f..315230d9f1490162567caa6a8ebff96cd6e08870 100644 (file)
@@ -13,6 +13,7 @@ import org.apache.fop.svg.*;
 import org.apache.fop.render.Renderer;
 import org.apache.fop.datatypes.IDReferences;
 import org.apache.fop.extensions.ExtensionObj;
+import org.apache.fop.fo.pagination.PageSequence;
 
 // Java
 import java.io.IOException;
@@ -67,5 +68,43 @@ public class AreaTree {
        return rootExtensions;
     }
     
+       public Page getNextPage(Page current, boolean isWithinPageSequence,     
+               boolean isFirstCall) {
+               Page nextPage = null;
+               int pageIndex = 0;
+               if (isFirstCall)
+                       pageIndex = pageList.size();
+               else
+                       pageIndex = pageList.indexOf(current);
+               if ((pageIndex + 1) < pageList.size()) {
+                       nextPage = (Page)pageList.elementAt(pageIndex + 1);
+                       if (isWithinPageSequence && !nextPage.getPageSequence().equals(current.getPageSequence())) {
+                               nextPage = null;
+                       }
+               }
+               return nextPage;
+       }
 
+       public Page getPreviousPage(Page current, boolean isWithinPageSequence,
+               boolean isFirstCall) {
+               Page previousPage = null;
+               int pageIndex = 0;
+               if (isFirstCall)
+                       pageIndex = pageList.size();
+               else
+                       pageIndex = pageList.indexOf(current);
+               // System.out.println("Page index = " + pageIndex);
+               if ((pageIndex - 1) >= 0) {
+                       previousPage = (Page)pageList.elementAt(pageIndex - 1);
+                       PageSequence currentPS = current.getPageSequence();
+                       // System.out.println("Current PS = '" + currentPS + "'");
+                       PageSequence previousPS = previousPage.getPageSequence();
+                       // System.out.println("Previous PS = '" + previousPS + "'");
+                       if (isWithinPageSequence && !previousPS.equals(currentPS)) {
+                               // System.out.println("Outside page sequence");
+                               previousPage = null;
+                       }
+               }
+               return previousPage;
+       }
 }
index 73c5b1ce65f94ad6bac5c18cc5ecd2f876642827..0b837317f105323e2fdc1929835c283b7a0c32cc 100644 (file)
@@ -11,6 +11,7 @@ import org.apache.fop.render.Renderer;
 import org.apache.fop.fo.flow.*;
 import org.apache.fop.fo.*;
 import org.apache.fop.apps.*;
+import org.apache.fop.fo.pagination.PageSequence;
 
 // Java
 import java.util.Vector;
@@ -29,6 +30,8 @@ public class Page {
        
     private AreaTree areaTree;
 
+       private PageSequence pageSequence;
+       
     protected int pageNumber = 0;
        protected String formattedPageNumber;
        
@@ -47,6 +50,18 @@ public class Page {
        markers = new Vector();
     }
 
+       public void setPageSequence(PageSequence pageSequence) {
+               this.pageSequence = pageSequence;
+       }
+       
+       public PageSequence getPageSequence() {
+               return pageSequence;
+       }
+       
+       public AreaTree getAreaTree() {
+               return areaTree;
+       }
+       
     public void setNumber(int number) {
        this.pageNumber = number;
     }