KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > util > ColorExt


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.util;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.color.ColorSpace JavaDoc;
24
25 /**
26  * Color helper class.
27  * <p>
28  * This class extends java.awt.Color class keeping track of the original color
29  * property values specified by the fo user in a rgb-icc call.
30  */

31 public final class ColorExt extends Color JavaDoc {
32     //
33
private static final long serialVersionUID = 1L;
34
35     // Values of fop-rgb-icc arguments
36
private float rgbReplacementRed;
37     private float rgbReplacementGreen;
38     private float rgbReplacementBlue;
39     
40     private String JavaDoc iccProfileName;
41     private String JavaDoc iccProfileSrc;
42     private ColorSpace JavaDoc colorSpace;
43     
44     private float[] colorValues;
45
46     /*
47      * Helper for createFromFoRgbIcc
48      */

49     private ColorExt(ColorSpace JavaDoc colorSpace, float[] colorValues, float opacity) {
50         super(colorSpace, colorValues, opacity);
51     }
52
53     /*
54      * Helper for createFromSvgIccColor
55      */

56     private ColorExt(float red, float green, float blue, float opacity) {
57         super(red, green, blue, opacity);
58     }
59
60     /**
61      * Create ColorExt object backup up FO's rgb-icc color function
62      *
63      * @param redReplacement
64      * Red part of RGB replacement color that will be used when ICC
65      * profile can not be loaded
66      * @param greenReplacement
67      * Green part of RGB replacement color that will be used when ICC
68      * profile can not be loaded
69      * @param blueReplacement
70      * Blue part of RGB replacement color that will be used when ICC
71      * profile can not be loaded
72      * @param profileName
73      * Name of ICC profile
74      * @param profileSrc
75      * Source of ICC profile
76      * @param colorSpace
77      * ICC ColorSpace for the ICC profile
78      * @param iccValues
79      * color values
80      * @return the requested color object
81      */

82     public static ColorExt createFromFoRgbIcc(float redReplacement,
83             float greenReplacement, float blueReplacement, String JavaDoc profileName,
84             String JavaDoc profileSrc, ColorSpace JavaDoc colorSpace, float[] iccValues) {
85         ColorExt ce = new ColorExt(colorSpace, iccValues, 1.0f);
86         ce.rgbReplacementRed = redReplacement;
87         ce.rgbReplacementGreen = greenReplacement;
88         ce.rgbReplacementBlue = blueReplacement;
89         ce.iccProfileName = profileName;
90         ce.iccProfileSrc = profileSrc;
91         ce.colorSpace = colorSpace;
92         ce.colorValues = iccValues;
93         return ce;
94     }
95
96     /**
97      * Create ColorExt object backing up SVG's icc-color function.
98      *
99      * @param red
100      * Red value resulting from the conversion from the user provided
101      * (icc) color values to the batik (rgb) color space
102      * @param green
103      * Green value resulting from the conversion from the user
104      * provided (icc) color values to the batik (rgb) color space
105      * @param blue
106      * Blue value resulting from the conversion from the user
107      * provided (icc) color values to the batik (rgb) color space
108      * @param opacity
109      * Opacity
110      * @param profileName
111      * ICC profile name
112      * @param profileHref
113      * the URI to the color profile
114      * @param profileCS
115      * ICC ColorSpace profile
116      * @param colorValues
117      * ICC color values
118      * @return the requested color object
119      */

120     public static ColorExt createFromSvgIccColor(float red, float green,
121             float blue, float opacity, String JavaDoc profileName, String JavaDoc profileHref,
122             ColorSpace JavaDoc profileCS, float[] colorValues) {
123         ColorExt ce = new ColorExt(red, green, blue, opacity);
124         ce.rgbReplacementRed = -1;
125         ce.rgbReplacementGreen = -1;
126         ce.rgbReplacementBlue = -1;
127         ce.iccProfileName = profileName;
128         ce.iccProfileSrc = profileHref;
129         ce.colorSpace = profileCS;
130         ce.colorValues = colorValues;
131         return ce;
132
133     }
134
135     /**
136      * Get ICC profile name
137      *
138      * @return ICC profile name
139      */

140     public String JavaDoc getIccProfileName() {
141         return this.iccProfileName;
142     }
143
144     /**
145      * Get ICC profile source
146      *
147      * @return ICC profile source
148      */

149     public String JavaDoc getIccProfileSrc() {
150         return this.iccProfileSrc;
151     }
152
153     /**
154      * @return the original ColorSpace
155      */

156     public ColorSpace JavaDoc getOrigColorSpace() {
157         return this.colorSpace;
158     }
159
160     /**
161      * @return the original color values
162      */

163     public float[] getOriginalColorComponents() {
164         return this.colorValues;
165     }
166
167     /**
168      * Create string representation of fop-rgb-icc function call to map this
169      * ColorExt settings
170      * @return the string representing the internal fop-rgb-icc() function call
171      */

172     public String JavaDoc toFunctionCall() {
173         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(40);
174         sb.append("fop-rgb-icc(");
175         sb.append(this.rgbReplacementRed + ",");
176         sb.append(this.rgbReplacementGreen + ",");
177         sb.append(this.rgbReplacementBlue + ",");
178         sb.append(this.iccProfileName + ",");
179         sb.append("\"" + this.iccProfileSrc + "\"");
180         float[] colorComponents = this.getColorComponents(null);
181         for (int ix = 0; ix < colorComponents.length; ix++) {
182             sb.append(",");
183             sb.append(colorComponents[ix]);
184         }
185         sb.append(")");
186         return sb.toString();
187     }
188
189 }
190
Popular Tags