Search in sources :

Example 1 with SVGTransform

use of net.sf.latexdraw.parsers.svg.SVGTransform 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 + ')');
}
Also used : SVGTransform(net.sf.latexdraw.parsers.svg.SVGTransform) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGDefsElement(net.sf.latexdraw.parsers.svg.SVGDefsElement) SVGStopElement(net.sf.latexdraw.parsers.svg.SVGStopElement) SVGLinearGradientElement(net.sf.latexdraw.parsers.svg.SVGLinearGradientElement)

Example 2 with SVGTransform

use of net.sf.latexdraw.parsers.svg.SVGTransform in project latexdraw by arnobl.

the class SVGShape method setSVGShadowParameters.

/**
 * Sets the shadow parameters of the figure by using an SVG element having "type:shadow".
 * @param elt The source element.
 */
protected void setSVGShadowParameters(final SVGElement elt) {
    if (elt == null || !shape.isShadowable())
        return;
    if (shape.isFillable()) {
        final String fill = elt.getFill();
        if (fill != null && !fill.equals(SVGAttributes.SVG_VALUE_NONE) && !fill.startsWith(SVG_URL_TOKEN_BEGIN)) {
            shape.setShadowCol(CSSColors.INSTANCE.getRGBColour(fill));
        }
    }
    final Color strok = elt.getStroke();
    if (strok != null) {
        shape.setShadowCol(strok);
    }
    final SVGTransformList tl = elt.getTransform();
    SVGTransform t;
    double tx;
    double ty;
    boolean sSize = false;
    boolean sAngle = false;
    for (int i = 0, size = tl.size(); i < size && (!sSize || !sAngle); i++) {
        t = tl.get(i);
        if (t.isTranslation()) {
            tx = t.getTX();
            ty = t.getTY();
            if (MathUtils.INST.equalsDouble(ty, 0.) && !sSize) {
                // It is shadowSize.
                shape.setShadowSize(tx);
                sSize = true;
            } else {
                final IPoint gravityCenter = shape.getGravityCentre();
                double angle;
                final double shSize = shape.getShadowSize();
                if (MathUtils.INST.equalsDouble(ty, 0.)) {
                    angle = tx < 0. ? Math.PI : 0.;
                } else {
                    if (MathUtils.INST.equalsDouble(shSize, Math.abs(tx))) {
                        angle = ty > 0. ? -Math.PI / 2. : Math.PI / 2.;
                    } else {
                        angle = Math.acos(gravityCenter.distance(gravityCenter.getX() + tx + shSize, gravityCenter.getY()) / gravityCenter.distance(gravityCenter.getX() + tx + shSize, gravityCenter.getY() + ty));
                        if (tx + shSize < 0) {
                            if (ty < 0.) {
                                angle = Math.PI - angle;
                            } else {
                                angle += Math.PI;
                            }
                        } else {
                            if (ty > 0.) {
                                angle *= -1;
                            }
                        }
                    }
                }
                shape.setShadowAngle(angle);
                sAngle = true;
            }
        }
    }
    shape.setHasShadow(true);
}
Also used : SVGTransform(net.sf.latexdraw.parsers.svg.SVGTransform) Color(net.sf.latexdraw.models.interfaces.shape.Color) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGTransformList(net.sf.latexdraw.parsers.svg.SVGTransformList)

Example 3 with SVGTransform

use of net.sf.latexdraw.parsers.svg.SVGTransform in project latexdraw by arnobl.

the class TestSVGTransform method setUp.

@Before
public void setUp() {
    t = new SVGTransform();
    m = t.getMatrix();
}
Also used : SVGTransform(net.sf.latexdraw.parsers.svg.SVGTransform) Before(org.junit.Before)

Aggregations

SVGTransform (net.sf.latexdraw.parsers.svg.SVGTransform)3 Color (net.sf.latexdraw.models.interfaces.shape.Color)1 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)1 SVGDefsElement (net.sf.latexdraw.parsers.svg.SVGDefsElement)1 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)1 SVGLinearGradientElement (net.sf.latexdraw.parsers.svg.SVGLinearGradientElement)1 SVGStopElement (net.sf.latexdraw.parsers.svg.SVGStopElement)1 SVGTransformList (net.sf.latexdraw.parsers.svg.SVGTransformList)1 Before (org.junit.Before)1