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.

PDFResourceContext.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. import java.util.LinkedHashSet;
  20. import java.util.Set;
  21. /**
  22. * The PDF resource context.
  23. *
  24. * There is one of these for every page in a PDF document. The object
  25. * specifies the dimensions of the page and references a /Resources
  26. * object, a contents stream and the page's parent in the page
  27. * hierarchy.
  28. *
  29. * Modified by Mark Lillywhite, mark-fop@inomial.com. The Parent
  30. * object was being referred to by reference, but all that we
  31. * ever used from the Parent was its PDF object ID, and according
  32. * to the memory profile this was causing OOM issues. So, we store
  33. * only the object ID of the parent, rather than the parent itself.
  34. */
  35. public class PDFResourceContext extends PDFDictionary {
  36. private Set<PDFXObject> xObjects = new LinkedHashSet<PDFXObject>();
  37. private Set<PDFPattern> patterns = new LinkedHashSet<PDFPattern>();
  38. private Set<PDFShading> shadings = new LinkedHashSet<PDFShading>();
  39. private Set<PDFGState> gstates = new LinkedHashSet<PDFGState>();
  40. /**
  41. * Creates a new ResourceContext.
  42. * @param resources the /Resources object
  43. */
  44. public PDFResourceContext(PDFResources resources) {
  45. /* generic creation of object */
  46. super();
  47. /* set fields using parameters */
  48. put("Resources", resources);
  49. resources.addContext(this);
  50. }
  51. public void addXObject(PDFXObject xObject) {
  52. xObjects.add(xObject);
  53. }
  54. public Set<PDFXObject> getXObjects() {
  55. return xObjects;
  56. }
  57. /**
  58. * Get the resources for this resource context.
  59. *
  60. * @return the resources in this resource context
  61. */
  62. public PDFResources getPDFResources() {
  63. return (PDFResources)get("Resources");
  64. }
  65. /**
  66. * set this page's annotation list
  67. *
  68. * @param annot a PDFAnnotList list of annotations
  69. */
  70. public void addAnnotation(PDFObject annot) {
  71. PDFAnnotList annotList = getAnnotations();
  72. if (annotList == null) {
  73. annotList = getDocument().getFactory().makeAnnotList();
  74. put("Annots", annotList);
  75. }
  76. annotList.addAnnot(annot);
  77. }
  78. /**
  79. * Get the current annotations.
  80. *
  81. * @return the current annotation list
  82. */
  83. public PDFAnnotList getAnnotations() {
  84. return (PDFAnnotList)get("Annots");
  85. }
  86. /**
  87. * A a GState to this resource context.
  88. *
  89. * @param gstate the GState to add
  90. */
  91. public void addGState(PDFGState gstate) {
  92. gstates.add(gstate);
  93. }
  94. public Set<PDFGState> getGStates() {
  95. return gstates;
  96. }
  97. /**
  98. * Add the shading to the current resource context.
  99. *
  100. * @param shading the shading to add
  101. */
  102. public void addShading(PDFShading shading) {
  103. shadings.add(shading);
  104. }
  105. public Set<PDFShading> getShadings() {
  106. return shadings;
  107. }
  108. public Set<PDFPattern> getPatterns() {
  109. return patterns;
  110. }
  111. public void addPattern(PDFPattern pattern) {
  112. patterns.add(pattern);
  113. }
  114. }