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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /**
  26. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_inline">
  27. * <code>fo:inline</code></a> formatting object.
  28. */
  29. public class Inline extends InlineLevel {
  30. // The value of properties relevant for fo:inline.
  31. // See also superclass InlineLevel
  32. private Length alignmentAdjust;
  33. private int alignmentBaseline;
  34. private Length baselineShift;
  35. private int dominantBaseline;
  36. // Unused but valid items, commented out for performance:
  37. // private CommonRelativePosition commonRelativePosition;
  38. // private LengthRangeProperty blockProgressionDimension;
  39. // private Length height;
  40. // private LengthRangeProperty inlineProgressionDimension;
  41. // private Length width;
  42. // private int wrapOption;
  43. // End of property values
  44. // used for FO validation
  45. private boolean blockOrInlineItemFound;
  46. private boolean canHaveBlockLevelChildren = true;
  47. /**
  48. * Base constructor
  49. *
  50. * @param parent {@link FONode} that is the parent of this object
  51. */
  52. public Inline(FONode parent) {
  53. super(parent);
  54. }
  55. /** {@inheritDoc} */
  56. public void bind(PropertyList pList) throws FOPException {
  57. super.bind(pList);
  58. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  59. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  60. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  61. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  62. }
  63. /** {@inheritDoc} */
  64. public void startOfNode() throws FOPException {
  65. super.startOfNode();
  66. /* Check to see if this node can have block-level children.
  67. * See validateChildNode() below.
  68. */
  69. int lvlLeader = findAncestor(FO_LEADER);
  70. int lvlFootnote = findAncestor(FO_FOOTNOTE);
  71. int lvlInCntr = findAncestor(FO_INLINE_CONTAINER);
  72. if (lvlLeader > 0) {
  73. if (lvlInCntr < 0
  74. || (lvlInCntr > 0 && lvlInCntr > lvlLeader)) {
  75. canHaveBlockLevelChildren = false;
  76. }
  77. } else if (lvlFootnote > 0) {
  78. if (lvlInCntr < 0 || lvlInCntr > lvlFootnote) {
  79. canHaveBlockLevelChildren = false;
  80. }
  81. }
  82. getFOEventHandler().startInline(this);
  83. }
  84. /** {@inheritDoc} */
  85. public void endOfNode() throws FOPException {
  86. super.endOfNode();
  87. getFOEventHandler().endInline(this);
  88. }
  89. /**
  90. * {@inheritDoc}
  91. * <br>XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
  92. * <br><i>Additionally: " An fo:inline that is a descendant of an fo:leader
  93. * or fo:footnote may not have block-level children, unless it has a
  94. * nearer ancestor that is an fo:inline-container." (paraphrased)</i>
  95. */
  96. protected void validateChildNode(Locator loc, String nsURI, String localName)
  97. throws ValidationException {
  98. if (FO_URI.equals(nsURI)) {
  99. if (localName.equals("marker")) {
  100. if (blockOrInlineItemFound) {
  101. nodesOutOfOrderError(loc, "fo:marker",
  102. "(#PCDATA|%inline;|%block;)");
  103. }
  104. } else if (!isBlockOrInlineItem(nsURI, localName)) {
  105. invalidChildError(loc, nsURI, localName);
  106. } else if (!canHaveBlockLevelChildren && isBlockItem(nsURI, localName)
  107. && !isNeutralItem(nsURI, localName)) {
  108. invalidChildError(loc, getName(), nsURI, localName, "rule.inlineContent");
  109. } else {
  110. blockOrInlineItemFound = true;
  111. }
  112. }
  113. }
  114. /** @return the "alignment-adjust" property */
  115. public Length getAlignmentAdjust() {
  116. return alignmentAdjust;
  117. }
  118. /** @return the "alignment-baseline" property */
  119. public int getAlignmentBaseline() {
  120. return alignmentBaseline;
  121. }
  122. /** @return the "baseline-shift" property */
  123. public Length getBaselineShift() {
  124. return baselineShift;
  125. }
  126. /** @return the "dominant-baseline" property */
  127. public int getDominantBaseline() {
  128. return dominantBaseline;
  129. }
  130. /** {@inheritDoc} */
  131. public String getLocalName() {
  132. return "inline";
  133. }
  134. /**
  135. * {@inheritDoc}
  136. * @return {@link org.apache.fop.fo.Constants#FO_INLINE}
  137. */
  138. public int getNameId() {
  139. return FO_INLINE;
  140. }
  141. }