Search in sources :

Example 1 with SVGPathSegMoveto

use of net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto 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 SVGPathSegMoveto

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

the class SVGPathParser method parseMoveto.

/**
 * Parses an SVGPath moveto.
 * @param isRelative True if segment is relative.
 * @throws ParseException If a problem occurs.
 */
protected void parseMoveto(final boolean isRelative) throws ParseException {
    nextChar();
    skipWSP();
    final double x = parseNumber(false);
    skipWSPComma();
    final double y = parseNumber(false);
    skipWSPComma();
    handler.onPathSeg(new SVGPathSegMoveto(x, y, isRelative));
    parserPathSeg(isRelative);
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto)

Example 3 with SVGPathSegMoveto

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

the class TestSVGPathSegArc method testToString.

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

Example 4 with SVGPathSegMoveto

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

the class TestSVGPathSegCurvetoCubic method testToString.

@Test
public void testToString() throws ParseException {
    SVGPathSegMoveto m = new SVGPathSegMoveto(0, 0, false);
    SVGPathParser parser = new SVGPathParser(m.toString() + " " + seg.toString(), pathSeg -> {
        if (pathSeg instanceof SVGPathSegMoveto && cpt == 0) {
            cpt++;
            return;
        }
        assertTrue(pathSeg instanceof SVGPathSegCurvetoCubic);
        SVGPathSegCurvetoCubic seg2 = (SVGPathSegCurvetoCubic) 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) SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) Test(org.junit.Test)

Example 5 with SVGPathSegMoveto

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

the class TestSVGPathSegCurvetoCubicSmooth 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 SVGPathSegCurvetoCubicSmooth);
        SVGPathSegCurvetoCubicSmooth seg2 = (SVGPathSegCurvetoCubicSmooth) 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) SVGPathSegCurvetoCubicSmooth(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubicSmooth) SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) Test(org.junit.Test)

Aggregations

SVGPathSegMoveto (net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto)22 SVGPathParser (net.sf.latexdraw.parsers.svg.parsers.SVGPathParser)9 Test (org.junit.Test)9 SVGPathSegLineto (net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)7 SVGPathSegList (net.sf.latexdraw.parsers.svg.path.SVGPathSegList)7 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)6 SVGPathSegClosePath (net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath)5 SVGPathSegCurvetoCubic (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic)4 SVGPathSegArc (net.sf.latexdraw.parsers.svg.path.SVGPathSegArc)3 SVGPathElement (net.sf.latexdraw.parsers.svg.SVGPathElement)2 SVGPathSegCurvetoCubicSmooth (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubicSmooth)2 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 ArcStyle (net.sf.latexdraw.models.interfaces.shape.ArcStyle)1 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)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 CtrlPointsSeg (net.sf.latexdraw.parsers.svg.path.CtrlPointsSeg)1 SVGPathSegCurvetoQuadratic (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoQuadratic)1