KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > graphics > color > PDDeviceNAttributes


1 /**
2  * Copyright (c) 2004, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

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 JavaDoc;
40
41 import java.util.HashMap JavaDoc;
42 import java.util.Iterator JavaDoc;
43 import java.util.Map JavaDoc;
44
45 /**
46  * This class represents attributes for a DeviceN color space.
47  *
48  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
49  * @version $Revision: 1.2 $
50  */

51 public class PDDeviceNAttributes
52 {
53     private COSDictionary dictionary;
54
55     /**
56      * Constructor.
57      */

58     public PDDeviceNAttributes()
59     {
60         dictionary = new COSDictionary();
61     }
62
63     /**
64      * Constructor.
65      *
66      * @param attributes A dictionary that has all of the attributes.
67      */

68     public PDDeviceNAttributes( COSDictionary attributes )
69     {
70         dictionary = attributes;
71     }
72
73     /**
74      * This will get the underlying cos dictionary.
75      *
76      * @return The dictionary that this object wraps.
77      */

78     public COSDictionary getCOSDictionary()
79     {
80         return dictionary;
81     }
82
83     /**
84      * This will get a map of colorants. See the PDF Reference for more details about
85      * this attribute. The map will contain a java.lang.String as the key, a colorant name,
86      * and a PDColorSpace as the value.
87      *
88      * @return The colorant map.
89      *
90      * @throws IOException If there is an error getting the colorspaces.
91      */

92     public Map getColorants() throws IOException JavaDoc
93     {
94         Map actuals = new HashMap JavaDoc();
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 JavaDoc 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     /**
112      * This will replace the existing colorant attribute. The key should be strings
113      * and the values should be PDColorSpaces.
114      *
115      * @param colorants The map of colorants.
116      */

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