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.

PDFColorSpace.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.pdf;
  8. public class PDFColorSpace {
  9. private boolean hasICCProfile;
  10. private byte[] iccProfile;
  11. private int numComponents;
  12. // Ok... so I had some grand purpose for this, but I can't recall.
  13. // I'm just writing it
  14. public static int DEVICE_UNKNOWN = -1;
  15. public static int DEVICE_GRAY = 1;
  16. // what's the *official* spelling?
  17. // public static int DEVICE_GREY = 1;
  18. public static int DEVICE_RGB = 2;
  19. public static int DEVICE_CMYK = 3;
  20. // Are there any others?
  21. protected int currentColorSpace = DEVICE_UNKNOWN;
  22. public PDFColorSpace(int theColorSpace) {
  23. this.currentColorSpace = theColorSpace;
  24. hasICCProfile = false;
  25. numComponents = calculateNumComponents();
  26. }
  27. private int calculateNumComponents() {
  28. if (currentColorSpace == DEVICE_GRAY) {
  29. return 1;
  30. } else if (currentColorSpace == DEVICE_RGB) {
  31. return 3;
  32. } else if (currentColorSpace == DEVICE_CMYK) {
  33. return 4;
  34. } else {
  35. return 0;
  36. }
  37. }
  38. public void setColorSpace(int theColorSpace) {
  39. this.currentColorSpace = theColorSpace;
  40. numComponents = calculateNumComponents();
  41. }
  42. public boolean hasICCProfile() {
  43. return hasICCProfile;
  44. }
  45. public byte[] getICCProfile() {
  46. if (hasICCProfile)
  47. return iccProfile;
  48. else
  49. return new byte[0];
  50. }
  51. public void setICCProfile(byte[] iccProfile) {
  52. this.iccProfile = iccProfile;
  53. hasICCProfile = true;
  54. }
  55. public int getColorSpace() {
  56. return (this.currentColorSpace);
  57. }
  58. public int getNumComponents() {
  59. return numComponents;
  60. }
  61. public String getColorSpacePDFString() {
  62. // shouldn't this be a select-case? I can never remember
  63. // the syntax for that.
  64. if (this.currentColorSpace == this.DEVICE_RGB) {
  65. return ("DeviceRGB");
  66. } else if (this.currentColorSpace == this.DEVICE_CMYK) {
  67. return ("DeviceCMYK");
  68. } else if (this.currentColorSpace == this.DEVICE_GRAY) {
  69. return ("DeviceGray");
  70. } else { // unknown... Error. Tell them it's RGB and hope they don't notice.
  71. return ("DeviceRGB");
  72. }
  73. }
  74. }