Element paintedElement,
Element paintElement) {
//
// Get unit processor to compute gradient control points
//
CSSStyleDeclaration cssDecl
= ctx.getViewCSS().getComputedStyle(paintElement, null);
UnitProcessor.Context uctx
= new DefaultUnitProcessorContext(ctx, cssDecl);
// parse the gradientUnits attribute, (default is 'objectBoundingBox')
String units = paintElement.getAttributeNS(null, ATTR_GRADIENT_UNITS);
if(units.length() == 0){
units = VALUE_OBJECT_BOUNDING_BOX;
}
// parse the x1 attribute, (default is 0%)
String x1 = paintElement.getAttributeNS(null, ATTR_X1);
if (x1.length() == 0){
x1 = "0%";
}
// parse the y1 attribute, (default is 0%)
String y1 = paintElement.getAttributeNS(null, ATTR_Y1);
if (y1.length() == 0){
y1 = "0%";
}
// parse the x2 attribute, (default is 100%)
String x2 = paintElement.getAttributeNS(null, ATTR_X2);
if (x2.length() == 0){
x2 = "100%";
}
// parse the y2 attribute, (default is 0%)
String y2 = paintElement.getAttributeNS(null, ATTR_Y2);
if (y2.length() == 0){
y2 = "0%";
}
int unitsType;
try {
unitsType = SVGUtilities.parseCoordinateSystem(units);
} catch (IllegalArgumentException ex) {
throw new IllegalAttributeValueException(
Messages.formatMessage("linearGradient.units.invalid",
new Object[] {units,
ATTR_GRADIENT_UNITS}));
}
SVGElement svgPaintedElement = (SVGElement) paintedElement;
Point2D p1
= SVGUtilities.convertGradientPoint(svgPaintedElement,
ATTR_X1, x1,
ATTR_Y1, y1,
unitsType, uctx);
Point2D p2
= SVGUtilities.convertGradientPoint(svgPaintedElement,
ATTR_X2, x2,
ATTR_Y2, y2,
unitsType, uctx);
// parse the 'spreadMethod' attribute, (default is PAD)
String spreadMethod =
paintElement.getAttributeNS(null, ATTR_SPREAD_METHOD);
if (spreadMethod.length() == 0) {
spreadMethod = VALUE_PAD;
}
LinearGradientPaint.CycleMethodEnum cycleMethod =
convertSpreadMethod(spreadMethod);
// Extract gradient transform
AffineTransform at =
SVGUtilities.convertAffineTransform(paintElement,
ATTR_GRADIENT_TRANSFORM,
ctx.getParserFactory());
at = SVGUtilities.convertAffineTransform(at, paintedNode, unitsType);
// Extract stop colors and intervals
Vector stopVector = extractGradientStops(paintElement, ctx);
// if no stop, fill is 'none'
if (stopVector.size() == 0) {
return null;
}
// if one stop, the fill is just one color
if (stopVector.size() == 1) {
return ((GradientStop) stopVector.get(0)).stopColor;
}
// Convert the stop offsets to intervals
int nStops = stopVector.size();
float curOffset = 0;
if (nStops > 0) {
GradientStop stop = (GradientStop) stopVector.elementAt(0);
curOffset = stop.offset;
}
for (int i=1; i < nStops; i++) {
GradientStop stop = (GradientStop)stopVector.elementAt(i);
if(stop.offset < curOffset){
stop.offset = curOffset;
}
curOffset = stop.offset;
}
// Extract the color interpolation property
CSSPrimitiveValue colorInterpolation =
(CSSPrimitiveValue)cssDecl.getPropertyCSSValue
(CSS_COLOR_INTERPOLATION_PROPERTY);
LinearGradientPaint.ColorSpaceEnum colorSpace
= LinearGradientPaint.SRGB;