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.

PageNumber.java 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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.awt.Color;
  20. import org.xml.sax.Locator;
  21. import org.apache.fop.accessibility.StructureTreeElement;
  22. import org.apache.fop.apps.FOPException;
  23. import org.apache.fop.datatypes.Length;
  24. import org.apache.fop.fo.Constants;
  25. import org.apache.fop.fo.FONode;
  26. import org.apache.fop.fo.FObj;
  27. import org.apache.fop.fo.PropertyList;
  28. import org.apache.fop.fo.ValidationException;
  29. import org.apache.fop.fo.properties.CommonAccessibility;
  30. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  31. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  32. import org.apache.fop.fo.properties.CommonFont;
  33. import org.apache.fop.fo.properties.CommonTextDecoration;
  34. import org.apache.fop.fo.properties.SpaceProperty;
  35. import org.apache.fop.fo.properties.StructureTreeElementHolder;
  36. /**
  37. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_page-number">
  38. * <code>fo:page-number</code></a> object.
  39. */
  40. public class PageNumber extends FObj
  41. implements StructureTreeElementHolder, CommonAccessibilityHolder {
  42. // The value of properties relevant for fo:page-number.
  43. private CommonAccessibility commonAccessibility;
  44. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  45. private CommonFont commonFont;
  46. private Length alignmentAdjust;
  47. private int alignmentBaseline;
  48. private Length baselineShift;
  49. private int dominantBaseline;
  50. private StructureTreeElement structureTreeElement;
  51. // private ToBeImplementedProperty letterSpacing;
  52. private SpaceProperty lineHeight;
  53. /** Holds the text decoration values. May be null */
  54. private CommonTextDecoration textDecoration;
  55. // private ToBeImplementedProperty textShadow;
  56. // Unused but valid items, commented out for performance:
  57. // private CommonAural commonAural;
  58. // private CommonMarginInline commonMarginInline;
  59. // private CommonRelativePosition commonRelativePosition;
  60. // private KeepProperty keepWithNext;
  61. // private KeepProperty keepWithPrevious;
  62. // private int scoreSpaces;
  63. // private Length textAltitude;
  64. // private Length textDepth;
  65. // private int textTransform;
  66. // private int visibility;
  67. // private SpaceProperty wordSpacing;
  68. // private int wrapOption;
  69. // End of property values
  70. // Properties which are not explicitely listed but are still applicable
  71. private Color color;
  72. /**
  73. * Base constructor
  74. *
  75. * @param parent {@link FONode} that is the parent of this object
  76. */
  77. public PageNumber(FONode parent) {
  78. super(parent);
  79. }
  80. /** {@inheritDoc} */
  81. public void bind(PropertyList pList) throws FOPException {
  82. super.bind(pList);
  83. commonAccessibility = CommonAccessibility.getInstance(pList);
  84. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  85. commonFont = pList.getFontProps();
  86. alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
  87. alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
  88. baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
  89. dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
  90. // letterSpacing = pList.get(PR_LETTER_SPACING);
  91. lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
  92. textDecoration = pList.getTextDecorationProps();
  93. // textShadow = pList.get(PR_TEXT_SHADOW);
  94. // implicit properties
  95. color = pList.get(Constants.PR_COLOR).getColor(getUserAgent());
  96. }
  97. /** {@inheritDoc} */
  98. protected void startOfNode() throws FOPException {
  99. super.startOfNode();
  100. getFOEventHandler().startPageNumber(this);
  101. }
  102. /** {@inheritDoc} */
  103. protected void endOfNode() throws FOPException {
  104. getFOEventHandler().endPageNumber(this);
  105. }
  106. /**
  107. * {@inheritDoc}
  108. * <br>XSL Content Model: empty
  109. */
  110. protected void validateChildNode(Locator loc, String nsURI, String localName)
  111. throws ValidationException {
  112. if (FO_URI.equals(nsURI)) {
  113. invalidChildError(loc, nsURI, localName);
  114. }
  115. }
  116. public CommonAccessibility getCommonAccessibility() {
  117. return commonAccessibility;
  118. }
  119. /** @return the Common Font Properties. */
  120. public CommonFont getCommonFont() {
  121. return commonFont;
  122. }
  123. /** @return the "color" property. */
  124. public Color getColor() {
  125. return color;
  126. }
  127. /** @return the Common Border, Padding, and Background Properties. */
  128. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  129. return commonBorderPaddingBackground;
  130. }
  131. /** @return the "text-decoration" property. */
  132. public CommonTextDecoration getTextDecoration() {
  133. return textDecoration;
  134. }
  135. /** @return the "alignment-adjust" property */
  136. public Length getAlignmentAdjust() {
  137. return alignmentAdjust;
  138. }
  139. /** @return the "alignment-baseline" property */
  140. public int getAlignmentBaseline() {
  141. return alignmentBaseline;
  142. }
  143. /** @return the "baseline-shift" property */
  144. public Length getBaselineShift() {
  145. return baselineShift;
  146. }
  147. /** @return the "dominant-baseline" property */
  148. public int getDominantBaseline() {
  149. return dominantBaseline;
  150. }
  151. /** @return the "line-height" property */
  152. public SpaceProperty getLineHeight() {
  153. return lineHeight;
  154. }
  155. @Override
  156. public void setStructureTreeElement(StructureTreeElement structureTreeElement) {
  157. this.structureTreeElement = structureTreeElement;
  158. }
  159. /** {@inheritDoc} */
  160. public StructureTreeElement getStructureTreeElement() {
  161. return structureTreeElement;
  162. }
  163. /** {@inheritDoc} */
  164. public String getLocalName() {
  165. return "page-number";
  166. }
  167. /**
  168. * {@inheritDoc}
  169. * @return {@link org.apache.fop.fo.Constants#FO_PAGE_NUMBER}
  170. */
  171. public int getNameId() {
  172. return FO_PAGE_NUMBER;
  173. }
  174. }