Search in sources :

Example 1 with SVGPathSegLineto

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

the class SVGPathElement method isLines.

/**
 * @return True if the path is composed of lines and has a 'close path' segment at the end.
 * @since 0.1
 */
public boolean isLines() {
    final SVGPathSegList segList = getSegList();
    if (segList.size() < 3 || !(segList.get(0) instanceof SVGPathSegMoveto))
        return false;
    boolean ok = true;
    int i;
    final int size;
    for (i = 1, size = segList.size() - 1; i < size && ok; i++) if (!(segList.get(i) instanceof SVGPathSegLineto))
        ok = false;
    return ok;
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList)

Example 2 with SVGPathSegLineto

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

the class TestSVGPathSegLineto method testToString.

@Test
public void testToString() throws ParseException {
    SVGPathSegMoveto m = new SVGPathSegMoveto(0d, 0d, false);
    SVGPathParser parser = new SVGPathParser(m.toString() + " " + seg.toString(), pathSeg -> {
        if (pathSeg instanceof SVGPathSegMoveto && cpt == 0) {
            cpt++;
            return;
        }
        assertTrue(pathSeg instanceof SVGPathSegLineto);
        SVGPathSegLineto seg2 = (SVGPathSegLineto) pathSeg;
        assertEquals(seg.getX(), seg2.getX(), 0.0001);
        assertEquals(seg.getY(), seg2.getY(), 0.0001);
        assertEquals(seg.isRelative(), seg2.isRelative());
    });
    parser.parse();
}
Also used : SVGPathParser(net.sf.latexdraw.parsers.svg.parsers.SVGPathParser) SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) Test(org.junit.Test)

Example 3 with SVGPathSegLineto

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

the class TestSVGPathSegLineto method setUp.

@Before
public void setUp() {
    cpt = 0;
    seg = new SVGPathSegLineto(-1d, -2d, true);
}
Also used : SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) Before(org.junit.Before)

Example 4 with SVGPathSegLineto

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

the class SVGArrow method createLineTo.

@Override
public void createLineTo(final double x, final double y) {
    createPath();
    currentPath.add(new SVGPathSegLineto(x, y, false));
}
Also used : SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)

Example 5 with SVGPathSegLineto

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

the class SVGCircleArc method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null || 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 IPoint start = shape.getStartPoint();
    final IPoint 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 IPoint 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);
        setSVGArrow(shape, shad, 0, true, doc, defs);
        setSVGArrow(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));
    setSVGArrow(shape, elt, 0, false, doc, defs);
    setSVGArrow(shape, elt, 1, false, doc, defs);
    if (shape.isShowPts()) {
        root.appendChild(getShowPointsElement(doc));
    }
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath) SVGPathSegArc(net.sf.latexdraw.parsers.svg.path.SVGPathSegArc) ArcStyle(net.sf.latexdraw.models.interfaces.shape.ArcStyle) SVGDefsElement(net.sf.latexdraw.parsers.svg.SVGDefsElement)

Aggregations

SVGPathSegLineto (net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)12 SVGPathSegMoveto (net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto)7 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)5 SVGPathSegList (net.sf.latexdraw.parsers.svg.path.SVGPathSegList)4 SVGPathSegClosePath (net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath)3 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 ArcStyle (net.sf.latexdraw.models.interfaces.shape.ArcStyle)1 SVGDefsElement (net.sf.latexdraw.parsers.svg.SVGDefsElement)1 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)1 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)1 SVGPathElement (net.sf.latexdraw.parsers.svg.SVGPathElement)1 SVGPathParser (net.sf.latexdraw.parsers.svg.parsers.SVGPathParser)1 SVGPathSeg (net.sf.latexdraw.parsers.svg.path.SVGPathSeg)1 SVGPathSegArc (net.sf.latexdraw.parsers.svg.path.SVGPathSegArc)1 SVGPathSegCurvetoCubic (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic)1 Before (org.junit.Before)1 Test (org.junit.Test)1