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 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.apache.fop.apps.FOPException;
  20. import org.apache.fop.datatypes.Length;
  21. import org.apache.fop.fo.FONode;
  22. import org.apache.fop.fo.PropertyList;
  23. import org.apache.fop.fo.properties.LengthRangeProperty;
  24. /**
  25. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_leader">
  26. * <code>fo:leader</code></a> object.
  27. * The main property of <code>fo:leader</code> is leader-pattern.
  28. * The following patterns are treated: rule, space, dots and use-content.
  29. * TODO implement validateChildNode()
  30. */
  31. public class Leader extends InlineLevel {
  32. // The value of properties relevant for fo:leader.
  33. // See also superclass InlineLevel
  34. private Length alignmentAdjust;
  35. private int alignmentBaseline;
  36. private Length baselineShift;
  37. private int dominantBaseline;
  38. private int leaderAlignment;
  39. private LengthRangeProperty leaderLength;
  40. private int leaderPattern;
  41. private Length leaderPatternWidth;
  42. private int ruleStyle;
  43. private Length ruleThickness;
  44. // private ToBeImplementedProperty letterSpacing;
  45. // private ToBeImplementedProperty textShadow;
  46. // Unused but valid items, commented out for performance:
  47. // private CommonRelativePosition commonRelativePosition;
  48. // private Length textDepth;
  49. // private Length textAltitude;
  50. // End of property values
  51. /**
  52. * Base constructor
  53. *
  54. * @param parent {@link FONode} that is the parent of this object
  55. */
  56. public Leader(FONode parent) {
  57. super(parent);
  58. }
  59. /** {@inheritDoc} */
  60. public void bind(PropertyList pList) throws FOPException {
  61. super.bind(pList);
  62. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  63. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  64. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  65. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  66. leaderAlignment = pList.get(PR_LEADER_ALIGNMENT).getEnum();
  67. leaderLength = pList.get(PR_LEADER_LENGTH).getLengthRange();
  68. leaderPattern = pList.get(PR_LEADER_PATTERN).getEnum();
  69. leaderPatternWidth = pList.get(PR_LEADER_PATTERN_WIDTH).getLength();
  70. ruleThickness = pList.get(PR_RULE_THICKNESS).getLength();
  71. switch(leaderPattern) {
  72. case EN_SPACE:
  73. // use Space
  74. break;
  75. case EN_RULE:
  76. // the following properties only apply
  77. // for leader-pattern = "rule"
  78. ruleStyle = pList.get(PR_RULE_STYLE).getEnum();
  79. break;
  80. case EN_DOTS:
  81. break;
  82. case EN_USECONTENT:
  83. // use inline layout manager to create inline areas
  84. // add the inline parent multiple times until leader full
  85. break;
  86. default:
  87. throw new RuntimeException("Invalid leader pattern: " + leaderPattern);
  88. }
  89. // letterSpacing = pList.get(PR_LETTER_SPACING);
  90. // textShadow = pList.get(PR_TEXT_SHADOW);
  91. }
  92. /** @return the "rule-style" property */
  93. public int getRuleStyle() {
  94. return ruleStyle;
  95. }
  96. /** @return the "rule-thickness" property */
  97. public Length getRuleThickness() {
  98. return ruleThickness;
  99. }
  100. /** @return the "leader-alignment" property */
  101. public int getLeaderAlignment() {
  102. return leaderAlignment;
  103. }
  104. /** @return the "leader-length" property */
  105. public LengthRangeProperty getLeaderLength() {
  106. return leaderLength;
  107. }
  108. /** @return the "leader-pattern" property */
  109. public int getLeaderPattern() {
  110. return leaderPattern;
  111. }
  112. /** @return the "leader-pattern-width" property */
  113. public Length getLeaderPatternWidth() {
  114. return leaderPatternWidth;
  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. /** {@inheritDoc} */
  133. public String getLocalName() {
  134. return "leader";
  135. }
  136. /**
  137. * {@inheritDoc}
  138. * @return {@link org.apache.fop.fo.Constants#FO_LEADER}
  139. */
  140. public int getNameId() {
  141. return FO_LEADER;
  142. }
  143. @Override
  144. protected void startOfNode() throws FOPException {
  145. super.startOfNode();
  146. getFOEventHandler().startLeader(this);
  147. }
  148. @Override
  149. protected void endOfNode() throws FOPException {
  150. super.endOfNode();
  151. getFOEventHandler().endLeader(this);
  152. }
  153. }