]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
AHS: initial marker support
authorarved <arved@unknown>
Mon, 16 Jul 2001 10:46:14 +0000 (10:46 +0000)
committerarved <arved@unknown>
Mon, 16 Jul 2001 10:46:14 +0000 (10:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194356 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/fo/flow/Marker.java
src/org/apache/fop/fo/flow/RetrieveMarker.java
src/org/apache/fop/fo/pagination/PageSequence.java
src/org/apache/fop/fo/pagination/Root.java
src/org/apache/fop/layout/Area.java
src/org/apache/fop/layout/AreaClass.java [new file with mode: 0644]
src/org/apache/fop/layout/Page.java

index fc86e16be6e376409b045abf75d92917cc734d08..627d985421ea85f1d6e6efc539d462e8912e712a 100644 (file)
@@ -1,4 +1,5 @@
-/*-- $Id$ --
+/*-- $Id$-- */
+/*
  * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  * For details on use and redistribution please refer to the
  * LICENSE file included with these sources.
@@ -9,30 +10,74 @@ package org.apache.fop.fo.flow;
 // FOP
 import org.apache.fop.fo.*;
 import org.apache.fop.messaging.MessageHandler;
-import org.apache.fop.fo.flow.*;
 import org.apache.fop.fo.properties.*;
-import org.apache.fop.layout.AreaTree;
+import org.apache.fop.layout.*;
+import org.apache.fop.datatypes.*;
 import org.apache.fop.apps.FOPException;
 
-/**
- */
-public class Marker extends ToBeImplementedElement {
+public class Marker extends FObjMixed {
+
+       private String markerClassName;
+       private Area registryArea;
+       
+       public static class Maker extends FObj.Maker {
+               public FObj make(FObj parent, PropertyList propertyList) throws FOPException {
+                               return new Marker(parent, propertyList);
+               }
+       }
+
+       public static FObj.Maker maker() {
+               return new Marker.Maker();
+       }
 
-    public static class Maker extends FObj.Maker {
-        public FObj make(FObj parent,
-                         PropertyList propertyList) throws FOPException {
-            return new Marker(parent, propertyList);
-        }
-    }
+       public Marker(FObj parent, PropertyList propertyList) {
+               super(parent, propertyList);
+               this.name = "fo:marker";
+               
+               // do check to see that 'this' is under fo:flow
+               
+               this.markerClassName = this.properties.get("marker-class-name").getString();
+               
+               // check to ensure that no other marker with same parent
+               // has this 'marker-class-name' is in addMarker() method
+               try {
+                       parent.addMarker(this);
+               } catch (FOPException fopex) {
+                       MessageHandler.error("marker cannot be added to '" + parent + "'");
+               }
+       }
 
-    public static FObj.Maker maker() {
-        return new Marker.Maker();
-    }
+         public Status layout(Area area) throws FOPException {
+               // no layout action desired
+               this.registryArea = area;
+               area.getPage().registerMarker(this);
+               // System.out.println("Marker being registered in area '" + area + "'");
+               return new Status(Status.OK);
+         }
 
-    protected Marker(FObj parent,
-                   PropertyList propertyList) throws FOPException {
-        super(parent, propertyList);
-        this.name = "fo:marker";
-    }
+       public Status layoutMarker(Area area) throws FOPException {
+               if (this.marker == START)
+                       this.marker = 0;
+                       
+               int numChildren = this.children.size();
+               for (int i = this.marker; i < numChildren; i++) {
+                       FONode fo = (FONode) children.elementAt(i);
+       
+                       Status status;
+                       if ((status = fo.layout(area)).isIncomplete()) {
+                       this.marker = i;
+                       return status;
+                       }
+               }
+       
+               return new Status(Status.OK);
+       }
 
+       public String getMarkerClassName() {
+               return markerClassName;
+       }
+       
+       public Area getRegistryArea() {
+               return registryArea;
+       }
 }
index 9f1f353694d11e46f2be08fff2c3a7ef885d0ac4..c1e092eaebfcae9be2f91835c076380f4c40cfb8 100644 (file)
@@ -1,4 +1,5 @@
-/*-- $Id$ --
+/*-- $Id$-- */
+/*
  * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  * For details on use and redistribution please refer to the
  * LICENSE file included with these sources.
@@ -9,30 +10,110 @@ package org.apache.fop.fo.flow;
 // FOP
 import org.apache.fop.fo.*;
 import org.apache.fop.messaging.MessageHandler;
-import org.apache.fop.fo.flow.*;
 import org.apache.fop.fo.properties.*;
-import org.apache.fop.layout.AreaTree;
+import org.apache.fop.layout.*;
+import org.apache.fop.datatypes.*;
 import org.apache.fop.apps.FOPException;
 
-/**
- */
-public class RetrieveMarker extends ToBeImplementedElement {
+// Java
+import java.util.Vector;
+
+public class RetrieveMarker extends FObjMixed {
 
-    public static class Maker extends FObj.Maker {
-        public FObj make(FObj parent,
-                         PropertyList propertyList) throws FOPException {
-            return new RetrieveMarker(parent, propertyList);
-        }
-    }
+       private String retrieveClassName;
+       private int retrievePosition;
+       private int retrieveBoundary;
+       
+       public static class Maker extends FObj.Maker {
+               public FObj make(FObj parent, PropertyList propertyList) throws FOPException {
+                               return new RetrieveMarker(parent, propertyList);
+               }
+       }
 
-    public static FObj.Maker maker() {
-        return new RetrieveMarker.Maker();
-    }
+       public static FObj.Maker maker() {
+               return new RetrieveMarker.Maker();
+       }
 
-    protected RetrieveMarker(FObj parent,
-                   PropertyList propertyList) throws FOPException {
-        super(parent, propertyList);
-        this.name = "fo:retrieve-marker";
-    }
+       public RetrieveMarker(FObj parent, PropertyList propertyList) {
+               super(parent, propertyList);
+               this.name = "fo:retrieve-marker";
+       
+               this.retrieveClassName = this.properties.get("retrieve-class-name").getString();
+               this.retrievePosition = this.properties.get("retrieve-position").getEnum();
+               this.retrieveBoundary = this.properties.get("retrieve-boundary").getEnum();
+       }
 
+       public Status layout(Area area) throws FOPException {
+               // locate qualifying areas by 'marker-class-name' and
+               // 'retrieve-boundary'. Initially we will always check
+               // the containing page
+               Page containingPage = area.getPage();
+               Marker bestMarker = searchPage(containingPage);
+               
+               // if marker not yet found, and 'retrieve-boundary' permits,
+               // search forward by Page
+               /* insert code for searching forward by Page, if allowed */
+               
+               Status status = new Status(Status.AREA_FULL_NONE);
+               if (null != bestMarker) {
+                       // System.out.println("Laying out marker in area '" + area + "'");
+                       status = bestMarker.layoutMarker(area);
+               }
+               
+               return status;
+       }
+       
+       private Marker searchPage(Page page) throws FOPException {
+               Vector pageMarkers = page.getMarkers();
+               if (pageMarkers.isEmpty())
+                       return null;
+                       
+               // 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))
+                                       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)
+                                               return currentMarker;
+                                       else if (null == fallback)
+                                               fallback = currentMarker;
+                               }
+                       }
+                       
+               } else if (retrievePosition == RetrievePosition.LSWP) {
+                       for (int c = pageMarkers.size(); c > 0; c--) {
+                               Marker currentMarker = (Marker)pageMarkers.elementAt(c-1);
+                               if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
+                                       if (currentMarker.getRegistryArea().isFirst)
+                                               return currentMarker;
+                                       else if (null == fallback)
+                                               fallback = currentMarker;
+                               }
+                       }       
+                       
+               } else if (retrievePosition == RetrievePosition.LEWP) {
+                       for (int c = pageMarkers.size(); c > 0; c--) {
+                               Marker currentMarker = (Marker)pageMarkers.elementAt(c-1);
+                               if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
+                                       if (currentMarker.getRegistryArea().isLast)
+                                               return currentMarker;
+                                       else if (null == fallback)
+                                               fallback = currentMarker;
+                               }
+                       }       
+                       
+               } else {
+                       throw new FOPException("Illegal 'retrieve-position' value");
+               }
+               return fallback;
+       }
 }
