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.

AbstractPageSequence.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.pagination;
  19. import org.apache.fop.apps.FOPException;
  20. import org.apache.fop.datatypes.Numeric;
  21. import org.apache.fop.fo.FONode;
  22. import org.apache.fop.fo.FObj;
  23. import org.apache.fop.fo.PropertyList;
  24. /**
  25. * Abstract base class for the <a href="http://www.w3.org/TR/xsl/#fo_page-sequence">
  26. * <code>fo:page-sequence</code></a> formatting object and the
  27. * <a href="http://xmlgraphics.apache.org/fop/0.95/extensions.html#external-document">
  28. * <code>fox:external-document</code></a> extension object.
  29. */
  30. public abstract class AbstractPageSequence extends FObj {
  31. // The value of properties relevant for fo:page-sequence.
  32. /** initial page number */
  33. protected Numeric initialPageNumber;
  34. /** forced page count */
  35. protected int forcePageCount;
  36. private String format;
  37. private int letterValue;
  38. private char groupingSeparator;
  39. private int groupingSize;
  40. private Numeric referenceOrientation; //XSL 1.1
  41. // End of property values
  42. private PageNumberGenerator pageNumberGenerator;
  43. /** starting page number */
  44. protected int startingPageNumber = 0;
  45. /**
  46. * Create an AbstractPageSequence that is a child
  47. * of the given parent {@link FONode}.
  48. *
  49. * @param parent the parent {@link FONode}
  50. */
  51. public AbstractPageSequence(FONode parent) {
  52. super(parent);
  53. }
  54. /** {@inheritDoc} */
  55. public void bind(PropertyList pList) throws FOPException {
  56. super.bind(pList);
  57. initialPageNumber = pList.get(PR_INITIAL_PAGE_NUMBER).getNumeric();
  58. forcePageCount = pList.get(PR_FORCE_PAGE_COUNT).getEnum();
  59. format = pList.get(PR_FORMAT).getString();
  60. letterValue = pList.get(PR_LETTER_VALUE).getEnum();
  61. groupingSeparator = pList.get(PR_GROUPING_SEPARATOR).getCharacter();
  62. groupingSize = pList.get(PR_GROUPING_SIZE).getNumber().intValue();
  63. referenceOrientation = pList.get(PR_REFERENCE_ORIENTATION).getNumeric();
  64. }
  65. /** {@inheritDoc} */
  66. protected void startOfNode() throws FOPException {
  67. this.pageNumberGenerator = new PageNumberGenerator(
  68. format, groupingSeparator, groupingSize, letterValue);
  69. }
  70. /**
  71. * Initialize the current page number for the start of the page sequence.
  72. */
  73. public void initPageNumber() {
  74. int pageNumberType = 0;
  75. if (initialPageNumber.getEnum() != 0) {
  76. // auto | auto-odd | auto-even.
  77. startingPageNumber = getRoot().getEndingPageNumberOfPreviousSequence() + 1;
  78. pageNumberType = initialPageNumber.getEnum();
  79. if (pageNumberType == EN_AUTO_ODD) {
  80. if (startingPageNumber % 2 == 0) {
  81. startingPageNumber++;
  82. }
  83. } else if (pageNumberType == EN_AUTO_EVEN) {
  84. if (startingPageNumber % 2 == 1) {
  85. startingPageNumber++;
  86. }
  87. }
  88. } else { // <integer> for explicit page number
  89. int pageStart = initialPageNumber.getValue();
  90. startingPageNumber = (pageStart > 0) ? pageStart : 1; // spec rule
  91. }
  92. }
  93. /**
  94. * Get the starting page number for this page sequence.
  95. *
  96. * @return the starting page number
  97. */
  98. public int getStartingPageNumber() {
  99. return startingPageNumber;
  100. }
  101. /**
  102. * Retrieves the string representation of a page number applicable
  103. * for this page sequence
  104. * @param pageNumber the page number
  105. * @return string representation of the page number
  106. */
  107. public String makeFormattedPageNumber(int pageNumber) {
  108. return pageNumberGenerator.makeFormattedPageNumber(pageNumber);
  109. }
  110. /**
  111. * Public accessor for the ancestor Root.
  112. * @return the ancestor Root
  113. */
  114. public Root getRoot() {
  115. return (Root)this.getParent();
  116. }
  117. /**
  118. * Get the value of the <code>force-page-count</code> property.
  119. * @return the force-page-count value
  120. */
  121. public int getForcePageCount() {
  122. return forcePageCount;
  123. }
  124. /**
  125. * Get the value of the <code>initial-page-number</code> property.
  126. * @return the initial-page-number property value
  127. */
  128. public Numeric getInitialPageNumber() {
  129. return initialPageNumber;
  130. }
  131. /**
  132. * Get the value of the <code>reference-orientation</code> property.
  133. * @return the "reference-orientation" property
  134. * @since XSL 1.1
  135. */
  136. public int getReferenceOrientation() {
  137. return referenceOrientation.getValue();
  138. }
  139. }