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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. }
  65. /** {@inheritDoc} */
  66. protected void startOfNode() throws FOPException {
  67. super.startOfNode();
  68. /* Check to see if this node can have block-level children.
  69. * See validateChildNode() below.
  70. */
  71. int lvlLeader = findAncestor(FO_LEADER);
  72. int lvlFootnote = findAncestor(FO_FOOTNOTE);
  73. int lvlInCntr = findAncestor(FO_INLINE_CONTAINER);
  74. if (lvlLeader > 0) {
  75. if (lvlInCntr < 0
  76. || (lvlInCntr > 0 && lvlInCntr > lvlLeader)) {
  77. canHaveBlockLevelChildren = false;
  78. }
  79. } else if (lvlFootnote > 0) {
  80. if (lvlInCntr < 0 || lvlInCntr > lvlFootnote) {
  81. canHaveBlockLevelChildren = false;
  82. }
  83. }
  84. getFOEventHandler().startInline(this);
  85. }
  86. /** {@inheritDoc} */
  87. protected void endOfNode() throws FOPException {
  88. super.endOfNode();
  89. getFOEventHandler().endInline(this);
  90. }
  91. /**
  92. * {@inheritDoc}
  93. * <br>XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
  94. * <br><i>Additionally: " An fo:inline that is a descendant of an fo:leader
  95. * or fo:footnote may not have block-level children, unless it has a
  96. * nearer ancestor that is an fo:inline-container." (paraphrased)</i>
  97. */
  98. protected void validateChildNode(Locator loc, String nsURI, String localName)
  99. throws ValidationException {
  100. if (FO_URI.equals(nsURI)) {
  101. if (localName.equals("marker")) {
  102. if (blockOrInlineItemFound) {
  103. nodesOutOfOrderError(loc, "fo:marker",
  104. "(#PCDATA|%inline;|%block;)");
  105. }
  106. } else if (!isBlockOrInlineItem(nsURI, localName)) {
  107. invalidChildError(loc, nsURI, localName);
  108. } else if (!canHaveBlockLevelChildren && isBlockItem(nsURI, localName)) {
  109. invalidChildError(loc, getParent().getName(), nsURI, getName(),
  110. "rule.inlineContent");
  111. } else {
  112. blockOrInlineItemFound = true;
  113. }
  114. }
  115. }
  116. /** @return the "alignment-adjust" property */
  117. public Length getAlignmentAdjust() {
  118. return alignmentAdjust;
  119. }
  120. /** @return the "alignment-baseline" property */
  121. public int getAlignmentBaseline() {
  122. return alignmentBaseline;
  123. }
  124. /** @return the "baseline-shift" property */
  125. public Length getBaselineShift() {
  126. return baselineShift;
  127. }
  128. /** @return the "dominant-baseline" property */
  129. public int getDominantBaseline() {
  130. return dominantBaseline;
  131. }
  132. @Override
  133. public void setPtr(String ptr) {
  134. this.ptr = ptr;
  135. }
  136. /** {@inheritDoc} */
  137. public String getPtr() {
  138. return ptr;
  139. }
  140. /** {@inheritDoc} */
  141. public String getLocalName() {
  142. return "inline";
  143. }
  144. /**
  145. * {@inheritDoc}
  146. * @return {@link org.apache.fop.fo.Constants#FO_INLINE}
  147. */
  148. public int getNameId() {
  149. return FO_INLINE;
  150. }
  151. }