001: /**
002: * Copyright (c) 2004, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.graphics.color;
031:
032: import java.awt.color.ColorSpace;
033: import java.awt.image.ColorModel;
034:
035: import java.io.IOException;
036:
037: import org.pdfbox.cos.COSArray;
038: import org.pdfbox.cos.COSBase;
039: import org.pdfbox.cos.COSName;
040: import org.pdfbox.pdmodel.common.function.PDFunction;
041:
042: /**
043: * This class represents a Separation color space.
044: *
045: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
046: * @version $Revision: 1.4 $
047: */
048: public class PDSeparation extends PDColorSpace {
049: /**
050: * The name of this color space.
051: */
052: public static final String NAME = "Separation";
053:
054: private COSArray array;
055:
056: /**
057: * Constructor.
058: */
059: public PDSeparation() {
060: array = new COSArray();
061: array.add(COSName.getPDFName(NAME));
062: array.add(COSName.getPDFName(""));
063: }
064:
065: /**
066: * Constructor.
067: *
068: * @param separation The array containing all separation information.
069: */
070: public PDSeparation(COSArray separation) {
071: array = separation;
072: }
073:
074: /**
075: * This will return the name of the color space. For a PDSeparation object
076: * this will always return "Separation"
077: *
078: * @return The name of the color space.
079: */
080: public String getName() {
081: return NAME;
082: }
083:
084: /**
085: * This will get the number of components that this color space is made up of.
086: *
087: * @return The number of components in this color space.
088: *
089: * @throws IOException If there is an error getting the number of color components.
090: */
091: public int getNumberOfComponents() throws IOException {
092: return 1;
093: }
094:
095: /**
096: * Create a Java colorspace for this colorspace.
097: *
098: * @return A color space that can be used for Java AWT operations.
099: *
100: * @throws IOException If there is an error creating the color space.
101: */
102: public ColorSpace createColorSpace() throws IOException {
103: throw new IOException("Not implemented");
104: }
105:
106: /**
107: * Create a Java color model for this colorspace.
108: *
109: * @param bpc The number of bits per component.
110: *
111: * @return A color model that can be used for Java AWT operations.
112: *
113: * @throws IOException If there is an error creating the color model.
114: */
115: public ColorModel createColorModel(int bpc) throws IOException {
116: throw new IOException("Not implemented");
117: }
118:
119: /**
120: * This will get the separation name.
121: *
122: * @return The name in the separation.
123: */
124: public String getColorantName() {
125: COSName name = (COSName) array.getObject(1);
126: return name.getName();
127: }
128:
129: /**
130: * This will set the separation name.
131: *
132: * @param name The separation name.
133: */
134: public void setColorantName(String name) {
135: array.set(1, COSName.getPDFName(name));
136: }
137:
138: /**
139: * This will get the alternate color space for this separation.
140: *
141: * @return The alternate color space.
142: *
143: * @throws IOException If there is an error getting the alternate color space.
144: */
145: public PDColorSpace getAlternateColorSpace() throws IOException {
146: COSBase alternate = array.getObject(2);
147: return PDColorSpaceFactory.createColorSpace(alternate);
148: }
149:
150: /**
151: * This will set the alternate color space.
152: *
153: * @param cs The alternate color space.
154: */
155: public void setAlternateColorSpace(PDColorSpace cs) {
156: COSBase space = null;
157: if (cs != null) {
158: space = cs.getCOSObject();
159: }
160: array.set(2, space);
161: }
162:
163: /**
164: * This will get the tint transform function.
165: *
166: * @return The tint transform function.
167: *
168: * @throws IOException If there is an error creating the PDFunction
169: */
170: public PDFunction getTintTransform() throws IOException {
171: return PDFunction.create(array.get(3));
172: }
173:
174: /**
175: * This will set the tint transform function.
176: *
177: * @param tint The tint transform function.
178: */
179: public void setTintTransform(PDFunction tint) {
180: array.set(3, tint);
181: }
182: }
|