You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ColorExt.java 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. /* $Id$ */
  18. package org.apache.fop.util;
  19. import java.awt.Color;
  20. import java.awt.color.ColorSpace;
  21. import java.util.Arrays;
  22. /**
  23. * Color helper class.
  24. * <p>
  25. * This class extends java.awt.Color class keeping track of the original color
  26. * property values specified by the fo user in a rgb-icc call.
  27. * @deprecated Replaced by {@link org.apache.xmlgraphics.java2d.color.ColorWithAlternatives}
  28. */
  29. @Deprecated
  30. public final class ColorExt extends Color {
  31. //
  32. private static final long serialVersionUID = 1L;
  33. // Values of fop-rgb-icc arguments
  34. private float rgbReplacementRed;
  35. private float rgbReplacementGreen;
  36. private float rgbReplacementBlue;
  37. private String iccProfileName;
  38. private String iccProfileSrc;
  39. private ColorSpace colorSpace;
  40. private float[] colorValues;
  41. /*
  42. * Helper for createFromFoRgbIcc
  43. */
  44. private ColorExt(ColorSpace colorSpace, float[] colorValues, float opacity) {
  45. super(colorSpace, colorValues, opacity);
  46. }
  47. /*
  48. * Helper for createFromSvgIccColor
  49. */
  50. private ColorExt(float red, float green, float blue, float opacity) {
  51. super(red, green, blue, opacity);
  52. }
  53. /**
  54. * Create ColorExt object backup up FO's rgb-icc color function
  55. *
  56. * @param redReplacement
  57. * Red part of RGB replacement color that will be used when ICC
  58. * profile can not be loaded
  59. * @param greenReplacement
  60. * Green part of RGB replacement color that will be used when ICC
  61. * profile can not be loaded
  62. * @param blueReplacement
  63. * Blue part of RGB replacement color that will be used when ICC
  64. * profile can not be loaded
  65. * @param profileName
  66. * Name of ICC profile
  67. * @param profileSrc
  68. * Source of ICC profile
  69. * @param colorSpace
  70. * ICC ColorSpace for the ICC profile
  71. * @param iccValues
  72. * color values
  73. * @return the requested color object
  74. */
  75. public static ColorExt createFromFoRgbIcc(float redReplacement,
  76. float greenReplacement, float blueReplacement, String profileName,
  77. String profileSrc, ColorSpace colorSpace, float[] iccValues) {
  78. ColorExt ce = new ColorExt(colorSpace, iccValues, 1.0f);
  79. ce.rgbReplacementRed = redReplacement;
  80. ce.rgbReplacementGreen = greenReplacement;
  81. ce.rgbReplacementBlue = blueReplacement;
  82. ce.iccProfileName = profileName;
  83. ce.iccProfileSrc = profileSrc;
  84. ce.colorSpace = colorSpace;
  85. ce.colorValues = iccValues;
  86. return ce;
  87. }
  88. /**
  89. * Create ColorExt object backing up SVG's icc-color function.
  90. *
  91. * @param red
  92. * Red value resulting from the conversion from the user provided
  93. * (icc) color values to the batik (rgb) color space
  94. * @param green
  95. * Green value resulting from the conversion from the user
  96. * provided (icc) color values to the batik (rgb) color space
  97. * @param blue
  98. * Blue value resulting from the conversion from the user
  99. * provided (icc) color values to the batik (rgb) color space
  100. * @param opacity
  101. * Opacity
  102. * @param profileName
  103. * ICC profile name
  104. * @param profileHref
  105. * the URI to the color profile
  106. * @param profileCS
  107. * ICC ColorSpace profile
  108. * @param colorValues
  109. * ICC color values
  110. * @return the requested color object
  111. */
  112. public static ColorExt createFromSvgIccColor( // CSOK: ParameterNumber
  113. float red, float green,
  114. float blue, float opacity, String profileName, String profileHref,
  115. ColorSpace profileCS, float[] colorValues) {
  116. //TODO this method is not referenced by FOP, can it be deleted?
  117. ColorExt ce = new ColorExt(red, green, blue, opacity);
  118. ce.rgbReplacementRed = -1;
  119. ce.rgbReplacementGreen = -1;
  120. ce.rgbReplacementBlue = -1;
  121. ce.iccProfileName = profileName;
  122. ce.iccProfileSrc = profileHref;
  123. ce.colorSpace = profileCS;
  124. ce.colorValues = colorValues;
  125. return ce;
  126. }
  127. /** {@inheritDoc} */
  128. @Override
  129. public int hashCode() {
  130. //implementation from the superclass should be good enough for our purposes
  131. return super.hashCode();
  132. }
  133. /** {@inheritDoc} */
  134. @Override
  135. public boolean equals(Object obj) {
  136. if (this == obj) {
  137. return true;
  138. }
  139. if (!super.equals(obj)) {
  140. return false;
  141. }
  142. if (getClass() != obj.getClass()) {
  143. return false;
  144. }
  145. ColorExt other = (ColorExt)obj;
  146. //TODO maybe use super.getColorComponents() instead
  147. if (!Arrays.equals(colorValues, other.colorValues)) {
  148. return false;
  149. }
  150. if (iccProfileName == null) {
  151. if (other.iccProfileName != null) {
  152. return false;
  153. }
  154. } else if (!iccProfileName.equals(other.iccProfileName)) {
  155. return false;
  156. }
  157. if (iccProfileSrc == null) {
  158. if (other.iccProfileSrc != null) {
  159. return false;
  160. }
  161. } else if (!iccProfileSrc.equals(other.iccProfileSrc)) {
  162. return false;
  163. }
  164. if (Float.floatToIntBits(rgbReplacementBlue)
  165. != Float.floatToIntBits(other.rgbReplacementBlue)) {
  166. return false;
  167. }
  168. if (Float.floatToIntBits(rgbReplacementGreen)
  169. != Float.floatToIntBits(other.rgbReplacementGreen)) {
  170. return false;
  171. }
  172. if (Float.floatToIntBits(rgbReplacementRed)
  173. != Float.floatToIntBits(other.rgbReplacementRed)) {
  174. return false;
  175. }
  176. return true;
  177. }
  178. /**
  179. * Get ICC profile name
  180. *
  181. * @return ICC profile name
  182. */
  183. public String getIccProfileName() {
  184. return this.iccProfileName;
  185. }
  186. /**
  187. * Get ICC profile source
  188. *
  189. * @return ICC profile source
  190. */
  191. public String getIccProfileSrc() {
  192. return this.iccProfileSrc;
  193. }
  194. /**
  195. * @return the original ColorSpace
  196. */
  197. public ColorSpace getOrigColorSpace() {
  198. //TODO this method is probably unnecessary due to super.cs and getColorSpace()
  199. return this.colorSpace;
  200. }
  201. /**
  202. * Returns the original color values.
  203. * @return the original color values
  204. */
  205. public float[] getOriginalColorComponents() {
  206. //TODO this method is probably unnecessary due to super.fvalue and getColorComponents()
  207. float[] copy = new float[this.colorValues.length];
  208. System.arraycopy(this.colorValues, 0, copy, 0, copy.length);
  209. return copy;
  210. }
  211. /**
  212. * Create string representation of fop-rgb-icc function call to map this
  213. * ColorExt settings
  214. * @return the string representing the internal fop-rgb-icc() function call
  215. */
  216. public String toFunctionCall() {
  217. StringBuffer sb = new StringBuffer(40);
  218. sb.append("fop-rgb-icc(");
  219. sb.append(this.rgbReplacementRed + ",");
  220. sb.append(this.rgbReplacementGreen + ",");
  221. sb.append(this.rgbReplacementBlue + ",");
  222. sb.append(this.iccProfileName + ",");
  223. if (this.iccProfileSrc != null) {
  224. sb.append("\"" + this.iccProfileSrc + "\"");
  225. }
  226. float[] colorComponents = this.getColorComponents(null);
  227. for (int ix = 0; ix < colorComponents.length; ix++) {
  228. sb.append(",");
  229. sb.append(colorComponents[ix]);
  230. }
  231. sb.append(")");
  232. return sb.toString();
  233. }
  234. }