001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id$ */
019:
020: package org.apache.fop.util;
021:
022: import java.awt.Color;
023: import java.awt.color.ColorSpace;
024:
025: /**
026: * Color helper class.
027: * <p>
028: * This class extends java.awt.Color class keeping track of the original color
029: * property values specified by the fo user in a rgb-icc call.
030: */
031: public final class ColorExt extends Color {
032: //
033: private static final long serialVersionUID = 1L;
034:
035: // Values of fop-rgb-icc arguments
036: private float rgbReplacementRed;
037: private float rgbReplacementGreen;
038: private float rgbReplacementBlue;
039:
040: private String iccProfileName;
041: private String iccProfileSrc;
042: private ColorSpace colorSpace;
043:
044: private float[] colorValues;
045:
046: /*
047: * Helper for createFromFoRgbIcc
048: */
049: private ColorExt(ColorSpace colorSpace, float[] colorValues,
050: float opacity) {
051: super (colorSpace, colorValues, opacity);
052: }
053:
054: /*
055: * Helper for createFromSvgIccColor
056: */
057: private ColorExt(float red, float green, float blue, float opacity) {
058: super (red, green, blue, opacity);
059: }
060:
061: /**
062: * Create ColorExt object backup up FO's rgb-icc color function
063: *
064: * @param redReplacement
065: * Red part of RGB replacement color that will be used when ICC
066: * profile can not be loaded
067: * @param greenReplacement
068: * Green part of RGB replacement color that will be used when ICC
069: * profile can not be loaded
070: * @param blueReplacement
071: * Blue part of RGB replacement color that will be used when ICC
072: * profile can not be loaded
073: * @param profileName
074: * Name of ICC profile
075: * @param profileSrc
076: * Source of ICC profile
077: * @param colorSpace
078: * ICC ColorSpace for the ICC profile
079: * @param iccValues
080: * color values
081: * @return the requested color object
082: */
083: public static ColorExt createFromFoRgbIcc(float redReplacement,
084: float greenReplacement, float blueReplacement,
085: String profileName, String profileSrc,
086: ColorSpace colorSpace, float[] iccValues) {
087: ColorExt ce = new ColorExt(colorSpace, iccValues, 1.0f);
088: ce.rgbReplacementRed = redReplacement;
089: ce.rgbReplacementGreen = greenReplacement;
090: ce.rgbReplacementBlue = blueReplacement;
091: ce.iccProfileName = profileName;
092: ce.iccProfileSrc = profileSrc;
093: ce.colorSpace = colorSpace;
094: ce.colorValues = iccValues;
095: return ce;
096: }
097:
098: /**
099: * Create ColorExt object backing up SVG's icc-color function.
100: *
101: * @param red
102: * Red value resulting from the conversion from the user provided
103: * (icc) color values to the batik (rgb) color space
104: * @param green
105: * Green value resulting from the conversion from the user
106: * provided (icc) color values to the batik (rgb) color space
107: * @param blue
108: * Blue value resulting from the conversion from the user
109: * provided (icc) color values to the batik (rgb) color space
110: * @param opacity
111: * Opacity
112: * @param profileName
113: * ICC profile name
114: * @param profileHref
115: * the URI to the color profile
116: * @param profileCS
117: * ICC ColorSpace profile
118: * @param colorValues
119: * ICC color values
120: * @return the requested color object
121: */
122: public static ColorExt createFromSvgIccColor(float red,
123: float green, float blue, float opacity, String profileName,
124: String profileHref, ColorSpace profileCS,
125: float[] colorValues) {
126: ColorExt ce = new ColorExt(red, green, blue, opacity);
127: ce.rgbReplacementRed = -1;
128: ce.rgbReplacementGreen = -1;
129: ce.rgbReplacementBlue = -1;
130: ce.iccProfileName = profileName;
131: ce.iccProfileSrc = profileHref;
132: ce.colorSpace = profileCS;
133: ce.colorValues = colorValues;
134: return ce;
135:
136: }
137:
138: /**
139: * Get ICC profile name
140: *
141: * @return ICC profile name
142: */
143: public String getIccProfileName() {
144: return this .iccProfileName;
145: }
146:
147: /**
148: * Get ICC profile source
149: *
150: * @return ICC profile source
151: */
152: public String getIccProfileSrc() {
153: return this .iccProfileSrc;
154: }
155:
156: /**
157: * @return the original ColorSpace
158: */
159: public ColorSpace getOrigColorSpace() {
160: return this .colorSpace;
161: }
162:
163: /**
164: * @return the original color values
165: */
166: public float[] getOriginalColorComponents() {
167: return this .colorValues;
168: }
169:
170: /**
171: * Create string representation of fop-rgb-icc function call to map this
172: * ColorExt settings
173: * @return the string representing the internal fop-rgb-icc() function call
174: */
175: public String toFunctionCall() {
176: StringBuffer sb = new StringBuffer(40);
177: sb.append("fop-rgb-icc(");
178: sb.append(this .rgbReplacementRed + ",");
179: sb.append(this .rgbReplacementGreen + ",");
180: sb.append(this .rgbReplacementBlue + ",");
181: sb.append(this .iccProfileName + ",");
182: sb.append("\"" + this .iccProfileSrc + "\"");
183: float[] colorComponents = this .getColorComponents(null);
184: for (int ix = 0; ix < colorComponents.length; ix++) {
185: sb.append(",");
186: sb.append(colorComponents[ix]);
187: }
188: sb.append(")");
189: return sb.toString();
190: }
191:
192: }
|