From cebfaa1cff9666f54deed91bc032b2a1868dde6f Mon Sep 17 00:00:00 2001 From: William Victor Mote Date: Fri, 2 May 2003 18:54:10 +0000 Subject: [PATCH] Add params includeSelf and returnRoot to findNearestAncestorGeneratingRAs() for a more general solution. 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 | 39 ++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index c008b5ac9..ca33fdcc8 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -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()); } -- 2.39.5