1 31 package org.pdfbox.util.operator; 32 33 import java.util.List ; 34 import java.util.Map ; 35 36 import org.pdfbox.cos.COSName; 37 import org.pdfbox.pdmodel.graphics.color.PDColorSpace; 38 import org.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory; 39 import org.pdfbox.pdmodel.graphics.color.PDColorSpaceInstance; 40 import org.pdfbox.pdmodel.graphics.color.PDDeviceCMYK; 41 import org.pdfbox.util.PDFOperator; 42 43 import java.io.IOException ; 44 45 53 54 public class SetStrokingColorSpace extends OperatorProcessor 55 { 56 private static final float[] EMPTY_FLOAT_ARRAY = new float[0]; 57 58 64 public void process(PDFOperator operator, List arguments) throws IOException 65 { 66 COSName name = (COSName)arguments.get( 0 ); 68 Map colorSpaces = context.getColorSpaces(); 69 PDColorSpace cs = null; 70 if( colorSpaces != null ) 71 { 72 cs = (PDColorSpace)colorSpaces.get( name.getName() ); 73 } 74 if( cs == null ) 75 { 76 cs = PDColorSpaceFactory.createColorSpace( name ); 77 } 78 PDColorSpaceInstance colorInstance = context.getGraphicsState().getStrokingColorSpace(); 79 colorInstance.setColorSpace( cs ); 80 int numComponents = cs.getNumberOfComponents(); 81 float[] values = EMPTY_FLOAT_ARRAY; 82 if( numComponents >= 0 ) 83 { 84 values = new float[numComponents]; 85 for( int i=0; i<numComponents; i++ ) 86 { 87 values[i] = 0f; 88 } 89 if( cs instanceof PDDeviceCMYK ) 90 { 91 values[3] = 1f; 92 } 93 } 94 colorInstance.setColorSpaceValue( values ); 95 } 96 } 97 | Popular Tags |