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.

PDFNumberTreeNode.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.pdf;
  19. /**
  20. * Class representing a PDF number tree node.
  21. */
  22. public class PDFNumberTreeNode extends PDFDictionary {
  23. private static final String KIDS = "Kids";
  24. private static final String NUMS = "Nums";
  25. private static final String LIMITS = "Limits";
  26. /**
  27. * create a named destination
  28. */
  29. public PDFNumberTreeNode() {
  30. /* generic creation of PDF object */
  31. super();
  32. }
  33. /**
  34. * Sets the Kids array.
  35. * @param kids the Kids array
  36. */
  37. public void setKids(PDFArray kids) {
  38. put(KIDS, kids);
  39. }
  40. /**
  41. * Returns the Kids array.
  42. * @return the Kids array
  43. */
  44. public PDFArray getKids() {
  45. return (PDFArray) get(KIDS);
  46. }
  47. /**
  48. * Sets the Nums array.
  49. * @param nums the Nums array
  50. */
  51. public void setNums(PDFNumsArray nums) {
  52. put(NUMS, nums);
  53. }
  54. /**
  55. * Returns the Nums array.
  56. * @return the Nums array
  57. */
  58. public PDFNumsArray getNums() {
  59. PDFNumsArray nums = (PDFNumsArray) get(NUMS);
  60. if (nums == null) {
  61. nums = new PDFNumsArray(this);
  62. setNums(nums);
  63. }
  64. return nums;
  65. }
  66. /**
  67. * Sets the lower limit value of the Limits array.
  68. * @param key the lower limit value
  69. */
  70. public void setLowerLimit(Integer key) {
  71. PDFArray limits = prepareLimitsArray();
  72. limits.set(0, key);
  73. }
  74. /**
  75. * Returns the lower limit value of the Limits array.
  76. * @return the lower limit value
  77. */
  78. public Integer getLowerLimit() {
  79. PDFArray limits = prepareLimitsArray();
  80. return (Integer) limits.get(0);
  81. }
  82. /**
  83. * Sets the upper limit value of the Limits array.
  84. * @param key the upper limit value
  85. */
  86. public void setUpperLimit(Integer key) {
  87. PDFArray limits = prepareLimitsArray();
  88. limits.set(1, key);
  89. }
  90. /**
  91. * Returns the upper limit value of the Limits array.
  92. * @return the upper limit value
  93. */
  94. public Integer getUpperLimit() {
  95. PDFArray limits = prepareLimitsArray();
  96. return (Integer) limits.get(1);
  97. }
  98. /**
  99. * Adds a number and object to the nums array and increases the
  100. * upper limit should it be required.
  101. * @param num The unique number identifying the object in the array
  102. * @param object The object being added
  103. */
  104. protected void addToNums(int num, Object object) {
  105. getNums().put(num, object);
  106. if (getUpperLimit() < num) {
  107. setUpperLimit(num);
  108. }
  109. }
  110. private PDFArray prepareLimitsArray() {
  111. PDFArray limits = (PDFArray) get(LIMITS);
  112. if (limits == null) {
  113. limits = new PDFArray(this, new Object[2]);
  114. put(LIMITS, limits);
  115. }
  116. if (limits.length() != 2) {
  117. throw new IllegalStateException("Limits array must have 2 entries");
  118. }
  119. return limits;
  120. }
  121. }