]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Add params includeSelf and returnRoot to findNearestAncestorGeneratingRAs() for a...
authorWilliam Victor Mote <vmote@apache.org>
Fri, 2 May 2003 18:54:10 +0000 (18:54 +0000)
committerWilliam Victor Mote <vmote@apache.org>
Fri, 2 May 2003 18:54:10 +0000 (18:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196391 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/FObj.java

index c008b5ac90d24d78cb6066db786fe94e63dd701b..ca33fdcc8936df36a68570a805d35ea8ab0332c5 100644 (file)
@@ -173,20 +173,43 @@ public class FObj extends FONode {
     }
 
     /**
-     * Find nearest ancestor, including self, which generates
-     * reference areas.
-     * If no such ancestor is found, use the value on the root FO.
+     * Find nearest ancestor which generates Reference Areas.
      *
+     * @param includeSelf Set to true to consider the current FObj as an
+     * "ancestor". Set to false to only return a true ancestor.
+     * @param returnRoot Supposing a condition where no appropriate ancestor
+     * FObj is found, setting returnRoot to true will return the FObj with no
+     * parent (presumably the root FO). Otherwise, null will be returned.
+     * Note that this will override a false setting for includeSelf, and return
+     * the current node if it is the root FO. Setting returnRoot to true should
+     * always return a valid FObj.
      * @return FObj of the nearest ancestor that generates Reference Areas
+     * and fits the parameters.
      */
-    private FObj findNearestAncestorGeneratingRAs() {
+    private FObj findNearestAncestorGeneratingRAs(boolean includeSelf,
+                                                  boolean returnRoot) {
         FObj p = this;
+        if (includeSelf && p.generatesReferenceAreas()) {
+            return p;
+        }
         FObj parent = p.findNearestAncestorFObj();
-        while (parent != null && !p.generatesReferenceAreas()) {
-            p = (FObj) parent;
+        if (parent == null && returnRoot) {
+            return p;
+        }
+        do {
+            p = parent;
             parent = p.findNearestAncestorFObj();
+        } while (parent != null && !p.generatesReferenceAreas());
+        if (p.generatesReferenceAreas()) {
+            return p;
+        }
+        // if we got here, it is because parent is null
+        if (returnRoot) {
+            return p;
+        }
+        else {
+            return null;
         }
-        return p;
     }
 
     public PropertyList getPropertiesForNamespace(String nameSpaceURI) {
@@ -304,7 +327,7 @@ public class FObj extends FONode {
      * reference areas, or from root FO if no ancestor found.
      */
     protected void setWritingMode() {
-        FObj p = findNearestAncestorGeneratingRAs();
+        FObj p = findNearestAncestorGeneratingRAs(true, true);
         this.properties.setWritingMode(
           p.getProperty("writing-mode").getEnum());
     }