You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Inline.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.fo.flow;
  19. import org.xml.sax.Locator;
  20. import org.apache.fop.apps.FOPException;
  21. import org.apache.fop.datatypes.Length;
  22. import org.apache.fop.fo.FONode;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.ValidationException;
  25. import org.apache.fop.fo.properties.StructurePointerPropertySet;
  26. /**
  27. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_inline">
  28. * <code>fo:inline</code></a> formatting object.
  29. */
  30. public class Inline extends InlineLevel implements StructurePointerPropertySet {
  31. // The value of properties relevant for fo:inline.
  32. // See also superclass InlineLevel
  33. private Length alignmentAdjust;
  34. private int alignmentBaseline;
  35. private Length baselineShift;
  36. private String ptr; // used for accessibility
  37. private int dominantBaseline;
  38. // Unused but valid items, commented out for performance:
  39. // private CommonRelativePosition commonRelativePosition;
  40. // private LengthRangeProperty blockProgressionDimension;
  41. // private Length height;
  42. // private LengthRangeProperty inlineProgressionDimension;
  43. // private Length width;
  44. // private int wrapOption;
  45. // End of property values
  46. // used for FO validation
  47. private boolean blockOrInlineItemFound = false;
  48. private boolean canHaveBlockLevelChildren = true;
  49. /**
  50. * Base constructor
  51. *
  52. * @param parent {@link FONode} that is the parent of this object
  53. */
  54. public Inline(FONode parent) {
  55. super(parent);
  56. }
  57. /** {@inheritDoc} */
  58. public void bind(PropertyList pList) throws FOPException {
  59. super.bind(pList);
  60. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  61. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  62. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  63. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  64. ptr = pList.get(PR_X_PTR).getString(); // used for accessibility
  65. }
  66. /** {@inheritDoc} */
  67. protected void startOfNode() throws FOPException {
  68. super.startOfNode();
  69. /* Check to see if this node can have block-level children.
  70. * See validateChildNode() below.
  71. */
  72. int lvlLeader = findAncestor(FO_LEADER);
  73. int lvlFootnote = findAncestor(FO_FOOTNOTE);
  74. int lvlInCntr = findAncestor(FO_INLINE_CONTAINER);
  75. if (lvlLeader > 0) {
  76. if (lvlInCntr < 0
  77. || (lvlInCntr > 0 && lvlInCntr > lvlLeader)) {
  78. canHaveBlockLevelChildren = false;
  79. }
  80. } else if (lvlFootnote > 0) {
  81. if (lvlInCntr < 0 || lvlInCntr > lvlFootnote) {
  82. canHaveBlockLevelChildren = false;
  83. }
  84. }
  85. getFOEventHandler().startInline(this);
  86. }
  87. /** {@inheritDoc} */
  88. protected void endOfNode() throws FOPException {
  89. super.endOfNode();
  90. getFOEventHandler().endInline(this);
  91. }
  92. /**
  93. * {@inheritDoc}
  94. * <br>XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
  95. * <br><i>Additionally: " An fo:inline that is a descendant of an fo:leader
  96. * or fo:footnote may not have block-level children, unless it has a
  97. * nearer ancestor that is an fo:inline-container." (paraphrased)</i>
  98. */
  99. protected void validateChildNode(Locator loc, String nsURI, String localName)
  100. throws ValidationException {
  101. if (FO_URI.equals(nsURI)) {
  102. if (localName.equals("marker")) {
  103. if (blockOrInlineItemFound) {
  104. nodesOutOfOrderError(loc, "fo:marker",
  105. "(#PCDATA|%inline;|%block;)");
  106. }
  107. } else if (!isBlockOrInlineItem(nsURI, localName)) {
  108. invalidChildError(loc, nsURI, localName);
  109. } else if (!canHaveBlockLevelChildren && isBlockItem(nsURI, localName)) {
  110. invalidChildError(loc, getParent().getName(), nsURI, getName(),
  111. "rule.inlineContent");
  112. } else {
  113. blockOrInlineItemFound = true;
  114. }
  115. }
  116. }
  117. /** @return the "alignment-adjust" property */
  118. public Length getAlignmentAdjust() {
  119. return alignmentAdjust;
  120. }
  121. /** @return the "alignment-baseline" property */
  122. public int getAlignmentBaseline() {
  123. return alignmentBaseline;
  124. }
  125. /** @return the "baseline-shift" property */
  126. public Length getBaselineShift() {
  127. return baselineShift;
  128. }
  129. /** @return the "dominant-baseline" property */
  130. public int getDominantBaseline() {
  131. return dominantBaseline;
  132. }
  133. /** {@inheritDoc} */
  134. public String getPtr() {
  135. return ptr;
  136. }
  137. /** {@inheritDoc} */
  138. public String getLocalName() {
  139. return "inline";
  140. }
  141. /**
  142. * {@inheritDoc}
  143. * @return {@link org.apache.fop.fo.Constants#FO_INLINE}
  144. */
  145. public int getNameId() {
  146. return FO_INLINE;
  147. }
  148. }