KickJava   Java API By Example, From Geeks To Geeks.

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


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$ */
19
20 package org.apache.fop.pdf;
21
22 /**
23  * Represents an ICCBased color space in PDF.
24  */

25 public class PDFICCBasedColorSpace extends PDFObject implements PDFColorSpace {
26
27     private PDFICCStream iccStream;
28     private String JavaDoc explicitName;
29     
30     /**
31      * Constructs a the ICCBased color space with an explicit name (ex. "DefaultRGB").
32      * @param explicitName an explicit name or null if a name should be generated
33      * @param iccStream the ICC stream to associate with this color space
34      */

35     public PDFICCBasedColorSpace(String JavaDoc explicitName, PDFICCStream iccStream) {
36         this.explicitName = explicitName;
37         this.iccStream = iccStream;
38     }
39     
40     /**
41      * Constructs a the ICCBased color space.
42      * @param iccStream the ICC stream to associate with this color space
43      */

44     public PDFICCBasedColorSpace(PDFICCStream iccStream) {
45         this(null, iccStream);
46     }
47     
48     /** @return the ICC stream associated with this color space */
49     public PDFICCStream getICCStream() {
50         return this.iccStream;
51     }
52     
53     /** @see org.apache.fop.pdf.PDFColorSpace#getNumComponents() */
54     public int getNumComponents() {
55         return iccStream.getICCProfile().getNumComponents();
56     }
57
58     /** @see org.apache.fop.pdf.PDFColorSpace#getName() */
59     public String JavaDoc getName() {
60         if (explicitName != null) {
61             return explicitName;
62         } else {
63             return "ICC" + iccStream.getObjectNumber();
64         }
65     }
66
67     /** @see org.apache.fop.pdf.PDFColorSpace#isDeviceColorSpace() */
68     public boolean isDeviceColorSpace() {
69         return false;
70     }
71
72     /** @see org.apache.fop.pdf.PDFColorSpace#isRGBColorSpace() */
73     public boolean isRGBColorSpace() {
74         return getNumComponents() == 3;
75     }
76
77     /** @see org.apache.fop.pdf.PDFColorSpace#isCMYKColorSpace() */
78     public boolean isCMYKColorSpace() {
79         return getNumComponents() == 4;
80     }
81
82     /** @see org.apache.fop.pdf.PDFColorSpace#isGrayColorSpace() */
83     public boolean isGrayColorSpace() {
84         return getNumComponents() == 1;
85     }
86
87     /** @see org.apache.fop.pdf.PDFObject#toPDFString() */
88     protected String JavaDoc toPDFString() {
89         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(64);
90         sb.append(getObjectID());
91         sb.append("[/ICCBased ").append(getICCStream().referencePDF()).append("]");
92         sb.append("\nendobj\n");
93         return sb.toString();
94     }
95
96 }
97
Popular Tags