index d24b988f540d1eadd7b4f9465a0c9905e3ba2c04..6e5cd65e86b572a5faebc90f315b18b3fc8da231 100644 (file)
@@ -241,8 +241,6 @@ public class PageSequence extends FObj {
 
             MessageHandler.log(" [" + currentPageNumber);
 
-            formatStaticContent(areaTree);
-
             if ((status.getCode() == Status.FORCE_PAGE_BREAK_EVEN) &&
                     ((currentPageNumber % 2) == 1)) {
             } else if ( (status.getCode() == Status.FORCE_PAGE_BREAK_ODD) &&
@@ -265,6 +263,10 @@ public class PageSequence extends FObj {
                 }
 
             }
+
+                       // because of markers, do after fo:flow
+            formatStaticContent(areaTree);
+
             MessageHandler.log("]");
             areaTree.addPage(currentPage);
                        this.pageCount++;       // used for 'force-page-count' calculations
index 9d5a8b899582cf5a0a926df9367ce4d664d4bfa9..14192eed1d66a824f2d5162f8fdebe05de02a9be 100644 (file)
@@ -48,6 +48,7 @@ public class Root extends FObj {
         this.name = "fo:root";
 
         pageSequences = new Vector();
+               
         if (parent != null) {
             throw new FOPException("root must be root element");
         }
index 247a048782a144ff8d1c1a364724f485b962074f..fc10ebf0669302d46e25599bfb45f99e52dd9b28 100644 (file)
@@ -8,9 +8,11 @@ package org.apache.fop.layout;
 
 // FOP
 import org.apache.fop.datatypes.*;
+import org.apache.fop.fo.flow.Marker;
 
 // Java
 import java.util.Vector;
+import java.util.Hashtable;
 
 abstract public class Area extends Box {
 
@@ -46,12 +48,29 @@ abstract public class Area extends Box {
 
     private IDReferences idReferences;
 
+       protected Vector markers;
+       
+       // as defined in Section 6.1.1
+       public org.apache.fop.fo.FObj generatedBy;      // corresponds to 'generated-by' trait
+       protected Hashtable returnedBy;
+       
+       // as defined in Section 6.1.1
+       protected String areaClass;
+       
+       // as defined in Section 4.2.2
+       public boolean isFirst = false;
+       public boolean isLast = false;
+       
     /* author : Seshadri G
     ** the fo which created it */      
+       // This is deprecated and should be phased out in
+       // favour of using 'generatedBy'
     public org.apache.fop.fo.FObj foCreator;   
         
     public Area (FontState fontState) {
-       setFontState(fontState);
+               setFontState(fontState);
+               this.markers = new Vector();
+               this.returnedBy = new Hashtable();
     }
 
     /**
@@ -64,10 +83,12 @@ abstract public class Area extends Box {
      * for this Area (its allocation rectangle)
      */
     public Area (FontState fontState, int allocationWidth, int maxHeight) {
-       setFontState(fontState);
+               setFontState(fontState);
         this.allocationWidth = allocationWidth;
         this.contentRectangleWidth = allocationWidth;
         this.maxHeight = maxHeight;
+               this.markers = new Vector();
+               this.returnedBy = new Hashtable();
     }
 
   private void setFontState(FontState fontState) {
@@ -340,4 +361,11 @@ abstract public class Area extends Box {
     return bp;
   }
 
+  public void addMarkers(Vector markers) {
+         markers.addAll(markers);
+  }
+  
+  public void addLineagePair(org.apache.fop.fo.FObj fo, int areaPosition) {
+         returnedBy.put(fo, new Integer(areaPosition));
+  }
 }
diff --git a/src/org/apache/fop/layout/AreaClass.java b/src/org/apache/fop/layout/AreaClass.java
new file mode 100644 (file)
index 0000000..764fd6c
--- /dev/null
@@ -0,0 +1,31 @@
+/* $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.layout;
+
+import org.apache.fop.apps.FOPException;
+
+public class AreaClass {
+       public static String UNASSIGNED = "unassigned";
+
+       public static String XSL_NORMAL = "xsl-normal";
+       public static String XSL_ABSOLUTE = "xsl-absolute";
+       public static String XSL_FOOTNOTE = "xsl-footnote";
+       public static String XSL_SIDE_FLOAT = "xsl-side-float";
+       public static String XSL_BEFORE_FLOAT = "xsl-before-float";
+       
+       // checker method
+       public static String setAreaClass(String areaClass)
+               throws FOPException {
+               if (areaClass.equals(XSL_NORMAL) || areaClass.equals(XSL_ABSOLUTE) ||
+                       areaClass.equals(XSL_FOOTNOTE) || areaClass.equals(XSL_SIDE_FLOAT) ||
+                       areaClass.equals(XSL_BEFORE_FLOAT))
+                       return areaClass;
+               else
+                       throw new FOPException("Unknown area class '" + areaClass + "'");
+       }
+}
+
index fe1d163326ee8321dba1cb1828fb01bc39896e1f..73c5b1ce65f94ad6bac5c18cc5ecd2f876642827 100644 (file)
@@ -38,10 +38,13 @@ public class Page {
 
     private Vector footnotes = null;
 
+       private Vector markers = null;
+       
     Page(AreaTree areaTree, int height, int width) {
        this.areaTree = areaTree;
        this.height = height;
        this.width = width;
+       markers = new Vector();
     }
 
     public void setNumber(int number) {
@@ -172,4 +175,12 @@ public class Page {
         }
         footnotes.addElement(fb);
     }
+       
+       public void registerMarker(Marker marker) {
+               markers.addElement(marker);
+       }
+       
+       public Vector getMarkers() {
+               return this.markers;
+       }
 }