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.

PDFImage.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.io.IOException;
  20. import java.io.OutputStream;
  21. /**
  22. * Interface for a PDF image.
  23. * This is used for inserting an image into PDF.
  24. */
  25. public interface PDFImage {
  26. /**
  27. * Key to look up XObject.
  28. * This should be a unique key to refer to the image.
  29. *
  30. * @return the key for this image
  31. */
  32. String getKey();
  33. /**
  34. * Setup the PDF image for the current document.
  35. * Some image formats may need to access the document (for example to
  36. * add an ICC profile to the document).
  37. *
  38. * @param doc the PDF parent document
  39. * (todo) Remove this and delegate to the XObject
  40. */
  41. void setup(PDFDocument doc);
  42. /**
  43. * Get the image width in pixels.
  44. *
  45. * @return the image width
  46. */
  47. int getWidth();
  48. /**
  49. * Get the image height in pixels.
  50. *
  51. * @return the image height
  52. */
  53. int getHeight();
  54. /**
  55. * Get the color space for this image.
  56. * Possible results are: DeviceGray, DeviceRGB, or DeviceCMYK
  57. *
  58. * @return the color space
  59. */
  60. PDFDeviceColorSpace getColorSpace();
  61. /**
  62. * Get the bits per color component for this image.
  63. *
  64. * @return the bits per component
  65. */
  66. int getBitsPerComponent();
  67. /**
  68. * Check if this image is a PostScript image.
  69. *
  70. * @return true if this is a PostScript image
  71. */
  72. boolean isPS();
  73. /**
  74. * Check if this image has a transparent color transparency.
  75. *
  76. * Classes such as {@link PDFImageXObject} rely on this simple
  77. * binary model of transparency (e.g. compare to
  78. * {@link java.awt.Transparency}) in order to render
  79. * color key masking (see PDF Spec 1.7 Chapter 8.9.6.4).
  80. * Therefore only return true if image has fully transparent
  81. * colors.
  82. *
  83. * @return true if it has at least one fully transparent color
  84. */
  85. boolean isTransparent();
  86. /**
  87. * Get the transparent color.
  88. *
  89. * @return the transparent color for this image
  90. */
  91. PDFColor getTransparentColor();
  92. /**
  93. * Get the PDF reference for a bitmap mask.
  94. *
  95. * @return the PDF reference for the mask image
  96. */
  97. String getMask();
  98. /**
  99. * Get the PDF reference for a soft mask.
  100. * @return the PDF reference for a soft mask image (or null if there's no soft mask)
  101. */
  102. PDFReference getSoftMaskReference();
  103. /** @return true for CMYK images generated by Adobe Photoshop */
  104. boolean isInverted();
  105. /**
  106. * Get the PDF Filter to be applied to the image.
  107. *
  108. * @return the PDF Filter or null
  109. */
  110. PDFFilter getPDFFilter();
  111. // get the image bytes, and bytes properties
  112. /**
  113. * Writes the raw, unencoded contents of the image to a given output stream.
  114. *
  115. * @param out OutputStream to write to
  116. * @throws IOException if there creating stream
  117. */
  118. void outputContents(OutputStream out) throws IOException;
  119. /**
  120. * Populates the XObject's dictionary with additional values. The values are added to the
  121. * dictionary after all the values obtained from other methods from this interface have
  122. * been put into the dictionary. That allows to override certain values.
  123. * @param dict the dictionary to fill
  124. */
  125. void populateXObjectDictionary(PDFDictionary dict);
  126. /**
  127. * Get the ICC stream for this image.
  128. *
  129. * @return the ICC stream for this image if any
  130. */
  131. PDFICCStream getICCStream();
  132. /**
  133. * Returns a hint in form of a String (Possible values from PDFFilterList)
  134. * indicating which filter setup should be used to encode the object.
  135. * @return the filter setup hint
  136. */
  137. String getFilterHint();
  138. /**
  139. * Indicates whether multiple image filters are allowed; this is implemented because Adobe
  140. * Reader does not like multiple FlateDecode filters applied to an image even though that
  141. * allowed by the PDF spec; this is probable due to security concerns since many PDF malware
  142. * exploits, like zip bombs, make use of a chain of FlateDecode filters.
  143. */
  144. boolean multipleFiltersAllowed();
  145. }