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.

ColorUtil.java 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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.Collections;
  22. import java.util.LinkedList;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.StringTokenizer;
  26. import org.apache.commons.logging.Log;
  27. import org.apache.commons.logging.LogFactory;
  28. import org.apache.fop.apps.FOUserAgent;
  29. import org.apache.fop.fo.expr.PropertyException;
  30. /**
  31. * Generic Color helper class.
  32. * <p>
  33. * This class supports parsing string values into color values and creating
  34. * color values for strings. It provides a list of standard color names.
  35. */
  36. public final class ColorUtil {
  37. /**
  38. *
  39. * keeps all the predefined and parsed colors.
  40. * <p>
  41. * This map is used to predefine given colors, as well as speeding up
  42. * parsing of already parsed colors.
  43. */
  44. private static Map colorMap = null;
  45. /** Logger instance */
  46. protected static Log log = LogFactory.getLog(ColorUtil.class);
  47. static {
  48. initializeColorMap();
  49. }
  50. /**
  51. * Private constructor since this is an utility class.
  52. */
  53. private ColorUtil() {
  54. }
  55. /**
  56. * Creates a color from a given string.
  57. * <p>
  58. * This function supports a wide variety of inputs.
  59. * <ul>
  60. * <li>#RGB (hex 0..f)</li>
  61. * <li>#RGBA (hex 0..f)</li>
  62. * <li>#RRGGBB (hex 00..ff)</li>
  63. * <li>#RRGGBBAA (hex 00..ff)</li>
  64. * <li>rgb(r,g,b) (0..255 or 0%..100%)</li>
  65. * <li>java.awt.Color[r=r,g=g,b=b] (0..255)</li>
  66. * <li>system-color(colorname)</li>
  67. * <li>transparent</li>
  68. * <li>colorname</li>
  69. * <li>fop-rgb-icc</li>
  70. * <li>cmyk</li>
  71. * </ul>
  72. *
  73. * @param foUserAgent FOUserAgent object
  74. * @param value
  75. * the string to parse.
  76. * @return a Color representing the string if possible
  77. * @throws PropertyException
  78. * if the string is not parsable or does not follow any of the
  79. * given formats.
  80. */
  81. public static Color parseColorString(FOUserAgent foUserAgent, String value)
  82. throws PropertyException {
  83. if (value == null) {
  84. return null;
  85. }
  86. Color parsedColor = (Color) colorMap.get(value.toLowerCase());
  87. if (parsedColor == null) {
  88. if (value.startsWith("#")) {
  89. parsedColor = parseWithHash(value);
  90. } else if (value.startsWith("rgb(")) {
  91. parsedColor = parseAsRGB(value);
  92. } else if (value.startsWith("url(")) {
  93. throw new PropertyException(
  94. "Colors starting with url( are not yet supported!");
  95. } else if (value.startsWith("java.awt.Color")) {
  96. parsedColor = parseAsJavaAWTColor(value);
  97. } else if (value.startsWith("system-color(")) {
  98. parsedColor = parseAsSystemColor(value);
  99. } else if (value.startsWith("fop-rgb-icc")) {
  100. parsedColor = parseAsFopRgbIcc(foUserAgent, value);
  101. } else if (value.startsWith("cmyk")) {
  102. parsedColor = parseAsCMYK(value);
  103. }
  104. if (parsedColor == null) {
  105. throw new PropertyException("Unknown Color: " + value);
  106. }
  107. colorMap.put(value, parsedColor);
  108. }
  109. // TODO - Returned Color object can be one from the static colorMap cache.
  110. // That means it should be treated as read only for the rest of its lifetime.
  111. // Not sure that is the case though.
  112. return parsedColor;
  113. }
  114. /**
  115. * Tries to parse a color given with the system-color() function.
  116. *
  117. * @param value
  118. * the complete line
  119. * @return a color if possible
  120. * @throws PropertyException
  121. * if the format is wrong.
  122. */
  123. private static Color parseAsSystemColor(String value)
  124. throws PropertyException {
  125. int poss = value.indexOf("(");
  126. int pose = value.indexOf(")");
  127. if (poss != -1 && pose != -1) {
  128. value = value.substring(poss + 1, pose);
  129. } else {
  130. throw new PropertyException("Unknown color format: " + value
  131. + ". Must be system-color(x)");
  132. }
  133. return (Color) colorMap.get(value);
  134. }
  135. /**
  136. * Tries to parse the standard java.awt.Color toString output.
  137. *
  138. * @param value
  139. * the complete line
  140. * @return a color if possible
  141. * @throws PropertyException
  142. * if the format is wrong.
  143. * @inheritDoc java.awt.Color#toString()
  144. */
  145. private static Color parseAsJavaAWTColor(String value)
  146. throws PropertyException {
  147. float red = 0.0f, green = 0.0f, blue = 0.0f;
  148. int poss = value.indexOf("[");
  149. int pose = value.indexOf("]");
  150. try {
  151. if (poss != -1 && pose != -1) {
  152. value = value.substring(poss + 1, pose);
  153. StringTokenizer st = new StringTokenizer(value, ",");
  154. if (st.hasMoreTokens()) {
  155. String str = st.nextToken().trim();
  156. red = Float.parseFloat(str.substring(2)) / 255f;
  157. }
  158. if (st.hasMoreTokens()) {
  159. String str = st.nextToken().trim();
  160. green = Float.parseFloat(str.substring(2)) / 255f;
  161. }
  162. if (st.hasMoreTokens()) {
  163. String str = st.nextToken().trim();
  164. blue = Float.parseFloat(str.substring(2)) / 255f;
  165. } else {
  166. throw new NumberFormatException();
  167. }
  168. if ((red < 0.0 || red > 1.0) || (green < 0.0 || green > 1.0)
  169. || (blue < 0.0 || blue > 1.0)) {
  170. throw new PropertyException("Color values out of range");
  171. }
  172. } else {
  173. throw new NullPointerException();
  174. }
  175. } catch (Exception e) {
  176. throw new PropertyException("Unknown color format: " + value);
  177. }
  178. return new Color(red, green, blue);
  179. }
  180. /**
  181. * Parse a color given with the rgb() function.
  182. *
  183. * @param value
  184. * the complete line
  185. * @return a color if possible
  186. * @throws PropertyException
  187. * if the format is wrong.
  188. */
  189. private static Color parseAsRGB(String value) throws PropertyException {
  190. Color parsedColor;
  191. int poss = value.indexOf("(");
  192. int pose = value.indexOf(")");
  193. if (poss != -1 && pose != -1) {
  194. value = value.substring(poss + 1, pose);
  195. StringTokenizer st = new StringTokenizer(value, ",");
  196. try {
  197. float red = 0.0f, green = 0.0f, blue = 0.0f;
  198. if (st.hasMoreTokens()) {
  199. String str = st.nextToken().trim();
  200. if (str.endsWith("%")) {
  201. red = Float.parseFloat(str.substring(0,
  202. str.length() - 1)) / 100.0f;
  203. } else {
  204. red = Float.parseFloat(str) / 255f;
  205. }
  206. }
  207. if (st.hasMoreTokens()) {
  208. String str = st.nextToken().trim();
  209. if (str.endsWith("%")) {
  210. green = Float.parseFloat(str.substring(0,
  211. str.length() - 1)) / 100.0f;
  212. } else {
  213. green = Float.parseFloat(str) / 255f;
  214. }
  215. }
  216. if (st.hasMoreTokens()) {
  217. String str = st.nextToken().trim();
  218. if (str.endsWith("%")) {
  219. blue = Float.parseFloat(str.substring(0,
  220. str.length() - 1)) / 100.0f;
  221. } else {
  222. blue = Float.parseFloat(str) / 255f;
  223. }
  224. }
  225. if ((red < 0.0 || red > 1.0) || (green < 0.0 || green > 1.0)
  226. || (blue < 0.0 || blue > 1.0)) {
  227. throw new PropertyException("Color values out of range");
  228. }
  229. parsedColor = new Color(red, green, blue);
  230. } catch (Exception e) {
  231. throw new PropertyException(
  232. "Arguments to rgb() must be [0..255] or [0%..100%]");
  233. }
  234. } else {
  235. throw new PropertyException("Unknown color format: " + value
  236. + ". Must be rgb(r,g,b)");
  237. }
  238. return parsedColor;
  239. }
  240. /**
  241. * parse a color given in the #.... format.
  242. *
  243. * @param value
  244. * the complete line
  245. * @return a color if possible
  246. * @throws PropertyException
  247. * if the format is wrong.
  248. */
  249. private static Color parseWithHash(String value) throws PropertyException {
  250. Color parsedColor = null;
  251. try {
  252. int len = value.length();
  253. if ((len >= 4) && (len <= 5)) {
  254. // note: divide by 15 so F = FF = 1 and so on
  255. float red = Integer.parseInt(value.substring(1, 2), 16) / 15f;
  256. float green = Integer.parseInt(value.substring(2, 3), 16) / 15f;
  257. float blue = Integer.parseInt(value.substring(3, 4), 16) / 15f;
  258. float alpha = 1.0f;
  259. if (len == 5) {
  260. alpha = Integer.parseInt(value.substring(4), 16) / 15f;
  261. }
  262. parsedColor = new Color(red, green, blue, alpha);
  263. } else if ((len == 7) || (len == 9)) {
  264. int red = Integer.parseInt(value.substring(1, 3), 16);
  265. int green = Integer.parseInt(value.substring(3, 5), 16);
  266. int blue = Integer.parseInt(value.substring(5, 7), 16);
  267. int alpha = 255;
  268. if (len == 9) {
  269. alpha = Integer.parseInt(value.substring(7), 16);
  270. }
  271. parsedColor = new Color(red, green, blue, alpha);
  272. } else {
  273. throw new NumberFormatException();
  274. }
  275. } catch (NumberFormatException e) {
  276. throw new PropertyException("Unknown color format: " + value
  277. + ". Must be #RGB. #RGBA, #RRGGBB, or #RRGGBBAA");
  278. }
  279. return parsedColor;
  280. }
  281. /**
  282. * Parse a color specified using the fop-rgb-icc() function.
  283. *
  284. * @param value the function call
  285. * @return a color if possible
  286. * @throws PropertyException if the format is wrong.
  287. */
  288. private static Color parseAsFopRgbIcc(FOUserAgent foUserAgent, String value)
  289. throws PropertyException {
  290. Color parsedColor;
  291. int poss = value.indexOf("(");
  292. int pose = value.indexOf(")");
  293. if (poss != -1 && pose != -1) {
  294. value = value.substring(poss + 1, pose);
  295. StringTokenizer st = new StringTokenizer(value, ",");
  296. try {
  297. float red = 0.0f, green = 0.0f, blue = 0.0f;
  298. if (st.hasMoreTokens()) {
  299. String str = st.nextToken().trim();
  300. red = Float.parseFloat(str);
  301. }
  302. if (st.hasMoreTokens()) {
  303. String str = st.nextToken().trim();
  304. green = Float.parseFloat(str);
  305. }
  306. if (st.hasMoreTokens()) {
  307. String str = st.nextToken().trim();
  308. blue = Float.parseFloat(str);
  309. }
  310. /* Verify rgb replacement arguments */
  311. if ((red < 0.0 || red > 1.0)
  312. || (green < 0.0 || green > 1.0)
  313. || (blue < 0.0 || blue > 1.0)) {
  314. throw new PropertyException("Color values out of range");
  315. }
  316. /* Get and verify ICC profile name */
  317. String iccProfileName = null;
  318. if (st.hasMoreTokens()) {
  319. iccProfileName = st.nextToken().trim();
  320. }
  321. if (iccProfileName == null || iccProfileName.length() == 0) {
  322. throw new PropertyException("ICC profile name missing");
  323. }
  324. /* Get and verify ICC profile source */
  325. String iccProfileSrc = null;
  326. if (st.hasMoreTokens()) {
  327. iccProfileSrc = st.nextToken().trim();
  328. // Strip quotes
  329. iccProfileSrc = iccProfileSrc.substring(1, iccProfileSrc.length() - 1);
  330. }
  331. if (iccProfileSrc == null || iccProfileSrc.length() == 0) {
  332. throw new PropertyException("ICC profile source missing");
  333. }
  334. /* ICC profile arguments */
  335. List iccArgList = new LinkedList();
  336. while (st.hasMoreTokens()) {
  337. String str = st.nextToken().trim();
  338. iccArgList.add(new Float(str));
  339. }
  340. /* Copy ICC profile arguments from list to array */
  341. float[] iccComponents = new float[iccArgList.size()];
  342. for (int ix = 0; ix < iccArgList.size(); ix++) {
  343. iccComponents[ix] = ((Float)iccArgList.get(ix)).floatValue();
  344. }
  345. /* Ask FOP factory to get ColorSpace for the specified ICC profile source */
  346. ColorSpace colorSpace = (foUserAgent != null
  347. ? foUserAgent.getFactory().getColorSpace(
  348. foUserAgent.getBaseURL(), iccProfileSrc) : null);
  349. if (colorSpace != null) {
  350. // ColorSpace available - create ColorExt (keeps track of replacement rgb
  351. // values for possible later colorTOsRGBString call
  352. parsedColor = ColorExt.createFromFoRgbIcc(red, green, blue,
  353. iccProfileName, iccProfileSrc, colorSpace, iccComponents);
  354. } else {
  355. // ICC profile could not be loaded - use rgb replacement values */
  356. log.warn("Color profile '" + iccProfileSrc
  357. + "' not found. Using rgb replacement values.");
  358. parsedColor = new Color(red, green, blue);
  359. }
  360. } catch (Exception e) {
  361. throw new PropertyException(
  362. "Arguments to rgb-icc() must be [0..255] or [0%..100%]");
  363. }
  364. } else {
  365. throw new PropertyException("Unknown color format: " + value
  366. + ". Must be fop-rgb-icc(r,g,b,NCNAME,\"src\",....)");
  367. }
  368. return parsedColor;
  369. }
  370. /**
  371. * Parse a color given with the cmyk() function.
  372. *
  373. * @param value
  374. * the complete line
  375. * @return a color if possible
  376. * @throws PropertyException
  377. * if the format is wrong.
  378. */
  379. private static Color parseAsCMYK(String value) throws PropertyException {
  380. Color parsedColor;
  381. int poss = value.indexOf("(");
  382. int pose = value.indexOf(")");
  383. if (poss != -1 && pose != -1) {
  384. value = value.substring(poss + 1, pose);
  385. StringTokenizer st = new StringTokenizer(value, ",");
  386. try {
  387. float cyan = 0.0f, magenta = 0.0f, yellow = 0.0f, black = 0.0f;
  388. if (st.hasMoreTokens()) {
  389. String str = st.nextToken().trim();
  390. if (str.endsWith("%")) {
  391. cyan = Float.parseFloat(str.substring(0,
  392. str.length() - 1)) / 100.0f;
  393. } else {
  394. cyan = Float.parseFloat(str);
  395. }
  396. }
  397. if (st.hasMoreTokens()) {
  398. String str = st.nextToken().trim();
  399. if (str.endsWith("%")) {
  400. magenta = Float.parseFloat(str.substring(0,
  401. str.length() - 1)) / 100.0f;
  402. } else {
  403. magenta = Float.parseFloat(str);
  404. }
  405. }
  406. if (st.hasMoreTokens()) {
  407. String str = st.nextToken().trim();
  408. if (str.endsWith("%")) {
  409. yellow = Float.parseFloat(str.substring(0,
  410. str.length() - 1)) / 100.0f;
  411. } else {
  412. yellow = Float.parseFloat(str);
  413. }
  414. }
  415. if (st.hasMoreTokens()) {
  416. String str = st.nextToken().trim();
  417. if (str.endsWith("%")) {
  418. black = Float.parseFloat(str.substring(0,
  419. str.length() - 1)) / 100.0f;
  420. } else {
  421. black = Float.parseFloat(str);
  422. }
  423. }
  424. if ((cyan < 0.0 || cyan > 1.0)
  425. || (magenta < 0.0 || magenta > 1.0)
  426. || (yellow < 0.0 || yellow > 1.0)
  427. || (black < 0.0 || black > 1.0)) {
  428. throw new PropertyException("Color values out of range");
  429. }
  430. float[] cmyk = new float[] {cyan, magenta, yellow, black};
  431. CMYKColorSpace cmykCs = CMYKColorSpace.getInstance();
  432. float[] rgb = cmykCs.toRGB(cmyk);
  433. parsedColor = ColorExt.createFromFoRgbIcc(rgb[0], rgb[1], rgb[2],
  434. null, "#CMYK", cmykCs, cmyk);
  435. } catch (Exception e) {
  436. throw new PropertyException(
  437. "Arguments to cmyk() must be in the range [0%-100%] or [0.0-1.0]");
  438. }
  439. } else {
  440. throw new PropertyException("Unknown color format: " + value
  441. + ". Must be cmyk(c,m,y,k)");
  442. }
  443. return parsedColor;
  444. }
  445. /**
  446. * Creates a re-parsable string representation of the given color.
  447. * <p>
  448. * First, the color will be converted into the sRGB colorspace. It will then
  449. * be printed as #rrggbb, or as #rrrggbbaa if an alpha value is present.
  450. *
  451. * @param color
  452. * the color to represent.
  453. * @return a re-parsable string representadion.
  454. */
  455. public static String colorToString(Color color) {
  456. ColorSpace cs = color.getColorSpace();
  457. if (cs != null && cs.getType() == ColorSpace.TYPE_CMYK) {
  458. StringBuffer sbuf = new StringBuffer(24);
  459. float[] cmyk = color.getColorComponents(null);
  460. sbuf.append("cmyk(" + cmyk[0] + "," + cmyk[1] + "," + cmyk[2] + "," + cmyk[3] + ")");
  461. return sbuf.toString();
  462. } else if (color instanceof ColorExt) {
  463. return ((ColorExt)color).toFunctionCall();
  464. } else {
  465. StringBuffer sbuf = new StringBuffer();
  466. sbuf.append('#');
  467. String s = Integer.toHexString(color.getRed());
  468. if (s.length() == 1) {
  469. sbuf.append('0');
  470. }
  471. sbuf.append(s);
  472. s = Integer.toHexString(color.getGreen());
  473. if (s.length() == 1) {
  474. sbuf.append('0');
  475. }
  476. sbuf.append(s);
  477. s = Integer.toHexString(color.getBlue());
  478. if (s.length() == 1) {
  479. sbuf.append('0');
  480. }
  481. sbuf.append(s);
  482. if (color.getAlpha() != 255) {
  483. s = Integer.toHexString(color.getAlpha());
  484. if (s.length() == 1) {
  485. sbuf.append('0');
  486. }
  487. sbuf.append(s);
  488. }
  489. return sbuf.toString();
  490. }
  491. }
  492. /**
  493. * Initializes the colorMap with some predefined values.
  494. */
  495. private static void initializeColorMap() {
  496. colorMap = Collections.synchronizedMap(new java.util.HashMap());
  497. colorMap.put("aliceblue", new Color(240, 248, 255));
  498. colorMap.put("antiquewhite", new Color(250, 235, 215));
  499. colorMap.put("aqua", new Color(0, 255, 255));
  500. colorMap.put("aquamarine", new Color(127, 255, 212));
  501. colorMap.put("azure", new Color(240, 255, 255));
  502. colorMap.put("beige", new Color(245, 245, 220));
  503. colorMap.put("bisque", new Color(255, 228, 196));
  504. colorMap.put("black", new Color(0, 0, 0));
  505. colorMap.put("blanchedalmond", new Color(255, 235, 205));
  506. colorMap.put("blue", new Color(0, 0, 255));
  507. colorMap.put("blueviolet", new Color(138, 43, 226));
  508. colorMap.put("brown", new Color(165, 42, 42));
  509. colorMap.put("burlywood", new Color(222, 184, 135));
  510. colorMap.put("cadetblue", new Color(95, 158, 160));
  511. colorMap.put("chartreuse", new Color(127, 255, 0));
  512. colorMap.put("chocolate", new Color(210, 105, 30));
  513. colorMap.put("coral", new Color(255, 127, 80));
  514. colorMap.put("cornflowerblue", new Color(100, 149, 237));
  515. colorMap.put("cornsilk", new Color(255, 248, 220));
  516. colorMap.put("crimson", new Color(220, 20, 60));
  517. colorMap.put("cyan", new Color(0, 255, 255));
  518. colorMap.put("darkblue", new Color(0, 0, 139));
  519. colorMap.put("darkcyan", new Color(0, 139, 139));
  520. colorMap.put("darkgoldenrod", new Color(184, 134, 11));
  521. colorMap.put("darkgray", new Color(169, 169, 169));
  522. colorMap.put("darkgreen", new Color(0, 100, 0));
  523. colorMap.put("darkgrey", new Color(169, 169, 169));
  524. colorMap.put("darkkhaki", new Color(189, 183, 107));
  525. colorMap.put("darkmagenta", new Color(139, 0, 139));
  526. colorMap.put("darkolivegreen", new Color(85, 107, 47));
  527. colorMap.put("darkorange", new Color(255, 140, 0));
  528. colorMap.put("darkorchid", new Color(153, 50, 204));
  529. colorMap.put("darkred", new Color(139, 0, 0));
  530. colorMap.put("darksalmon", new Color(233, 150, 122));
  531. colorMap.put("darkseagreen", new Color(143, 188, 143));
  532. colorMap.put("darkslateblue", new Color(72, 61, 139));
  533. colorMap.put("darkslategray", new Color(47, 79, 79));
  534. colorMap.put("darkslategrey", new Color(47, 79, 79));
  535. colorMap.put("darkturquoise", new Color(0, 206, 209));
  536. colorMap.put("darkviolet", new Color(148, 0, 211));
  537. colorMap.put("deeppink", new Color(255, 20, 147));
  538. colorMap.put("deepskyblue", new Color(0, 191, 255));
  539. colorMap.put("dimgray", new Color(105, 105, 105));
  540. colorMap.put("dimgrey", new Color(105, 105, 105));
  541. colorMap.put("dodgerblue", new Color(30, 144, 255));
  542. colorMap.put("firebrick", new Color(178, 34, 34));
  543. colorMap.put("floralwhite", new Color(255, 250, 240));
  544. colorMap.put("forestgreen", new Color(34, 139, 34));
  545. colorMap.put("fuchsia", new Color(255, 0, 255));
  546. colorMap.put("gainsboro", new Color(220, 220, 220));
  547. colorMap.put("ghostwhite", new Color(248, 248, 255));
  548. colorMap.put("gold", new Color(255, 215, 0));
  549. colorMap.put("goldenrod", new Color(218, 165, 32));
  550. colorMap.put("gray", new Color(128, 128, 128));
  551. colorMap.put("green", new Color(0, 128, 0));
  552. colorMap.put("greenyellow", new Color(173, 255, 47));
  553. colorMap.put("grey", new Color(128, 128, 128));
  554. colorMap.put("honeydew", new Color(240, 255, 240));
  555. colorMap.put("hotpink", new Color(255, 105, 180));
  556. colorMap.put("indianred", new Color(205, 92, 92));
  557. colorMap.put("indigo", new Color(75, 0, 130));
  558. colorMap.put("ivory", new Color(255, 255, 240));
  559. colorMap.put("khaki", new Color(240, 230, 140));
  560. colorMap.put("lavender", new Color(230, 230, 250));
  561. colorMap.put("lavenderblush", new Color(255, 240, 245));
  562. colorMap.put("lawngreen", new Color(124, 252, 0));
  563. colorMap.put("lemonchiffon", new Color(255, 250, 205));
  564. colorMap.put("lightblue", new Color(173, 216, 230));
  565. colorMap.put("lightcoral", new Color(240, 128, 128));
  566. colorMap.put("lightcyan", new Color(224, 255, 255));
  567. colorMap.put("lightgoldenrodyellow", new Color(250, 250, 210));
  568. colorMap.put("lightgray", new Color(211, 211, 211));
  569. colorMap.put("lightgreen", new Color(144, 238, 144));
  570. colorMap.put("lightgrey", new Color(211, 211, 211));
  571. colorMap.put("lightpink", new Color(255, 182, 193));
  572. colorMap.put("lightsalmon", new Color(255, 160, 122));
  573. colorMap.put("lightseagreen", new Color(32, 178, 170));
  574. colorMap.put("lightskyblue", new Color(135, 206, 250));
  575. colorMap.put("lightslategray", new Color(119, 136, 153));
  576. colorMap.put("lightslategrey", new Color(119, 136, 153));
  577. colorMap.put("lightsteelblue", new Color(176, 196, 222));
  578. colorMap.put("lightyellow", new Color(255, 255, 224));
  579. colorMap.put("lime", new Color(0, 255, 0));
  580. colorMap.put("limegreen", new Color(50, 205, 50));
  581. colorMap.put("linen", new Color(250, 240, 230));
  582. colorMap.put("magenta", new Color(255, 0, 255));
  583. colorMap.put("maroon", new Color(128, 0, 0));
  584. colorMap.put("mediumaquamarine", new Color(102, 205, 170));
  585. colorMap.put("mediumblue", new Color(0, 0, 205));
  586. colorMap.put("mediumorchid", new Color(186, 85, 211));
  587. colorMap.put("mediumpurple", new Color(147, 112, 219));
  588. colorMap.put("mediumseagreen", new Color(60, 179, 113));
  589. colorMap.put("mediumslateblue", new Color(123, 104, 238));
  590. colorMap.put("mediumspringgreen", new Color(0, 250, 154));
  591. colorMap.put("mediumturquoise", new Color(72, 209, 204));
  592. colorMap.put("mediumvioletred", new Color(199, 21, 133));
  593. colorMap.put("midnightblue", new Color(25, 25, 112));
  594. colorMap.put("mintcream", new Color(245, 255, 250));
  595. colorMap.put("mistyrose", new Color(255, 228, 225));
  596. colorMap.put("moccasin", new Color(255, 228, 181));
  597. colorMap.put("navajowhite", new Color(255, 222, 173));
  598. colorMap.put("navy", new Color(0, 0, 128));
  599. colorMap.put("oldlace", new Color(253, 245, 230));
  600. colorMap.put("olive", new Color(128, 128, 0));
  601. colorMap.put("olivedrab", new Color(107, 142, 35));
  602. colorMap.put("orange", new Color(255, 165, 0));
  603. colorMap.put("orangered", new Color(255, 69, 0));
  604. colorMap.put("orchid", new Color(218, 112, 214));
  605. colorMap.put("palegoldenrod", new Color(238, 232, 170));
  606. colorMap.put("palegreen", new Color(152, 251, 152));
  607. colorMap.put("paleturquoise", new Color(175, 238, 238));
  608. colorMap.put("palevioletred", new Color(219, 112, 147));
  609. colorMap.put("papayawhip", new Color(255, 239, 213));
  610. colorMap.put("peachpuff", new Color(255, 218, 185));
  611. colorMap.put("peru", new Color(205, 133, 63));
  612. colorMap.put("pink", new Color(255, 192, 203));
  613. colorMap.put("plum ", new Color(221, 160, 221));
  614. colorMap.put("plum", new Color(221, 160, 221));
  615. colorMap.put("powderblue", new Color(176, 224, 230));
  616. colorMap.put("purple", new Color(128, 0, 128));
  617. colorMap.put("red", new Color(255, 0, 0));
  618. colorMap.put("rosybrown", new Color(188, 143, 143));
  619. colorMap.put("royalblue", new Color(65, 105, 225));
  620. colorMap.put("saddlebrown", new Color(139, 69, 19));
  621. colorMap.put("salmon", new Color(250, 128, 114));
  622. colorMap.put("sandybrown", new Color(244, 164, 96));
  623. colorMap.put("seagreen", new Color(46, 139, 87));
  624. colorMap.put("seashell", new Color(255, 245, 238));
  625. colorMap.put("sienna", new Color(160, 82, 45));
  626. colorMap.put("silver", new Color(192, 192, 192));
  627. colorMap.put("skyblue", new Color(135, 206, 235));
  628. colorMap.put("slateblue", new Color(106, 90, 205));
  629. colorMap.put("slategray", new Color(112, 128, 144));
  630. colorMap.put("slategrey", new Color(112, 128, 144));
  631. colorMap.put("snow", new Color(255, 250, 250));
  632. colorMap.put("springgreen", new Color(0, 255, 127));
  633. colorMap.put("steelblue", new Color(70, 130, 180));
  634. colorMap.put("tan", new Color(210, 180, 140));
  635. colorMap.put("teal", new Color(0, 128, 128));
  636. colorMap.put("thistle", new Color(216, 191, 216));
  637. colorMap.put("tomato", new Color(255, 99, 71));
  638. colorMap.put("turquoise", new Color(64, 224, 208));
  639. colorMap.put("violet", new Color(238, 130, 238));
  640. colorMap.put("wheat", new Color(245, 222, 179));
  641. colorMap.put("white", new Color(255, 255, 255));
  642. colorMap.put("whitesmoke", new Color(245, 245, 245));
  643. colorMap.put("yellow", new Color(255, 255, 0));
  644. colorMap.put("yellowgreen", new Color(154, 205, 50));
  645. colorMap.put("transparent", new Color(0, 0, 0, 0));
  646. }
  647. }