Search in sources :

Example 1 with SVGPathSegMoveto

use of net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class SVGCircleArc method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (doc.getFirstChild().getDefs() == null) {
        return null;
    }
    final SVGDefsElement defs = doc.getFirstChild().getDefs();
    final double rotationAngle = shape.getRotationAngle();
    final double startAngle = shape.getAngleStart() % (2. * Math.PI);
    final double endAngle = shape.getAngleEnd() % (2. * Math.PI);
    final ArcStyle type = shape.getArcStyle();
    final SVGElement root = new SVGGElement(doc);
    final Point start = shape.getStartPoint();
    final Point end = shape.getEndPoint();
    final double radius = shape.getWidth() / 2.0;
    final boolean largeArcFlag = Math.abs(endAngle - startAngle) >= Math.PI;
    final boolean sweepFlag = startAngle >= endAngle;
    final SVGPathSegList path = new SVGPathSegList();
    SVGElement elt;
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_ARC);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    path.add(new SVGPathSegMoveto(start.getX(), start.getY(), false));
    path.add(new SVGPathSegArc(end.getX(), end.getY(), radius, radius, 0, largeArcFlag, sweepFlag, false));
    if (type == ArcStyle.CHORD) {
        path.add(new SVGPathSegClosePath());
    } else {
        if (type == ArcStyle.WEDGE) {
            final Point gravityCenter = shape.getGravityCentre();
            path.add(new SVGPathSegLineto(gravityCenter.getX(), gravityCenter.getY(), false));
            path.add(new SVGPathSegClosePath());
        }
    }
    if (shape.hasShadow()) {
        final SVGElement shad = new SVGPathElement(doc);
        shad.setAttribute(SVGAttributes.SVG_D, path.toString());
        setSVGShadowAttributes(shad, true);
        root.appendChild(shad);
        parameteriseSVGArrow(shape, shad, 0, true, doc, defs);
        parameteriseSVGArrow(shape, shad, 1, true, doc, defs);
    }
    // The background of the borders must be filled is there is a shadow.
    if (shape.hasShadow()) {
        elt = new SVGPathElement(doc);
        elt.setAttribute(SVGAttributes.SVG_D, path.toString());
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGPathElement(doc);
    elt.setAttribute(SVGAttributes.SVG_D, path.toString());
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        final SVGElement dble = new SVGPathElement(doc);
        dble.setAttribute(SVGAttributes.SVG_D, path.toString());
        setSVGDoubleBordersAttributes(dble);
        root.appendChild(dble);
    }
    setSVGRotationAttribute(root);
    setSVGAttributes(doc, elt, true);
    elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(rotationAngle));
    parameteriseSVGArrow(shape, elt, 0, false, doc, defs);
    parameteriseSVGArrow(shape, elt, 1, false, doc, defs);
    if (shape.isShowPts()) {
        root.appendChild(getShowPointsElement(doc));
    }
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathElement(net.sf.latexdraw.parser.svg.SVGPathElement) Point(net.sf.latexdraw.model.api.shape.Point) SVGPathSegLineto(net.sf.latexdraw.parser.svg.path.SVGPathSegLineto) SVGPathSegList(net.sf.latexdraw.parser.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath) SVGPathSegArc(net.sf.latexdraw.parser.svg.path.SVGPathSegArc) ArcStyle(net.sf.latexdraw.model.api.shape.ArcStyle) SVGDefsElement(net.sf.latexdraw.parser.svg.SVGDefsElement)

Example 2 with SVGPathSegMoveto

use of net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class TestSVGPathSegCurvetoQuadraticSmooth method testToString.

