001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: BidiOverride.java 488960 2006-12-20 08:34:28Z spepping $ */
019:
020: package org.apache.fop.fo.flow;
021:
022: import java.awt.Color;
023:
024: import org.apache.fop.apps.FOPException;
025: import org.apache.fop.fo.FONode;
026: import org.apache.fop.fo.FObjMixed;
027: import org.apache.fop.fo.PropertyList;
028: import org.apache.fop.fo.ValidationException;
029: import org.apache.fop.fo.properties.CommonAural;
030: import org.apache.fop.fo.properties.CommonFont;
031: import org.apache.fop.fo.properties.CommonRelativePosition;
032: import org.apache.fop.fo.properties.SpaceProperty;
033: import org.xml.sax.Locator;
034:
035: /**
036: * fo:bidi-override element.
037: */
038: public class BidiOverride extends FObjMixed {
039:
040: // used for FO validation
041: private boolean blockOrInlineItemFound = false;
042: private boolean canHaveBlockLevelChildren = true;
043: // The value of properties relevant for fo:bidi-override.
044: // private ToBeImplementedProperty prDirection;
045: // private ToBeImplementedProperty prLetterSpacing;
046: private SpaceProperty lineHeight;
047:
048: // private ToBeImplementedProperty prScoreSpaces;
049: // private ToBeImplementedProperty prUnicodeBidi;
050:
051: // Unused but valid items, commented out for performance:
052: // private CommonAural commonAural;
053: // private CommonFont commonFont;
054: // private CommonRelativePosition commonRelativePosition;
055: // private Color prColor;
056: // private SpaceProperty prWordSpacing;
057: // End of property values
058:
059: /**
060: * @param parent FONode that is the parent of this object
061: */
062: public BidiOverride(FONode parent) {
063: super (parent);
064:
065: /* Check to see if this node can have block-level children.
066: * See validateChildNode() below.
067: */
068: int lvlLeader = findAncestor(FO_LEADER);
069: int lvlInCntr = findAncestor(FO_INLINE_CONTAINER);
070: int lvlInline = findAncestor(FO_INLINE);
071: int lvlFootnote = findAncestor(FO_FOOTNOTE);
072:
073: if (lvlLeader > 0) {
074: if (lvlInCntr < 0
075: || (lvlInCntr > 0 && lvlInCntr > lvlLeader)) {
076: canHaveBlockLevelChildren = false;
077: }
078: } else if (lvlInline > 0 && lvlFootnote == (lvlInline + 1)) {
079: if (lvlInCntr < 0
080: || (lvlInCntr > 0 && lvlInCntr > lvlInline)) {
081: canHaveBlockLevelChildren = false;
082: }
083: }
084:
085: }
086:
087: /**
088: * @see org.apache.fop.fo.FObj#bind(PropertyList)
089: */
090: public void bind(PropertyList pList) throws FOPException {
091: // prDirection = pList.get(PR_DIRECTION);
092: // prLetterSpacing = pList.get(PR_LETTER_SPACING);
093: lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
094: // prScoreSpaces = pList.get(PR_SCORE_SPACES);
095: // prUnicodeBidi = pList.get(PR_UNICODE_BIDI);
096: }
097:
098: /**
099: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
100: * XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
101: * Additionally: "An fo:bidi-override that is a descendant of an fo:leader
102: * or of the fo:inline child of an fo:footnote may not have block-level
103: * children, unless it has a nearer ancestor that is an
104: * fo:inline-container."
105: */
106: protected void validateChildNode(Locator loc, String nsURI,
107: String localName) throws ValidationException {
108: if (FO_URI.equals(nsURI) && localName.equals("marker")) {
109: if (blockOrInlineItemFound) {
110: nodesOutOfOrderError(loc, "fo:marker",
111: "(#PCDATA|%inline;|%block;)");
112: }
113: } else if (!isBlockOrInlineItem(nsURI, localName)) {
114: invalidChildError(loc, nsURI, localName);
115: } else if (!canHaveBlockLevelChildren
116: && isBlockItem(nsURI, localName)) {
117: String ruleViolated = "An fo:bidi-override"
118: + " that is a descendant of an fo:leader or of the fo:inline child"
119: + " of an fo:footnote may not have block-level children, unless it"
120: + " has a nearer ancestor that is an fo:inline-container.";
121: invalidChildError(loc, nsURI, localName, ruleViolated);
122: } else {
123: blockOrInlineItemFound = true;
124: }
125: }
126:
127: /**
128: * @return the "line-height" property.
129: */
130: public SpaceProperty getLineHeight() {
131: return lineHeight;
132: }
133:
134: /** @see org.apache.fop.fo.FONode#getLocalName() */
135: public String getLocalName() {
136: return "bidi-override";
137: }
138:
139: /**
140: * @see org.apache.fop.fo.FObj#getNameId()
141: */
142: public int getNameId() {
143: return FO_BIDI_OVERRIDE;
144: }
145: }
|