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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 fo:inline formatting object.
  27. */
  28. public class Inline extends InlineLevel {
  29. // The value of properties relevant for fo:inline.
  30. // See also superclass InlineLevel
  31. private Length alignmentAdjust;
  32. private int alignmentBaseline;
  33. private Length baselineShift;
  34. private int dominantBaseline;
  35. // Unused but valid items, commented out for performance:
  36. // private CommonRelativePosition commonRelativePosition;
  37. // private LengthRangeProperty blockProgressionDimension;
  38. // private Length height;
  39. // private LengthRangeProperty inlineProgressionDimension;
  40. // private Length width;
  41. // private int wrapOption;
  42. // End of property values
  43. // used for FO validation
  44. private boolean blockOrInlineItemFound = false;
  45. private boolean canHaveBlockLevelChildren = true;
  46. /**
  47. * @param parent FONode that is the parent of this object
  48. */
  49. public Inline(FONode parent) {
  50. super(parent);
  51. }
  52. /**
  53. * {@inheritDoc}
  54. */
  55. public void bind(PropertyList pList) throws FOPException {
  56. super.bind(pList);
  57. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  58. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  59. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  60. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  61. }
  62. /**
  63. * {@inheritDoc}
  64. */
  65. protected void startOfNode() throws FOPException {
  66. super.startOfNode();
  67. /* Check to see if this node can have block-level children.
  68. * See validateChildNode() below.
  69. */
  70. int lvlLeader = findAncestor(FO_LEADER);
  71. int lvlFootnote = findAncestor(FO_FOOTNOTE);
  72. int lvlInCntr = findAncestor(FO_INLINE_CONTAINER);
  73. if (lvlLeader > 0) {
  74. if (lvlInCntr < 0
  75. || (lvlInCntr > 0 && lvlInCntr > lvlLeader)) {
  76. canHaveBlockLevelChildren = false;
  77. }
  78. } else if (lvlFootnote > 0) {
  79. if (lvlInCntr < 0 || lvlInCntr > lvlFootnote) {
  80. canHaveBlockLevelChildren = false;
  81. }
  82. }
  83. getFOEventHandler().startInline(this);
  84. }
  85. /**
  86. * {@inheritDoc}
  87. */
  88. protected void endOfNode() throws FOPException {
  89. super.endOfNode();
  90. getFOEventHandler().endInline(this);
  91. }
  92. /**
  93. * {@inheritDoc}
  94. * XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
  95. * 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)
  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(), "rule.inlineContent");
  111. } else {
  112. blockOrInlineItemFound = true;
  113. }
  114. }
  115. }
  116. /**
  117. * @return the "alignment-adjust" property
  118. */
  119. public Length getAlignmentAdjust() {
  120. return alignmentAdjust;
  121. }
  122. /**
  123. * @return the "alignment-baseline" property
  124. */
  125. public int getAlignmentBaseline() {
  126. return alignmentBaseline;
  127. }
  128. /**
  129. * @return the "baseline-shift" property
  130. */
  131. public Length getBaselineShift() {
  132. return baselineShift;
  133. }
  134. /**
  135. * @return the "dominant-baseline" property
  136. */
  137. public int getDominantBaseline() {
  138. return dominantBaseline;
  139. }
  140. /** {@inheritDoc} */
  141. public String getLocalName() {
  142. return "inline";
  143. }
  144. /** {@inheritDoc} */
  145. public int getNameId() {
  146. return FO_INLINE;
  147. }
  148. }