@Test
public void testToString() {
    final AtomicBoolean done = new AtomicBoolean(false);
    final SVGPathSegMoveto m = new SVGPathSegMoveto(0d, 0d, false);
    SVGParserUtils.INSTANCE.parseSVGPath(m.toString() + " " + seg.toString(), pathSeg -> {
        if (pathSeg instanceof SVGPathSegMoveto) {
            return;
        }
        done.set(true);
        final SVGPathSegCurvetoQuadraticSmooth seg2 = (SVGPathSegCurvetoQuadraticSmooth) pathSeg;
        assertEquals(seg.getX(), seg2.getX(), 0.0001);
        assertEquals(seg.getY(), seg2.getY(), 0.0001);
        assertEquals(seg.isRelative(), seg2.isRelative());
    });
    assertTrue(done.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SVGPathSegCurvetoQuadraticSmooth(net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoQuadraticSmooth) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) Test(org.junit.jupiter.api.Test)

Example 3 with SVGPathSegMoveto

use of net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class TestSVGPathSegMoveto method testToString.

@Test
@NoBadaboomCheck
public void testToString() {
    final AtomicBoolean done = new AtomicBoolean(false);
    SVGParserUtils.INSTANCE.parseSVGPath(seg.toString(), pathSeg -> {
        done.set(true);
        final SVGPathSegMoveto seg2 = (SVGPathSegMoveto) pathSeg;
        assertEquals(seg.getX(), seg2.getX(), 0.0001);
        assertEquals(seg.getY(), seg2.getY(), 0.0001);
        assertEquals(seg.isRelative(), seg2.isRelative());
    });
    assertTrue(done.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) Test(org.junit.jupiter.api.Test) NoBadaboomCheck(net.sf.latexdraw.NoBadaboomCheck)

Example 4 with SVGPathSegMoveto

use of net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class TestSVGPathSegCurvetoCubic method testToString.

@Test
void testToString() {
    final AtomicBoolean done = new AtomicBoolean(false);
    final SVGPathSegMoveto m = new SVGPathSegMoveto(0, 0, false);
    SVGParserUtils.INSTANCE.parseSVGPath(m.toString() + " " + seg.toString(), pathSeg -> {
        if (pathSeg instanceof SVGPathSegMoveto) {
            return;
        }
        done.set(true);
        final SVGPathSegCurvetoCubic seg2 = (SVGPathSegCurvetoCubic) pathSeg;
        assertEquals(seg.getX(), seg2.getX(), 0.0001);
        assertEquals(seg.getY(), seg2.getY(), 0.0001);
        assertEquals(seg.isRelative(), seg2.isRelative());
    });
    assertTrue(done.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic) Test(org.junit.jupiter.api.Test)

Example 5 with SVGPathSegMoveto

use of net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto in project latexdraw by arnobl.

the class TestSVGPathSegCurvetoQuadratic method testToString.

@Test
void testToString() {
    final AtomicBoolean done = new AtomicBoolean(false);
    final SVGPathSegMoveto m = new SVGPathSegMoveto(0d, 0d, false);
    SVGParserUtils.INSTANCE.parseSVGPath(m.toString() + " " + seg.toString(), pathSeg -> {
        if (pathSeg instanceof SVGPathSegMoveto) {
            return;
        }
        done.set(true);
        final SVGPathSegCurvetoQuadratic seg2 = (SVGPathSegCurvetoQuadratic) pathSeg;
        assertEquals(seg.getX(), seg2.getX(), 0.0001);
        assertEquals(seg.getX1(), seg2.getX1(), 0.0001);
        assertEquals(seg.getY(), seg2.getY(), 0.0001);
        assertEquals(seg.getY1(), seg2.getY1(), 0.0001);
        assertEquals(seg.isRelative(), seg2.isRelative());
    });
    assertTrue(done.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoQuadratic(net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoQuadratic) Test(org.junit.jupiter.api.Test)

Aggregations

SVGPathSegMoveto (net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 Test (org.junit.jupiter.api.Test)9 SVGPathSegList (net.sf.latexdraw.parser.svg.path.SVGPathSegList)7 SVGPathSegClosePath (net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath)5 SVGPathSegLineto (net.sf.latexdraw.parser.svg.path.SVGPathSegLineto)4 Point (net.sf.latexdraw.model.api.shape.Point)3 SVGPathSegArc (net.sf.latexdraw.parser.svg.path.SVGPathSegArc)3 SVGPathSegCurvetoCubic (net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic)3 SVGPathElement (net.sf.latexdraw.parser.svg.SVGPathElement)2 SVGPathSegCurvetoCubicSmooth (net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubicSmooth)2 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 NoBadaboomCheck (net.sf.latexdraw.NoBadaboomCheck)1 ArcStyle (net.sf.latexdraw.model.api.shape.ArcStyle)1 BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)1 SVGDefsElement (net.sf.latexdraw.parser.svg.SVGDefsElement)1 SVGElement (net.sf.latexdraw.parser.svg.SVGElement)1 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)1 CtrlPointsSeg (net.sf.latexdraw.parser.svg.path.CtrlPointsSeg)1