]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
More code commenting and minor cleanup of bookmark/Resolvable/ATH code.
authorGlen Mazza <gmazza@apache.org>
Thu, 16 Dec 2004 23:59:13 +0000 (23:59 +0000)
committerGlen Mazza <gmazza@apache.org>
Thu, 16 Dec 2004 23:59:13 +0000 (23:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198202 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/area/AreaTreeHandler.java
src/java/org/apache/fop/area/BookmarkData.java
src/java/org/apache/fop/area/CachedRenderPagesModel.java
src/java/org/apache/fop/area/LinkResolver.java
src/java/org/apache/fop/area/PageViewport.java
src/java/org/apache/fop/area/RenderPagesModel.java
src/java/org/apache/fop/area/Resolvable.java
src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java

index 86611034cad7e51356dded11ab0ea61238aa8da0..68ac04914a08e2d7c63394d69caef43067d48bfe 100644 (file)
@@ -51,7 +51,7 @@ import org.apache.fop.layoutmgr.PageSequenceLayoutManager;
  * The area tree needs to be simple to render and follow the spec
  * closely.
  * This area tree has the concept of page sequences.
- * Where ever possible information is discarded or optimized to
+ * Wherever possible information is discarded or optimized to
  * keep memory use low. The data is also organized to make it
  * possible for renderers to minimize their output.
  * A page can be saved if not fully resolved and once rendered
@@ -82,11 +82,12 @@ public class AreaTreeHandler extends FOEventHandler {
     // The fo:root node of the document
     private Root rootFObj;
 
-    // HashMap of ID's whose area is located on one or more PageViewports
-    // Each ID has an arraylist of PageViewports sharing the area with this ID
+    // HashMap of ID's whose area is located on one or more consecutive 
+    // PageViewports.  Each ID has an arraylist of PageViewports that
+    // form the defined area of this ID
     private Map idLocations = new HashMap();
 
-    // idref's whose corresponding id's have yet to be found
+    // idref's whose target PageViewports have yet to be identified
     // Each idref has a HashSet of Resolvable objects containing that idref
     private Map unresolvedIDRefs = new HashMap();
 
@@ -136,8 +137,9 @@ public class AreaTreeHandler extends FOEventHandler {
             idLocations.put(id, pvList);
             pvList.add(pv);
 
-            /* See if this ID is in the unresolved idref list.  Note:
-             * unresolving occurs at first PV found for a given area. 
+            /* 
+             * See if this ID is in the unresolved idref list, if so
+             * resolve Resolvable objects tied to it.
              */
             Set todo = (Set) unresolvedIDRefs.get(id);
             if (todo != null) {
@@ -237,7 +239,6 @@ public class AreaTreeHandler extends FOEventHandler {
             PageSequenceLayoutManager pageSLM 
                 = new PageSequenceLayoutManager(this, pageSequence);
             pageSLM.activateLayout();
-            pageSequence.setCurrentPageNumber(pageSLM.getPageCount());
         }
     }
 
@@ -285,7 +286,7 @@ public class AreaTreeHandler extends FOEventHandler {
     private void addOffDocumentItem(OffDocumentItem odi) {
         if (odi instanceof Resolvable) {
             Resolvable res = (Resolvable) odi;
-            String[] ids = res.getIDs();
+            String[] ids = res.getIDRefs();
             for (int count = 0; count < ids.length; count++) {
                 if (idLocations.containsKey(ids[count])) {
                     res.resolveIDRef(ids[count], (List) idLocations.get(ids[count]));
index 5384a7cdf82076fd5566b74a9ca6c691e86ff0c0..9e814a0d97516492bd6504ffa70ef75ee9592d6c 100644 (file)
@@ -23,8 +23,9 @@ import java.util.List;
 import java.util.HashMap;
 
 /**
- * An instance of this class is either a PDF bookmark OffDocumentItem and
- * its child bookmarks.
+ * An instance of this class is either a PDF bookmark-tree and
+ * its child bookmark-items, or a bookmark-item and the child
+ * child bookmark-items under it.
  */
 public class BookmarkData extends OffDocumentItem implements Resolvable {
     private ArrayList subData = new ArrayList();
@@ -43,9 +44,8 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
 
     /**
      * Create a new bookmark data object.
-     * This should only be call by the top level element as its
-     * idref will be null.
-     *
+     * This should only be called by the bookmark-tree item because
+     * it has no idref item that needs to be resolved.
      */
     public BookmarkData() {
         idRef = null;
@@ -54,22 +54,23 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
 
     /**
      * Create a new pdf bookmark data object.
-     * This is used by the outlines to create a data object
-     * with a id reference. The id reference is to be resolved.
+     * This is used by the bookmark-items to create a data object
+     * with a idref.  During processing, this idref will be
+     * subsequently resolved to a particular PageViewport.
      *
-     * @param id the id reference
+     * @param idref the id reference
      */
-    public BookmarkData(String id) {
-        idRef = id;
+    public BookmarkData(String idref) {
+        this.idRef = idref;
         unresolvedIDRefs.put(idRef, this);
     }
 
     /**
-     * Get the id reference for this data.
+     * Get the idref for this bookmark-item
      *
-     * @return the id reference
+     * @return the idref for the bookmark-item
      */
-    public String getID() {
+    public String getIDRef() {
         return idRef;
     }
 
@@ -81,8 +82,8 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
      */
     public void addSubData(BookmarkData sub) {
         subData.add(sub);
-        unresolvedIDRefs.put(sub.getID(), sub);
-        String[] ids = sub.getIDs();
+        unresolvedIDRefs.put(sub.getIDRef(), sub);
+        String[] ids = sub.getIDRefs();
         for (int count = 0; count < ids.length; count++) {
             unresolvedIDRefs.put(ids[count], sub);
         }
@@ -136,63 +137,46 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
 
     /**
      * Check if this resolvable object has been resolved.
-     * Once the id reference is null then it has been resolved.
+     * A BookmarkData object is considered resolved once the idrefs for it
+     * and for all of its child bookmark-items have been resolved.
      *
-     * @return true if this has been resolved
+     * @return true if this object has been resolved
      */
     public boolean isResolved() {
-        return unresolvedIDRefs == null;
+        return unresolvedIDRefs == null || (unresolvedIDRefs.size() == 0);
     }
 
     /**
-     * Get the id references held by this object.
-     * Also includes all id references of all children.
-     *
-     * @return the array of id references
+     * @see org.apache.fop.area.Resolvable#getIDRefs()
      */
-    public String[] getIDs() {
+    public String[] getIDRefs() {
         return (String[])unresolvedIDRefs.keySet().toArray(new String[] {});
     }
 
     /**
      * Resolve this resolvable object.
-     * This resolves the id reference and if possible also
+     * This resolves the idref of this object and if possible also
      * resolves id references of child elements that have the same
      * id reference.
      *
-     * @param id the ID which has already been resolved to one or more
-     *      PageViewport objects
-     * @param pages the list of PageViewport objects the ID resolves to
+     * @see org.apache.fop.area.Resolvable#resolveIDRef(String, List)
+     * @todo check to make sure works when multiple bookmark-items
+     * have the same idref
      */
     public void resolveIDRef(String id, List pages) {
-        // this method is buggy
         if (!id.equals(idRef)) {
-            BookmarkData bd = (BookmarkData)unresolvedIDRefs.get(id);
-            unresolvedIDRefs.remove(id);
+            BookmarkData bd = (BookmarkData) unresolvedIDRefs.get(id);
             if (bd != null) {
                 bd.resolveIDRef(id, pages);
-                if (bd.isResolved()) {
-                    checkFinish();
-                }
-            } else if (idRef == null) {
-                checkFinish();
+                unresolvedIDRefs.remove(id);
             }
         } else {
-            if (pages != null) {
-                pageRef = (PageViewport)pages.get(0);
-            }
+            pageRef = (PageViewport) pages.get(0);
             // TODO get rect area of id on page
             unresolvedIDRefs.remove(idRef);
-            checkFinish();
         }
     }
 
-    private void checkFinish() {
-        if (unresolvedIDRefs.size() == 0) {
-            unresolvedIDRefs = null;
-        }
-    }
-    
     /**
      * @see org.apache.fop.area.OffDocumentItem#getName()
      */
index 18e003cb97b5d014d2d7db4a4e5b79a7b3a2c737..d09f000019a66318f8e7a433c31f83e36199ceca 100644 (file)
@@ -81,7 +81,7 @@ public class CachedRenderPagesModel extends RenderPagesModel {
                 try {
                     renderer.renderPage(p);
                     if (!p.isResolved()) {
-                        String[] idrefs = p.getIDs();
+                        String[] idrefs = p.getIDRefs();
                         for (int count = 0; count < idrefs.length; count++) {
                             log.warn("Page " + p.getPageNumber() + 
                                 ": Unresolved id reference \"" + idrefs[count] 
index cbc38095a6c96bbc225f365adc366154f0158dd6..c3c0830d370a786a028e0e520a717f637fd22128 100644 (file)
@@ -54,7 +54,7 @@ public class LinkResolver implements Resolvable, Serializable {
         return resolved;
     }
 
-    public String[] getIDs() {
+    public String[] getIDRefs() {
         return new String[] {idRef};
     }
 
index 94d0b9f94dd1aedf458fc96a8f7a787204d6d013..74a491614a60c09e751304d811b261139b17c542 100644 (file)
@@ -157,7 +157,7 @@ public class PageViewport implements Resolvable, Cloneable {
      * Get the unresolved idrefs for this page.
      * @return String array of idref's that still have not been resolved
      */
-    public String[] getIDs() {
+    public String[] getIDRefs() {
         return (unresolvedIDRefs == null) ? null :
             (String[]) unresolvedIDRefs.keySet().toArray(new String[] {});
     }
index 8a188b99bd17a03037c5c050cf027d3def130d7e..c28b7fb6105d86a4912e1acfd9ff5742f8ef3bb8 100644 (file)
@@ -149,7 +149,7 @@ public class RenderPagesModel extends StorePagesModel {
                 try {
                     renderer.renderPage(p);
                     if (!p.isResolved()) {
-                        String[] idrefs = p.getIDs();
+                        String[] idrefs = p.getIDRefs();
                         for (int count = 0; count < idrefs.length; count++) {
                             log.warn("Page " + p.getPageNumber() + 
                                 ": Unresolved id reference \"" + idrefs[count] 
index 7d1da2c23ad1daa2acc8c69d94943b5155ee5f96..e8ad3f791d6e8df66baa5e8dc8f004472b976517 100644 (file)
@@ -42,7 +42,7 @@ public interface Resolvable {
      *
      * @return the id references for resolving this object
      */
-    String[] getIDs();
+    String[] getIDRefs();
 
     /**
      * This method allows the Resolvable object to resolve one of
index 30db0d7e8eb15e87a6a500c1a7bf4b7f42183785..09115fdf8ff1fa5b5171afe1a4da94815ae780d0 100644 (file)
@@ -47,7 +47,7 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable {
      *
      * @return the id reference for this unresolved page number
      */
-    public String[] getIDs() {
+    public String[] getIDRefs() {
         return new String[] {pageIDRef};
     }
 
index 4ac067b08e5c320db73d233c37e7c4445f2a2ae6..4af6295003104bdad147cd56d2a0313c510a39dd 100644 (file)
@@ -226,6 +226,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
         pageCount--;
         log.debug("Ending layout");
         flush();
+        fobj.setCurrentPageNumber(getPageCount());
     }
 
     /**