KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > pdf > PDFDeviceColorSpace


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
18 /* $Id: PDFDeviceColorSpace.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.pdf;
21
22 /**
23  * Represents a device-specific color space. Used for mapping DeviceRGB, DeviceCMYK and DeviceGray.
24  */

25 public class PDFDeviceColorSpace implements PDFColorSpace {
26     
27     private int numComponents;
28
29     /**
30      * Unknown colorspace
31      */

32     public static final int DEVICE_UNKNOWN = -1;
33
34     /**
35      * Gray colorspace
36      */

37     public static final int DEVICE_GRAY = 1;
38
39     /**
40      * RGB colorspace
41      */

42     public static final int DEVICE_RGB = 2;
43
44     /**
45      * CMYK colorspace
46      */

47     public static final int DEVICE_CMYK = 3;
48
49     // Are there any others?
50

51     /**
52      * Current color space value.
53      */

54     protected int currentColorSpace = DEVICE_UNKNOWN;
55
56     /**
57      * Create a PDF colorspace object.
58      *
59      * @param theColorSpace the current colorspace
60      */

61     public PDFDeviceColorSpace(int theColorSpace) {
62         this.currentColorSpace = theColorSpace;
63         numComponents = calculateNumComponents();
64     }
65
66     private int calculateNumComponents() {
67         if (currentColorSpace == DEVICE_GRAY) {
68             return 1;
69         } else if (currentColorSpace == DEVICE_RGB) {
70             return 3;
71         } else if (currentColorSpace == DEVICE_CMYK) {
72             return 4;
73         } else {
74             return 0;
75         }
76     }
77
78     /**
79      * Set the current colorspace.
80      *
81      * @param theColorSpace the new color space value
82      */

83     public void setColorSpace(int theColorSpace) {
84         this.currentColorSpace = theColorSpace;
85         numComponents = calculateNumComponents();
86     }
87
88     /**
89      * Get the colorspace value
90      *
91      * @return the colorspace value
92      */

93     public int getColorSpace() {
94         return (this.currentColorSpace);
95     }
96
97     /**
98      * Get the number of color components for this colorspace
99      *
100      * @return the number of components
101      */

102     public int getNumComponents() {
103         return numComponents;
104     }
105
106     /** @return the name of the color space */
107     public String JavaDoc getName() {
108         switch (currentColorSpace) {
109         case DEVICE_CMYK:
110             return "DeviceCMYK";
111         case DEVICE_GRAY:
112             return "DeviceGray";
113         case DEVICE_RGB:
114             return "DeviceRGB";
115         default:
116             throw new IllegalStateException JavaDoc("Unsupported color space in use.");
117         }
118     }
119
120     /** @see org.apache.fop.pdf.PDFColorSpace#isDeviceColorSpace() */
121     public boolean isDeviceColorSpace() {
122         return true;
123     }
124
125     /** @see org.apache.fop.pdf.PDFColorSpace#isRGBColorSpace() */
126     public boolean isRGBColorSpace() {
127         return getColorSpace() == DEVICE_RGB;
128     }
129
130     /** @see org.apache.fop.pdf.PDFColorSpace#isCMYKColorSpace() */
131     public boolean isCMYKColorSpace() {
132         return getColorSpace() == DEVICE_CMYK;
133     }
134
135     /** @see org.apache.fop.pdf.PDFColorSpace#isGrayColorSpace() */
136     public boolean isGrayColorSpace() {
137         return getColorSpace() == DEVICE_GRAY;
138     }
139     
140 }
141
Popular Tags