diff options
author | Glen Mazza <gmazza@apache.org> | 2004-08-03 05:22:43 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-08-03 05:22:43 +0000 |
commit | a2894d22fa5606ccfe463ea5ac688bfb92abf9e6 (patch) | |
tree | 99691954cab8910dbc991adaa5029453e0e50a16 /src/java/org/apache | |
parent | dec1e96ca07e2a9ae6ef626eed7d89d3a0ebed9b (diff) | |
download | xmlgraphics-fop-a2894d22fa5606ccfe463ea5ac688bfb92abf9e6.tar.gz xmlgraphics-fop-a2894d22fa5606ccfe463ea5ac688bfb92abf9e6.zip |
Implemented validity checking for fo:bidi-override.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197851 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/fop/fo/AbstractCharIterator.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/FObj.java | 22 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/flow/BidiOverride.java | 86 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/flow/Inline.java | 46 |
4 files changed, 91 insertions, 65 deletions
diff --git a/src/java/org/apache/fop/fo/AbstractCharIterator.java b/src/java/org/apache/fop/fo/AbstractCharIterator.java index 9f310bf2d..d2e05ab4e 100644 --- a/src/java/org/apache/fop/fo/AbstractCharIterator.java +++ b/src/java/org/apache/fop/fo/AbstractCharIterator.java @@ -33,7 +33,7 @@ public abstract class AbstractCharIterator implements CharIterator, Cloneable { /** * @see org.apache.fop.fo.CharIterator#nextChar() */ - public abstract char nextChar() throws NoSuchElementException ; + public abstract char nextChar() throws NoSuchElementException; /** * @see java.util.Iterator#next() diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index a9272333b..3d8c69b1b 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -366,7 +366,7 @@ public class FObj extends FONode implements Constants { /** * Return an iterator over the object's childNodes starting - * at the pased node. + * at the passed-in node. * @param childNode First node in the iterator * @return A ListIterator or null if childNode isn't a child of * this FObj. @@ -529,5 +529,25 @@ public class FObj extends FONode implements Constants { || (!isOutOfLineFODescendant && lName.equals("float")) || lName.equals("retrieve-marker"))); } + + /** + * Convenience method for validity checking. Checks if the + * current node has an ancestor of a given name. + * @param ancestorName -- node name to check for (e.g., "fo:root") + * @return number of levels above FO where ancestor exists, + * -1 if not found + */ + protected int findAncestor(String ancestorName) { + int found = 1; + FONode temp = getParent(); + while (temp != null) { + if (temp.getName().equals(ancestorName)) { + return found; + } + found += 1; + temp = temp.getParent(); + } + return -1; + } } diff --git a/src/java/org/apache/fop/fo/flow/BidiOverride.java b/src/java/org/apache/fop/fo/flow/BidiOverride.java index b0cc8b0ec..9e0e37cfd 100644 --- a/src/java/org/apache/fop/fo/flow/BidiOverride.java +++ b/src/java/org/apache/fop/fo/flow/BidiOverride.java @@ -18,7 +18,13 @@ package org.apache.fop.fo.flow; +// XML +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXParseException; + // FOP +import org.apache.fop.fo.FOElementMapping; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObjMixed; import org.apache.fop.layoutmgr.AddLMVisitor; @@ -30,36 +36,72 @@ import org.apache.fop.fo.properties.CommonRelativePosition; */ public class BidiOverride extends FObjMixed { + // used for FO validation + private boolean blockOrInlineItemFound = false; + private boolean canHaveBlockLevelChildren = true; + /** * @param parent FONode that is the parent of this object */ public BidiOverride(FONode parent) { super(parent); - } - - private void setup() { - - // Common Aural Properties - CommonAural mAurProps = propMgr.getAuralProps(); + + /* Check to see if this node can have block-level children. + * See validateChildNode() below. + */ + int lvlLeader = findAncestor("fo:leader"); + int lvlInCntr = findAncestor("fo:inline-container"); + int lvlInline = findAncestor("fo:inline"); + int lvlFootnote = findAncestor("fo:footnote"); - // Common Font Properties - //this.fontState = propMgr.getFontState(area.getFontInfo()); + if (lvlLeader > 0) { + if (lvlInCntr < 0 || + (lvlInCntr > 0 && lvlInCntr > lvlLeader)) { + canHaveBlockLevelChildren = false; + } + } else if (lvlInline > 0 && lvlFootnote == (lvlInline + 1)) { + if (lvlInCntr < 0 || + (lvlInCntr > 0 && lvlInCntr > lvlInline)) { + canHaveBlockLevelChildren = false; + } + } - // Common Margin Properties-Inline - CommonRelativePosition mProps = propMgr.getRelativePositionProps(); + } - // this.propertyList.get("color"); - // this.propertyList.get("direction"); + /** + * @see org.apache.fop.fo.FObj#addProperties + */ + protected void addProperties(Attributes attlist) throws SAXParseException { + super.addProperties(attlist); setupID(); - // this.propertyList.get("letter-spacing"); - // this.propertyList.get("line-height"); - // this.propertyList.get("line-height-shift-adjustment"); - // this.propertyList.get("score-spaces"); - // this.propertyList.get("text-shadow"); - // this.propertyList.get("text-transform"); - // this.propertyList.get("unicode-bidi"); - // this.propertyList.get("word-spacing"); + } + /** + * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) + * XSL Content Model: marker* (#PCDATA|%inline;|%block;)* + * Additionally: "An fo:bidi-override that is a descendant of an fo:leader + * or of the fo:inline child of an fo:footnote may not have block-level + * children, unless it has a nearer ancestor that is an + * fo:inline-container." + */ + protected void validateChildNode(Locator loc, String nsURI, String localName) + throws SAXParseException { + if (nsURI == FOElementMapping.URI && localName.equals("marker")) { + if (blockOrInlineItemFound) { + nodesOutOfOrderError(loc, "fo:marker", + "(#PCDATA|%inline;|%block;)"); + } + } else if (!isBlockOrInlineItem(nsURI, localName)) { + invalidChildError(loc, nsURI, localName); + } else if (!canHaveBlockLevelChildren && isBlockItem(nsURI, localName)) { + invalidChildError(loc, nsURI, localName); + } else { + blockOrInlineItemFound = true; + } + } + + public String getName() { + return "fo:bidi-override"; } /** @@ -77,8 +119,4 @@ public class BidiOverride extends FObjMixed { public void acceptVisitor(AddLMVisitor aLMV) { aLMV.serveBidiOverride(this); } - - public String getName() { - return "fo:bidi-override"; - } } diff --git a/src/java/org/apache/fop/fo/flow/Inline.java b/src/java/org/apache/fop/fo/flow/Inline.java index adb33d0d1..61e654eb1 100644 --- a/src/java/org/apache/fop/fo/flow/Inline.java +++ b/src/java/org/apache/fop/fo/flow/Inline.java @@ -67,39 +67,7 @@ public class Inline extends FObjMixed { + " be directly under flow", locator); } - // Common Accessibility Properties - CommonAccessibility mAccProps = propMgr.getAccessibilityProps(); - - // Common Aural Properties - CommonAural mAurProps = propMgr.getAuralProps(); - - // Common Border, Padding, and Background Properties - CommonBorderAndPadding bap = propMgr.getBorderAndPadding(); - CommonBackground bProps = propMgr.getBackgroundProps(); - - // Common Font Properties - //this.fontState = propMgr.getFontState(area.getFontInfo()); - - // Common Margin Properties-Inline - CommonMarginInline mProps = propMgr.getMarginInlineProps(); - - // Common Relative Position Properties - CommonRelativePosition mRelProps = propMgr.getRelativePositionProps(); - - // this.propertyList.get("alignment-adjust"); - // this.propertyList.get("alignment-baseline"); - // this.propertyList.get("baseline-shift"); - // this.propertyList.get("color"); - // this.propertyList.get("dominant-baseline"); setupID(); - // this.propertyList.get("keep-together"); - // this.propertyList.get("keep-with-next"); - // this.propertyList.get("keep-with-previous"); - // this.propertyList.get("line-height"); - // this.propertyList.get("line-height-shift-adjustment"); - // this.propertyList.get("text-devoration"); - // this.propertyList.get("visibility"); - // this.propertyList.get("z-index"); int textDecoration = this.propertyList.get(PR_TEXT_DECORATION).getEnum(); @@ -119,6 +87,13 @@ public class Inline extends FObjMixed { } /** + * @see org.apache.fop.fo.FONode#end + */ + protected void endOfNode() throws SAXParseException { + getFOInputHandler().endInline(this); + } + + /** * @return true (Inline can contain Markers) */ protected boolean containsMarkers() { @@ -136,13 +111,6 @@ public class Inline extends FObjMixed { aLMV.serveInline(this); } - /** - * @see org.apache.fop.fo.FONode#end - */ - protected void endOfNode() throws SAXParseException { - getFOInputHandler().endInline(this); - } - public String getName() { return "fo:inline"; } |