1 17 18 19 20 package org.apache.fop.pdf; 21 22 25 public class PDFDeviceColorSpace implements PDFColorSpace { 26 27 private int numComponents; 28 29 32 public static final int DEVICE_UNKNOWN = -1; 33 34 37 public static final int DEVICE_GRAY = 1; 38 39 42 public static final int DEVICE_RGB = 2; 43 44 47 public static final int DEVICE_CMYK = 3; 48 49 51 54 protected int currentColorSpace = DEVICE_UNKNOWN; 55 56 61 public PDFDeviceColorSpace(int theColorSpace) { 62 this.currentColorSpace = theColorSpace; 63 numComponents = calculateNumComponents(); 64 } 65 66 private int calculateNumComponents() { 67 if (currentColorSpace == DEVICE_GRAY) { 68 return 1; 69 } else if (currentColorSpace == DEVICE_RGB) { 70 return 3; 71 } else if (currentColorSpace == DEVICE_CMYK) { 72 return 4; 73 } else { 74 return 0; 75 } 76 } 77 78 83 public void setColorSpace(int theColorSpace) { 84 this.currentColorSpace = theColorSpace; 85 numComponents = calculateNumComponents(); 86 } 87 88 93 public int getColorSpace() { 94 return (this.currentColorSpace); 95 } 96 97 102 public int getNumComponents() { 103 return numComponents; 104 } 105 106 107 public String getName() { 108 switch (currentColorSpace) { 109 case DEVICE_CMYK: 110 return "DeviceCMYK"; 111 case DEVICE_GRAY: 112 return "DeviceGray"; 113 case DEVICE_RGB: 114 return "DeviceRGB"; 115 default: 116 throw new IllegalStateException ("Unsupported color space in use."); 117 } 118 } 119 120 121 public boolean isDeviceColorSpace() { 122 return true; 123 } 124 125 126 public boolean isRGBColorSpace() { 127 return getColorSpace() == DEVICE_RGB; 128 } 129 130 131 public boolean isCMYKColorSpace() { 132 return getColorSpace() == DEVICE_CMYK; 133 } 134 135 136 public boolean isGrayColorSpace() { 137 return getColorSpace() == DEVICE_GRAY; 138 } 139 140 } 141 | Popular Tags |