}
ref = (SVGRadialGradientElement) locateDef(
ref.getHref().getBaseVal(), ref);
}
if (acx == null) {
SVGLength length = new SVGLengthImpl();
length.newValueSpecifiedUnits(
SVGLength.SVG_LENGTHTYPE_PERCENTAGE, 0.5f);
acx = new SVGAnimatedLengthImpl(length);
}
if (acy == null) {
SVGLength length = new SVGLengthImpl();
length.newValueSpecifiedUnits(
SVGLength.SVG_LENGTHTYPE_PERCENTAGE, 0.5f);
acy = new SVGAnimatedLengthImpl(length);
}
if (ar == null) {
SVGLength length = new SVGLengthImpl();
length.newValueSpecifiedUnits(
SVGLength.SVG_LENGTHTYPE_PERCENTAGE, 1);
ar = new SVGAnimatedLengthImpl(length);
}
if (afx == null) {
SVGLength length = new SVGLengthImpl();
length.newValueSpecifiedUnits(
SVGLength.SVG_LENGTHTYPE_PERCENTAGE, 0.5f);
afx = new SVGAnimatedLengthImpl(length);
}
if (afy == null) {
SVGLength length = new SVGLengthImpl();
length.newValueSpecifiedUnits(
SVGLength.SVG_LENGTHTYPE_PERCENTAGE, 0.5f);
afy = new SVGAnimatedLengthImpl(length);
}
ColorSpace aColorSpace = new ColorSpace(ColorSpace.DEVICE_RGB);
org.w3c.dom.NodeList nl = stops;
SVGStopElementImpl stop;
if (nl.getLength() == 0) {
// the color should be "none"
if (fill)
di.fill = false;
else
di.stroke = false;
return;
} else if (nl.getLength() == 1) {
stop = (SVGStopElementImpl) nl.item(0);
CSSValue cv = stop.getPresentationAttribute("stop-color");
if (cv == null) {
// maybe using color
cv = stop.getPresentationAttribute("color");
}
if (cv == null) {
// problems
MessageHandler.errorln("no stop-color or color in stop element");
return;
}
PDFColor color = new PDFColor(0, 0, 0);
if (cv != null &&
cv.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
if (((CSSPrimitiveValue) cv).getPrimitiveType() ==
CSSPrimitiveValue.CSS_RGBCOLOR) {
RGBColor col =
((CSSPrimitiveValue) cv).getRGBColorValue();
CSSPrimitiveValue val;
val = col.getRed();
float red = val.getFloatValue(
CSSPrimitiveValue.CSS_NUMBER);
val = col.getGreen();
float green = val.getFloatValue(
CSSPrimitiveValue.CSS_NUMBER);
val = col.getBlue();
float blue = val.getFloatValue(
CSSPrimitiveValue.CSS_NUMBER);
color = new PDFColor(red, green, blue);
}
}
currentStream.write(color.getColorSpaceOut(fill));
if (fill)
di.fill = true;
else
di.stroke = true;
return;
}
Hashtable table = null;
Vector someColors = new Vector();
Vector theCoords = null;
Vector theBounds = new Vector();
// the coords should be relative to the current object
// check value types, eg. %
if (gradUnits == SVGUnitTypes.SVG_UNIT_TYPE_USERSPACEONUSE) {
if (area instanceof SVGTransformable) {
SVGTransformable tf = (SVGTransformable) area;
double x1, y1, x2, y2;
x1 = acx.getBaseVal().getValue();
y1 = -acy.getBaseVal().getValue();
x2 = afx.getBaseVal().getValue();
y2 = -afy.getBaseVal().getValue();
SVGMatrix matrix = tf.getScreenCTM();
double oldx = x1;
x1 = matrix.getA() * x1 + matrix.getB() * y1 +
matrix.getE();
y1 = matrix.getC() * oldx + matrix.getD() * y1 +
matrix.getF();
oldx = x2;
x2 = matrix.getA() * x2 + matrix.getB() * y2 +
matrix.getE();
y2 = matrix.getC() * oldx + matrix.getD() * y2 +
matrix.getF();
theCoords = new Vector();
// if(spread == SVGGradientElement.SVG_SPREADMETHOD_REFLECT) {
// } else if(spread== SVGGradientElement.SVG_SPREADMETHOD_REFLECT) {
// } else {
theCoords.addElement(
new Double(currentXPosition / 1000f + x1));
// the y val needs to be adjust by 2 * R * rotation
// depending on if this value is from an x or y coord
// before transformation
theCoords.addElement(
new Double(currentYPosition / 1000f - y1 +
(matrix.getC() - matrix.getD()) * 2 *
ar.getBaseVal().getValue()));
theCoords.addElement(new Double(0));
theCoords.addElement(
new Double(currentXPosition / 1000f + x2));
theCoords.addElement(
new Double(currentYPosition / 1000f - y2 +
(matrix.getC() - matrix.getD()) * 2 *
ar.getBaseVal().getValue()));
theCoords.addElement(
new Double(ar.getBaseVal().getValue()));
// }
}
} else if (gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX &&
area instanceof GraphicElement) {
SVGRect rect = ((GraphicElement) area).getBBox();
if (rect != null) {
theCoords = new Vector();
SVGLength val;
val = acx.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE || gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement(
new Double(currentXPosition / 1000f +
rect.getX() +
val.getValue() * rect.getWidth()));
} else {
theCoords.addElement(
new Double(currentXPosition / 1000f +
val.getValue()));
}
val = acy.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE || gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement(
new Double(currentYPosition / 1000f -
rect.getY() -
val.getValue() * rect.getHeight()));
} else {
theCoords.addElement(
new Double(currentYPosition / 1000f -
val.getValue()));
}
theCoords.addElement(new Double(0));
val = afx.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE || gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement(
new Double(currentXPosition / 1000f +
rect.getX() +
val.getValue() * rect.getWidth()));
} else {
theCoords.addElement(
new Double(currentXPosition / 1000f +
val.getValue()));
}
val = afy.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE || gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement(
new Double(currentYPosition / 1000f -
rect.getY() -
val.getValue() * rect.getHeight()));
} else {
theCoords.addElement(
new Double(currentYPosition / 1000f -
val.getValue()));
}
val = ar.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE || gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement(
new Double(val.getValue() * rect.getHeight()));
} else {
theCoords.addElement(new Double(val.getValue()));
}
}
}
if (theCoords == null) {
// percentage values are expressed according to the viewport.
SVGElement vp =
((GraphicElement) area).getNearestViewportElement();
if (area instanceof GraphicElement) {
SVGRect rect = ((GraphicElement) area).getBBox();
if (rect != null) {
theCoords = new Vector();
SVGLength val = acx.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE ||
gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement(
new Double(currentXPosition / 1000f +
rect.getX() +
val.getValue() * rect.getWidth()));
} else {
theCoords.addElement(
new Double(currentXPosition / 1000f +
val.getValue()));
}
val = acy.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE ||
gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement(
new Double(currentYPosition / 1000f -
rect.getY() -
val.getValue() * rect.getHeight()));
} else {
theCoords.addElement(
new Double(currentYPosition / 1000f -
val.getValue()));
}
theCoords.addElement(new Double(0));
val = afx.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE ||
gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement(
new Double(currentXPosition / 1000f +
rect.getX() +
val.getValue() * rect.getWidth()));
} else {
theCoords.addElement(
new Double(currentXPosition / 1000f +
val.getValue()));
}
val = afy.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE ||
gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement(
new Double(currentYPosition / 1000f -
rect.getY() -
val.getValue() * rect.getHeight()));
} else {
theCoords.addElement(
new Double(currentYPosition / 1000f -
val.getValue()));
}
val = ar.getBaseVal();
if (val.getUnitType() ==
SVGLength.SVG_LENGTHTYPE_PERCENTAGE ||
gradUnits ==
SVGUnitTypes.SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
theCoords.addElement( new Double(val.getValue() *
rect.getHeight()));
} else {
theCoords.addElement(new Double(val.getValue()));
}
}
}
}
if (theCoords == null) {
theCoords = new Vector();
theCoords.addElement( new Double(currentXPosition / 1000f +
acx.getBaseVal().getValue()));
theCoords.addElement( new Double(currentYPosition / 1000f -
acy.getBaseVal().getValue()));
theCoords.addElement(new Double(0));
theCoords.addElement( new Double(currentXPosition / 1000f +
afx.getBaseVal().getValue())); // Fx
theCoords.addElement(
new Double(currentYPosition / 1000f -
afy.getBaseVal().getValue())); // Fy
theCoords.addElement(
new Double(ar.getBaseVal().getValue()));
}
float lastoffset = 0;
for (int count = 0; count < nl.getLength(); count++) {
stop = (SVGStopElementImpl) nl.item(count);
CSSValue cv = stop.getPresentationAttribute("stop-color");
if (cv == null) {
// maybe using color
cv = stop.getPresentationAttribute("color");
}
if (cv == null) {
// problems
MessageHandler.errorln("no stop-color or color in stop element");
continue;
}
PDFColor color = new PDFColor(0, 0, 0);
if (cv != null &&
cv.getValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
if (((CSSPrimitiveValue) cv).getPrimitiveType() ==
CSSPrimitiveValue.CSS_RGBCOLOR) {
RGBColor col =
((CSSPrimitiveValue) cv).getRGBColorValue();
CSSPrimitiveValue val;
val = col.getRed();
float red = val.getFloatValue(
CSSPrimitiveValue.CSS_NUMBER);
val = col.getGreen();
float green = val.getFloatValue(
CSSPrimitiveValue.CSS_NUMBER);
val = col.getBlue();
float blue = val.getFloatValue(
CSSPrimitiveValue.CSS_NUMBER);
color = new PDFColor(red, green, blue);
}
}
float offset = stop.getOffset().getBaseVal();