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

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