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.

Leader.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 java.util.Stack;
  20. import org.xml.sax.Locator;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.complexscripts.bidi.DelimitedTextRange;
  23. import org.apache.fop.datatypes.Length;
  24. import org.apache.fop.fo.FONode;
  25. import org.apache.fop.fo.PropertyList;
  26. import org.apache.fop.fo.ValidationException;
  27. import org.apache.fop.fo.properties.LengthRangeProperty;
  28. import org.apache.fop.util.CharUtilities;
  29. /**
  30. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_leader">
  31. * <code>fo:leader</code></a> object.
  32. * The main property of <code>fo:leader</code> is leader-pattern.
  33. * The following patterns are treated: rule, space, dots and use-content.
  34. */
  35. public class Leader extends InlineLevel {
  36. // The value of properties relevant for fo:leader.
  37. // See also superclass InlineLevel
  38. private Length alignmentAdjust;
  39. private int alignmentBaseline;
  40. private Length baselineShift;
  41. private int dominantBaseline;
  42. private int leaderAlignment;
  43. private LengthRangeProperty leaderLength;
  44. private int leaderPattern;
  45. private Length leaderPatternWidth;
  46. private int ruleStyle;
  47. private Length ruleThickness;
  48. // private ToBeImplementedProperty letterSpacing;
  49. // private ToBeImplementedProperty textShadow;
  50. // Unused but valid items, commented out for performance:
  51. // private CommonRelativePosition commonRelativePosition;
  52. // private Length textDepth;
  53. // private Length textAltitude;
  54. // End of property values
  55. /**
  56. * Base constructor
  57. *
  58. * @param parent {@link FONode} that is the parent of this object
  59. */
  60. public Leader(FONode parent) {
  61. super(parent);
  62. }
  63. /** {@inheritDoc} */
  64. public void bind(PropertyList pList) throws FOPException {
  65. super.bind(pList);
  66. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  67. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  68. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  69. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  70. leaderAlignment = pList.get(PR_LEADER_ALIGNMENT).getEnum();
  71. leaderLength = pList.get(PR_LEADER_LENGTH).getLengthRange();
  72. leaderPattern = pList.get(PR_LEADER_PATTERN).getEnum();
  73. leaderPatternWidth = pList.get(PR_LEADER_PATTERN_WIDTH).getLength();
  74. // use default rule thickness as a default
  75. ruleThickness = getPropertyMakerFor(PR_RULE_THICKNESS).make(pList).getLength();
  76. switch(leaderPattern) {
  77. case EN_SPACE:
  78. // use Space
  79. break;
  80. case EN_RULE:
  81. // the following properties only apply
  82. // for leader-pattern = "rule"
  83. ruleStyle = pList.get(PR_RULE_STYLE).getEnum();
  84. // use specified rule thickness to override default (established above)
  85. ruleThickness = pList.get(PR_RULE_THICKNESS).getLength();
  86. break;
  87. case EN_DOTS:
  88. break;
  89. case EN_USECONTENT:
  90. // use inline layout manager to create inline areas
  91. // add the inline parent multiple times until leader full
  92. break;
  93. default:
  94. throw new RuntimeException("Invalid leader pattern: " + leaderPattern);
  95. }
  96. // letterSpacing = pList.get(PR_LETTER_SPACING);
  97. // textShadow = pList.get(PR_TEXT_SHADOW);
  98. }
  99. /**
  100. * {@inheritDoc}
  101. * <br>XSL Content Model: (#PCDATA|%inline;)*
  102. * <br><i>Additionally: "The content must not contain an
  103. * fo:leader, fo:inline-container, fo:block-container, fo:float,
  104. * fo:footnote, or fo:marker either as a direct child or as a
  105. * descendant."</i>
  106. */
  107. protected void validateChildNode(Locator loc, String nsURI, String localName)
  108. throws ValidationException {
  109. if (FO_URI.equals(nsURI)) {
  110. if (localName.equals("leader")
  111. || localName.equals("inline-container")
  112. || localName.equals("block-container")
  113. || localName.equals("float")
  114. || localName.equals("marker")
  115. || !isInlineItem(nsURI, localName)) {
  116. invalidChildError(loc, nsURI, localName);
  117. }
  118. }
  119. }
  120. /** @return the "rule-style" property */
  121. public int getRuleStyle() {
  122. return ruleStyle;
  123. }
  124. /** @return the "rule-thickness" property */
  125. public Length getRuleThickness() {
  126. return ruleThickness;
  127. }
  128. /** @return the "leader-alignment" property */
  129. public int getLeaderAlignment() {
  130. return leaderAlignment;
  131. }
  132. /** @return the "leader-length" property */
  133. public LengthRangeProperty getLeaderLength() {
  134. return leaderLength;
  135. }
  136. /** @return the "leader-pattern" property */
  137. public int getLeaderPattern() {
  138. return leaderPattern;
  139. }
  140. /** @return the "leader-pattern-width" property */
  141. public Length getLeaderPatternWidth() {
  142. return leaderPatternWidth;
  143. }
  144. /** @return the "alignment-adjust" property */
  145. public Length getAlignmentAdjust() {
  146. return alignmentAdjust;
  147. }
  148. /** @return the "alignment-baseline" property */
  149. public int getAlignmentBaseline() {
  150. return alignmentBaseline;
  151. }
  152. /** @return the "baseline-shift" property */
  153. public Length getBaselineShift() {
  154. return baselineShift;
  155. }
  156. /** @return the "dominant-baseline" property */
  157. public int getDominantBaseline() {
  158. return dominantBaseline;
  159. }
  160. /** {@inheritDoc} */
  161. public String getLocalName() {
  162. return "leader";
  163. }
  164. /**
  165. * {@inheritDoc}
  166. * @return {@link org.apache.fop.fo.Constants#FO_LEADER}
  167. */
  168. public int getNameId() {
  169. return FO_LEADER;
  170. }
  171. @Override
  172. public void startOfNode() throws FOPException {
  173. super.startOfNode();
  174. getFOEventHandler().startLeader(this);
  175. }
  176. @Override
  177. public void endOfNode() throws FOPException {
  178. super.endOfNode();
  179. getFOEventHandler().endLeader(this);
  180. }
  181. @Override
  182. protected Stack<DelimitedTextRange> collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges,
  183. DelimitedTextRange currentRange) {
  184. if (currentRange != null) {
  185. if (leaderPattern == EN_USECONTENT) {
  186. ranges = super.collectDelimitedTextRanges(ranges, currentRange);
  187. } else {
  188. currentRange.append(CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this);
  189. }
  190. }
  191. return ranges;
  192. }
  193. }