1 31 package org.pdfbox.pdmodel.graphics.color; 32 33 import java.awt.Color ; 34 import java.awt.color.ColorSpace ; 35 import java.io.IOException ; 36 37 import org.pdfbox.cos.COSArray; 38 import org.pdfbox.cos.COSFloat; 39 40 46 public class PDColorSpaceInstance 47 { 48 private PDColorSpace colorSpace = new PDDeviceGray(); 49 private COSArray colorSpaceValue = new COSArray(); 50 51 55 public PDColorSpaceInstance() 56 { 57 colorSpaceValue.add( new COSFloat( 0 ) ); 58 } 59 60 65 public Color createColor() throws IOException 66 { 67 Color retval = null; 68 float[] components = colorSpaceValue.toFloatArray(); 69 if( components.length == 3 ) 70 { 71 retval = new Color ( components[0], components[1], components[2] ); 76 } 77 else 78 { 79 ColorSpace cs = colorSpace.createColorSpace(); 80 retval = new Color ( cs, components, 1f ); 81 } 82 return retval; 83 } 84 85 90 public PDColorSpaceInstance( COSArray csValues ) 91 { 92 colorSpaceValue = csValues; 93 } 94 95 96 101 public PDColorSpace getColorSpace() 102 { 103 return colorSpace; 104 } 105 106 111 public void setColorSpace(PDColorSpace value) 112 { 113 colorSpace = value; 114 } 115 116 121 public float[] getColorSpaceValue() 122 { 123 return colorSpaceValue.toFloatArray(); 124 } 125 126 131 public COSArray getCOSColorSpaceValue() 132 { 133 return colorSpaceValue; 134 } 135 136 141 public void setColorSpaceValue(float[] value) 142 { 143 colorSpaceValue.setFloatArray( value ); 144 } 145 } 146 | Popular Tags |