Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.graphics.color » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.pdfbox.pdmodel.graphics.color;
   18   
   19   import org.apache.pdfbox.cos.COSBase;
   20   import org.apache.pdfbox.cos.COSDictionary;
   21   import org.apache.pdfbox.cos.COSName;
   22   
   23   import org.apache.pdfbox.pdmodel.common.COSDictionaryMap;
   24   
   25   import java.io.IOException;
   26   
   27   import java.util.HashMap;
   28   import java.util.Iterator;
   29   import java.util.Map;
   30   
   31   /**
   32    * This class represents attributes for a DeviceN color space.
   33    *
   34    * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
   35    * @version $Revision: 1.2 $
   36    */
   37   public class PDDeviceNAttributes
   38   {
   39       private COSDictionary dictionary;
   40   
   41       /**
   42        * Constructor.
   43        */
   44       public PDDeviceNAttributes()
   45       {
   46           dictionary = new COSDictionary();
   47       }
   48   
   49       /**
   50        * Constructor.
   51        *
   52        * @param attributes A dictionary that has all of the attributes.
   53        */
   54       public PDDeviceNAttributes( COSDictionary attributes )
   55       {
   56           dictionary = attributes;
   57       }
   58   
   59       /**
   60        * This will get the underlying cos dictionary.
   61        *
   62        * @return The dictionary that this object wraps.
   63        */
   64       public COSDictionary getCOSDictionary()
   65       {
   66           return dictionary;
   67       }
   68   
   69       /**
   70        * This will get a map of colorants.  See the PDF Reference for more details about
   71        * this attribute.  The map will contain a java.lang.String as the key, a colorant name,
   72        * and a PDColorSpace as the value.
   73        *
   74        * @return The colorant map.
   75        *
   76        * @throws IOException If there is an error getting the colorspaces.
   77        */
   78       public Map getColorants() throws IOException
   79       {
   80           Map actuals = new HashMap();
   81           COSDictionary colorants = (COSDictionary)dictionary.getDictionaryObject( COSName.getPDFName( "Colorants" ) );
   82           if( colorants == null )
   83           {
   84               colorants = new COSDictionary();
   85               dictionary.setItem( COSName.getPDFName( "Colorants" ), colorants );
   86           }
   87           for( COSName name : colorants.keySet() )
   88           {
   89               COSBase value = colorants.getDictionaryObject( name );
   90               actuals.put( name.getName(), PDColorSpaceFactory.createColorSpace( value ) );
   91           }
   92           return new COSDictionaryMap( actuals, colorants );
   93       }
   94   
   95       /**
   96        * This will replace the existing colorant attribute.  The key should be strings
   97        * and the values should be PDColorSpaces.
   98        *
   99        * @param colorants The map of colorants.
  100        */
  101       public void setColorants( Map colorants )
  102       {
  103           COSDictionary colorantDict = null;
  104           if( colorants != null )
  105           {
  106               colorantDict = COSDictionaryMap.convert( colorants );
  107           }
  108           dictionary.setItem( COSName.getPDFName( "Colorants" ), colorantDict );
  109       }
  110   }

Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.graphics.color » [javadoc | source]