use of net.sf.latexdraw.parsers.svg.SVGStopElement in project latexdraw by arnobl.
the class SVGShape method setSVGLinearGradient.
private void setSVGLinearGradient(final SVGDocument doc, final SVGElement root) {
final SVGDefsElement defs = doc.getFirstChild().getDefs();
final SVGElement grad = new SVGLinearGradientElement(doc);
final double gradMidPt = shape.getGradMidPt();
final double gradAngle = shape.getGradAngle();
final String id = SVGElements.SVG_LINEAR_GRADIENT + shape.hashCode();
grad.setAttribute(SVGAttributes.SVG_ID, id);
if (!MathUtils.INST.equalsDouble(MathUtils.INST.mod2pi(gradAngle + Math.PI / 2d), 0d)) {
final SVGTransform rotate = new SVGTransform();
rotate.setRotate(toDegrees(gradAngle) + 90d, 0.5, 0.5);
grad.setAttribute(SVGAttributes.SVG_GRADIENT_TRANSFORM, rotate.toString());
}
final SVGStopElement stop1 = new SVGStopElement(doc);
stop1.setAttribute(SVGAttributes.SVG_OFFSET, "0");
stop1.setAttribute(SVGAttributes.SVG_STOP_COLOR, CSSColors.INSTANCE.getColorName(shape.getGradColStart(), true));
if (shape.getGradColStart().getO() < 1d) {
stop1.setAttribute(SVGAttributes.SVG_STOP_OPACITY, MathUtils.INST.format.format(shape.getGradColStart().getO()));
}
grad.appendChild(stop1);
final SVGStopElement stop2 = new SVGStopElement(doc);
stop2.setAttribute(SVGAttributes.SVG_OFFSET, MathUtils.INST.format.format(gradMidPt));
stop2.setAttribute(SVGAttributes.SVG_STOP_COLOR, CSSColors.INSTANCE.getColorName(shape.getGradColEnd(), true));
if (shape.getGradColEnd().getO() < 1d) {
stop2.setAttribute(SVGAttributes.SVG_STOP_OPACITY, MathUtils.INST.format.format(shape.getGradColEnd().getO()));
}
grad.appendChild(stop2);
defs.appendChild(grad);
root.setAttribute(SVGAttributes.SVG_FILL, SVG_URL_TOKEN_BEGIN + id + ')');
}
Aggregations