1 31 package org.pdfbox.pdmodel.graphics.color; 32 33 import java.awt.color.ColorSpace ; 34 import java.awt.image.ColorModel ; 35 36 import java.io.IOException ; 37 38 import java.util.List ; 39 40 import org.pdfbox.cos.COSArray; 41 import org.pdfbox.cos.COSBase; 42 import org.pdfbox.cos.COSName; 43 import org.pdfbox.cos.COSNull; 44 45 import org.pdfbox.pdmodel.common.COSArrayList; 46 47 53 public class PDDeviceN extends PDColorSpace 54 { 55 58 public static final String NAME = "DeviceN"; 59 60 private COSArray array; 61 62 65 public PDDeviceN() 66 { 67 array = new COSArray(); 68 array.add( COSName.getPDFName( NAME ) ); 69 array.add( COSName.getPDFName( "" ) ); 70 } 71 72 77 public PDDeviceN( COSArray separation ) 78 { 79 array = separation; 80 } 81 82 88 public String getName() 89 { 90 return NAME; 91 } 92 93 100 public int getNumberOfComponents() throws IOException 101 { 102 return getColorantNames().size(); 103 } 104 105 112 public ColorSpace createColorSpace() throws IOException 113 { 114 throw new IOException ( "Not implemented" ); 115 } 116 117 126 public ColorModel createColorModel( int bpc ) throws IOException 127 { 128 throw new IOException ( "Not implemented" ); 129 } 130 131 136 public List getColorantNames() 137 { 138 COSArray names = (COSArray)array.getObject( 1 ); 139 return COSArrayList.convertCOSNameCOSArrayToList( names ); 140 } 141 142 147 public void setColorantNames( List names ) 148 { 149 COSArray namesArray = COSArrayList.convertStringListToCOSNameCOSArray( names ); 150 array.set( 1, namesArray ); 151 } 152 153 160 public PDColorSpace getAlternateColorSpace() throws IOException 161 { 162 COSBase alternate = array.getObject( 2 ); 163 return PDColorSpaceFactory.createColorSpace( alternate ); 164 } 165 166 171 public void setAlternateColorSpace( PDColorSpace cs ) 172 { 173 COSBase space = null; 174 if( cs != null ) 175 { 176 space = cs.getCOSObject(); 177 } 178 array.set( 2, space ); 179 } 180 181 188 public COSBase getTintTransform() 189 { 190 return array.get( 3 ); 191 } 192 193 200 public void setTintTransform( COSBase tint ) 201 { 202 array.set( 3, tint ); 203 } 204 205 211 public PDDeviceNAttributes getAttributes() 212 { 213 PDDeviceNAttributes retval = null; 214 if( array.size() <5) 215 { 216 retval = new PDDeviceNAttributes(); 217 setAttributes( retval ); 218 } 219 return retval; 220 } 221 222 228 public void setAttributes( PDDeviceNAttributes attributes ) 229 { 230 if( attributes == null ) 231 { 232 array.remove( 4 ); 233 } 234 else 235 { 236 while( array.size() < 5 ) 238 { 239 array.add( COSNull.NULL ); 240 } 241 array.set( 4, attributes.getCOSDictionary() ); 242 } 243 } 244 } | Popular Tags |