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.

PDFICCStream.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.awt.color.ICC_Profile;
  20. import java.io.IOException;
  21. import java.io.OutputStream;
  22. /**
  23. * Special PDFStream for ICC profiles (color profiles).
  24. */
  25. public class PDFICCStream extends PDFStream {
  26. private ICC_Profile cp;
  27. private PDFDeviceColorSpace pdfColorSpace;
  28. /**
  29. * @see org.apache.fop.pdf.PDFObject#PDFObject()
  30. */
  31. public PDFICCStream() {
  32. super();
  33. cp = null;
  34. }
  35. /**
  36. * Sets the color space to encode in PDF.
  37. * @param icc the ICC profile
  38. * @param alt the PDF color space
  39. */
  40. public void setColorSpace(ICC_Profile icc, PDFDeviceColorSpace alt) {
  41. this.cp = icc;
  42. pdfColorSpace = alt;
  43. }
  44. /**
  45. * Returns the associated ICC profile. Note that this will return null once the
  46. * ICC stream has been written to the PDF file.
  47. * @return the ICC profile (or null if the stream has already been written)
  48. */
  49. public ICC_Profile getICCProfile() {
  50. return this.cp;
  51. }
  52. /**
  53. * overload the base object method so we don't have to copy
  54. * byte arrays around so much
  55. * {@inheritDoc}
  56. */
  57. @Override
  58. public int output(java.io.OutputStream stream)
  59. throws java.io.IOException {
  60. int length = super.output(stream);
  61. this.cp = null; //Free ICC stream when it's not used anymore
  62. return length;
  63. }
  64. /** {@inheritDoc} */
  65. @Override
  66. protected void outputRawStreamData(OutputStream out) throws IOException {
  67. cp.write(out);
  68. }
  69. /** {@inheritDoc} */
  70. @Override
  71. protected void populateStreamDict(Object lengthEntry) {
  72. put("N", cp.getNumComponents());
  73. if (pdfColorSpace != null) {
  74. put("Alternate", new PDFName(pdfColorSpace.getName()));
  75. }
  76. super.populateStreamDict(lengthEntry);
  77. }
  78. }