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 java.awt.color.ColorSpace;
   20   import java.awt.image.ColorModel;
   21   import java.io.IOException;
   22   
   23   import java.awt.Transparency;
   24   import java.awt.image.ComponentColorModel;
   25   import java.awt.image.DataBuffer;
   26   
   27   
   28   /**
   29    * This class represents a CMYK color space.
   30    *
   31    * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
   32    * @version $Revision: 1.6 $
   33    */
   34   public class PDDeviceCMYK extends PDColorSpace
   35   {
   36       /**
   37        * The single instance of this class.
   38        */
   39       public static final PDDeviceCMYK INSTANCE = new PDDeviceCMYK();
   40   
   41       /**
   42        * The name of this color space.
   43        */
   44       public static final String NAME = "DeviceCMYK";
   45   
   46       /**
   47        * The abbreviated name of this color space.
   48        */
   49       public static final String ABBREVIATED_NAME = "CMYK";
   50   
   51       private PDDeviceCMYK()
   52       {
   53       }
   54   
   55       /**
   56        * This will return the name of the color space.
   57        *
   58        * @return The name of the color space.
   59        */
   60       public String getName()
   61       {
   62           return NAME;
   63       }
   64   
   65       /**
   66        * This will get the number of components that this color space is made up of.
   67        *
   68        * @return The number of components in this color space.
   69        *
   70        * @throws IOException If there is an error getting the number of color components.
   71        */
   72       public int getNumberOfComponents() throws IOException
   73       {
   74           return 4;
   75       }
   76   
   77       /**
   78        * Create a Java colorspace for this colorspace.
   79        *
   80        * @return A color space that can be used for Java AWT operations.
   81        */
   82       protected ColorSpace createColorSpace()
   83       {
   84           return new ColorSpaceCMYK();
   85       }
   86   
   87       /**
   88        * Create a Java color model for this colorspace.
   89        *
   90        * @param bpc The number of bits per component.
   91        *
   92        * @return A color model that can be used for Java AWT operations.
   93        *
   94        * @throws IOException If there is an error creating the color model.
   95        */
   96       public ColorModel createColorModel( int bpc ) throws IOException
   97       {
   98   
   99           int[] nbBits = { bpc, bpc, bpc, bpc };
  100           ComponentColorModel componentColorModel = 
  101               new ComponentColorModel( getJavaColorSpace(), 
  102                            nbBits, 
  103                            false,                     
  104                            false,              
  105                            Transparency.OPAQUE,
  106                            DataBuffer.TYPE_BYTE );
  107              return componentColorModel;
  108   
  109       }
  110   }

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