001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.css.engine.value.svg;
020:
021: import org.apache.batik.css.engine.value.AbstractValue;
022: import org.w3c.dom.DOMException;
023: import org.w3c.dom.css.CSSValue;
024:
025: /**
026: * This class represents an ICC color value.
027: *
028: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
029: * @version $Id: ICCColor.java 476924 2006-11-19 21:13:26Z dvholten $
030: */
031: public class ICCColor extends AbstractValue {
032:
033: /**
034: * The color profile.
035: */
036: protected String colorProfile;
037:
038: /**
039: * The color count.
040: */
041: protected int count;
042:
043: /**
044: * The colors.
045: */
046: protected float[] colors = new float[5];
047:
048: /**
049: * Creates a new ICCColor.
050: */
051: public ICCColor(String name) {
052: colorProfile = name;
053: }
054:
055: /**
056: * Implements {@link
057: * org.apache.batik.css.engine.value.Value#getCssValueType()}.
058: */
059: public short getCssValueType() {
060: return CSSValue.CSS_CUSTOM;
061: }
062:
063: /**
064: * Returns the color name.
065: */
066: public String getColorProfile() throws DOMException {
067: return colorProfile;
068: }
069:
070: /**
071: * Returns the number of colors.
072: */
073: public int getNumberOfColors() throws DOMException {
074: return count;
075: }
076:
077: /**
078: * Returns the color at the given index.
079: */
080: public float getColor(int i) throws DOMException {
081: return colors[i];
082: }
083:
084: /**
085: * A string representation of the current value.
086: */
087: public String getCssText() {
088: StringBuffer sb = new StringBuffer(count * 8);
089: sb.append("icc-color(");
090: sb.append(colorProfile);
091: for (int i = 0; i < count; i++) {
092: sb.append(", ");
093: sb.append(colors[i]);
094: }
095: sb.append(')');
096: return sb.toString();
097: }
098:
099: /**
100: * Appends a color to the list.
101: */
102: public void append(float c) {
103: if (count == colors.length) {
104: float[] t = new float[count * 2];
105: System.arraycopy(colors, 0, t, 0, count);
106: colors = t;
107: }
108: colors[count++] = c;
109: }
110: }
|