1 31 package org.pdfbox.pdmodel.graphics.color; 32 33 import org.pdfbox.cos.COSBase; 34 import org.pdfbox.cos.COSDictionary; 35 import org.pdfbox.cos.COSName; 36 37 import org.pdfbox.pdmodel.common.COSDictionaryMap; 38 39 import java.io.IOException ; 40 41 import java.util.HashMap ; 42 import java.util.Iterator ; 43 import java.util.Map ; 44 45 51 public class PDDeviceNAttributes 52 { 53 private COSDictionary dictionary; 54 55 58 public PDDeviceNAttributes() 59 { 60 dictionary = new COSDictionary(); 61 } 62 63 68 public PDDeviceNAttributes( COSDictionary attributes ) 69 { 70 dictionary = attributes; 71 } 72 73 78 public COSDictionary getCOSDictionary() 79 { 80 return dictionary; 81 } 82 83 92 public Map getColorants() throws IOException 93 { 94 Map actuals = new HashMap (); 95 COSDictionary colorants = (COSDictionary)dictionary.getDictionaryObject( COSName.getPDFName( "Colorants" ) ); 96 if( colorants == null ) 97 { 98 colorants = new COSDictionary(); 99 dictionary.setItem( COSName.getPDFName( "Colorants" ), colorants ); 100 } 101 Iterator iter = colorants.keyList().iterator(); 102 while( iter.hasNext() ) 103 { 104 COSName name = (COSName)iter.next(); 105 COSBase value = colorants.getDictionaryObject( name ); 106 actuals.put( name.getName(), PDColorSpaceFactory.createColorSpace( value ) ); 107 } 108 return new COSDictionaryMap( actuals, colorants ); 109 } 110 111 117 public void setColorants( Map colorants ) 118 { 119 COSDictionary colorantDict = null; 120 if( colorants != null ) 121 { 122 colorantDict = COSDictionaryMap.convert( colorants ); 123 } 124 dictionary.setItem( COSName.getPDFName( "Colorants" ), colorantDict ); 125 } 126 } | Popular Tags |