GradientElementpublic abstract class GradientElement extends PaintElement GradientElement abstract class is a helper base
class for LinearGradient and RadialGradient .
|
Fields Summary |
---|
com.sun.perseus.j2d.PaintDef | computedPaintComputed PaintDef, in userSpaceOnUse. | float[] | lastColorMapFractionsThe last computed GradientColorMap fractions | int[] | lastColorMapRGBAThe last computed GradientColorMap colors | com.sun.perseus.j2d.Transform | transformAddintional paint transform, like the gradientTransform on gradients. |
Constructors Summary |
---|
public GradientElement(DocumentNode ownerDocument)Constructor.
super(ownerDocument);
isObjectBBox = true;
|
Methods Summary |
---|
final void | buildGradientColorMap()Builds a GradientColorMap from the children <stop>
elements.
// First, compute the number of stop children.
ElementNode c = (ElementNode) getFirstElementChild();
int n = 0;
Stop[] stop = new Stop[5];
while (c != null) {
if (c.getLocalName() == SVGConstants.SVG_STOP_TAG
&&
c.getNamespaceURI() == SVGConstants.SVG_NAMESPACE_URI) {
stop[n] = (Stop) c;
n++;
if (n > stop.length - 1) {
Stop[] tmpStop = new Stop[stop.length + 5];
System.arraycopy(stop, 0, tmpStop, 0, stop.length);
stop = tmpStop;
}
}
c = (ElementNode) c.getNextElementSibling();
}
if (n == 0) {
// To obtain the same result as a 'none' fill, we just use two
// stops with fully transparent fill.
lastColorMapFractions = new float[] {0, 1};
lastColorMapRGBA = new int[] {0x00000000, 0x00000000};
return;
} if (n == 1) {
// We duplicate the single gradient to provide the effect of
// a solid color.
RGB color = stop[0].getStopColor();
int a = (int) (stop[0].getStopOpacity() * 255);
lastColorMapFractions = new float[] {0, 1};
lastColorMapRGBA = new int[] {a << 24
| color.getRed() << 16
| color.getGreen() << 8
| color.getBlue(),
a << 24
| color.getRed() << 16
| color.getGreen() << 8
| color.getBlue()
};
return;
}
float[] fractions = new float[n];
int[] rgba = new int[n];
RGB col = null;
for (int i = 0; i < n; i++) {
fractions[i] = stop[i].getOffset();
if (i > 0 && fractions[i] <= fractions[i - 1]) {
fractions[i] = fractions[i - 1];
}
col = stop[i].getStopColor();
rgba[i] = ((int) (stop[i].getStopOpacity() * 255) << 24)
| col.getRed() << 16
| col.getGreen() << 8
| col.getBlue();
}
// Check that the first stop is zero. If not, we need to dupplicate the
// first stop and give it fraction zero.
if (fractions[0] != 0) {
float[] tmpFractions = new float[fractions.length + 1];
int[] tmpRgba = new int[rgba.length + 1];
tmpFractions[0] = 0;
tmpRgba[0] = rgba[0];
System.arraycopy(fractions, 0, tmpFractions, 1, fractions.length);
System.arraycopy(rgba, 0, tmpRgba, 1, rgba.length);
fractions = tmpFractions;
rgba = tmpRgba;
}
// Check that the last stop is 1. If not we duplicate the last stop.
if (fractions[fractions.length - 1] != 1) {
float[] tmpFractions = new float[fractions.length + 1];
int[] tmpRgba = new int[rgba.length + 1];
tmpFractions[tmpFractions.length - 1] = 1;
tmpRgba[tmpRgba.length - 1] = rgba[rgba.length - 1];
System.arraycopy(fractions, 0, tmpFractions, 0, fractions.length);
System.arraycopy(rgba, 0, tmpRgba, 0, rgba.length);
fractions = tmpFractions;
rgba = tmpRgba;
}
lastColorMapFractions = fractions;
lastColorMapRGBA = rgba;
| TraitAnim | createTraitAnimImpl(java.lang.String traitName)GradientElement handles the gradientTransform as a TransformTraitAnim and
the gradientUnits as a StringTraitAnim.
if (SVGConstants.SVG_GRADIENT_TRANSFORM_ATTRIBUTE == traitName) {
return new TransformTraitAnim(this, traitName);
} else if (SVGConstants.SVG_GRADIENT_UNITS_ATTRIBUTE == traitName) {
return new StringTraitAnim(this, NULL_NS, traitName);
} else {
return super.createTraitAnimImpl(traitName);
}
| org.w3c.dom.svg.SVGMatrix | getMatrixTraitImpl(java.lang.String name)
if (SVGConstants.SVG_GRADIENT_TRANSFORM_ATTRIBUTE.equals(name)) {
return toSVGMatrixTrait(transform);
} else {
return super.getMatrixTraitImpl(name);
}
| public java.lang.String | getTraitImpl(java.lang.String name)
if (SVGConstants.SVG_GRADIENT_TRANSFORM_ATTRIBUTE == name) {
return toStringTrait(transform);
} if (SVGConstants.SVG_GRADIENT_UNITS_ATTRIBUTE == name) {
if (isObjectBBox) {
return SVGConstants.SVG_OBJECT_BOUND_BOX_VALUE;
} else {
return SVGConstants.SVG_USER_SPACE_ON_USE_VALUE;
}
} else {
return super.getTraitImpl(name);
}
| public com.sun.perseus.j2d.Transform | getTransform()
return transform;
| protected void | onPaintChange()Should be called when the paint should recompute itself and
notify its references.
computedPaint = null;
lastColorMapFractions = null;
lastColorMapRGBA = null;
if (loaded) {
notifyPaintChange();
}
| void | setFloatArrayTrait(java.lang.String name, float[][] value)Set the trait value as float array.
// We use .equals for the transform attribute as the string may not
// have been interned. We use == for the motion pseudo attribute because
// it is only used internally and from the SVGConstants strings.
if (SVGConstants.SVG_GRADIENT_TRANSFORM_ATTRIBUTE.equals(name)) {
if (transform == null) {
modifyingNode();
transform = new Transform(value[0][0],
value[1][0],
value[2][0],
value[3][0],
value[4][0],
value[5][0]);
} else {
if (!transform.equals(value)) {
modifyingNode();
transform.setTransform(value[0][0],
value[1][0],
value[2][0],
value[3][0],
value[4][0],
value[5][0]);
} else {
return;
}
}
modifiedNode();
} else {
super.setFloatArrayTrait(name, value);
}
| public void | setIsObjectBBox(boolean newIsObjectBBox)Sets the isObjectBBox state.
if (newIsObjectBBox == isObjectBBox) {
return;
}
isObjectBBox = newIsObjectBBox;
onPaintChange();
| void | setMatrixTraitImpl(java.lang.String name, com.sun.perseus.j2d.Transform matrix)
if (SVGConstants.SVG_GRADIENT_TRANSFORM_ATTRIBUTE.equals(name)) {
setTransform(matrix);
} else {
super.setMatrixTraitImpl(name, matrix);
}
| public void | setTraitImpl(java.lang.String name, java.lang.String value)
if (SVGConstants.SVG_GRADIENT_TRANSFORM_ATTRIBUTE == name) {
setTransform(parseTransformTrait(name, value));
} else if (SVGConstants.SVG_GRADIENT_UNITS_ATTRIBUTE
.equals(name)) {
if (SVGConstants.SVG_OBJECT_BOUND_BOX_VALUE.equals(value)) {
setIsObjectBBox(true);
} else if (SVGConstants.SVG_USER_SPACE_ON_USE_VALUE.equals(value)) {
setIsObjectBBox(false);
} else {
throw illegalTraitValue(name, value);
}
} else {
super.setTraitImpl(name, value);
}
| public void | setTransform(com.sun.perseus.j2d.Transform newTransform)
if (equal(newTransform, transform)) {
return;
}
modifyingNode();
this.transform = newTransform;
onPaintChange();
modifiedNode();
| boolean | supportsTrait(java.lang.String traitName)Supported traits: transform.
if (SVGConstants.SVG_GRADIENT_TRANSFORM_ATTRIBUTE == traitName
||
SVGConstants.SVG_GRADIENT_UNITS_ATTRIBUTE == traitName) {
return true;
} else {
return super.supportsTrait(traitName);
}
| java.lang.String | toStringTrait(java.lang.String name, float[][] value)
if (SVGConstants.SVG_GRADIENT_TRANSFORM_ATTRIBUTE == name) {
Transform transform = new Transform(value[0][0],
value[1][0],
value[2][0],
value[3][0],
value[4][0],
value[5][0]);
return toStringTrait(transform);
} else {
return super.toStringTrait(name, value);
}
| public float[][] | validateFloatArrayTrait(java.lang.String traitName, java.lang.String value, java.lang.String reqNamespaceURI, java.lang.String reqLocalName, java.lang.String reqTraitNamespace, java.lang.String reqTraitName)Validates the input trait value.
if (SVGConstants.SVG_GRADIENT_TRANSFORM_ATTRIBUTE == traitName) {
Transform txf = parseTransformTrait(traitName, value);
return new float[][] {{txf.getComponent(0)},
{txf.getComponent(1)},
{txf.getComponent(2)},
{txf.getComponent(3)},
{txf.getComponent(4)},
{txf.getComponent(5)}};
} else {
return super.validateFloatArrayTrait(traitName,
value,
reqNamespaceURI,
reqLocalName,
reqTraitNamespace,
reqTraitName);
}
| java.lang.String | validateTraitNS(java.lang.String namespaceURI, java.lang.String traitName, java.lang.String value, java.lang.String reqNamespaceURI, java.lang.String reqLocalName, java.lang.String reqTraitNamespace, java.lang.String reqTraitName)Validates the input trait value.
if (namespaceURI != null) {
return super.validateTraitNS(namespaceURI,
traitName,
value,
reqNamespaceURI,
reqLocalName,
reqTraitNamespace,
reqTraitName);
}
if (SVGConstants.SVG_GRADIENT_UNITS_ATTRIBUTE
.equals(traitName)) {
if (!SVGConstants.SVG_USER_SPACE_ON_USE_VALUE.equals(value)
&&
!SVGConstants.SVG_OBJECT_BOUND_BOX_VALUE.equals(value)) {
throw illegalTraitValue(traitName, value);
}
return value;
}
return super.validateTraitNS(namespaceURI,
traitName,
value,
reqNamespaceURI,
reqLocalName,
reqTraitNamespace,
reqTraitName);
|
|