Search in sources :

Example 11 with SVGPathSegMoveto

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

the class SVGPathElement method isBezierCurve.

public boolean isBezierCurve() {
    final SVGPathSegList segList = getSegList();
    if (segList.isEmpty() || !(segList.get(0) instanceof SVGPathSegMoveto)) {
        return false;
    }
    final int size = segList.size() - 1;
    boolean ok = true;
    int i;
    for (i = 1; i < size && ok; i++) {
        if (!(segList.get(i) instanceof SVGPathSegCurvetoCubic) && !(segList.get(i) instanceof SVGPathSegCurvetoCubicSmooth)) {
            ok = false;
        }
    }
    return ok && (segList.get(size) instanceof SVGPathSegClosePath || segList.get(size) instanceof SVGPathSegCurvetoCubic || segList.get(size) instanceof SVGPathSegCurvetoCubicSmooth);
}
Also used : SVGPathSegCurvetoCubicSmooth(net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubicSmooth) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic) SVGPathSegList(net.sf.latexdraw.parser.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath)

Example 12 with SVGPathSegMoveto

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

the class SVGArrow method createArc.

@Override
public void createArc(final double cx, final double cy, final double rx, final double ry, final double angle, final double length, final ObservableValue<Color> strokeProp, final ObservableDoubleValue strokeWidthProp) {
    final boolean sweepFlag = angle < 0d ^ arrow.isInverted() ^ !arrow.isLeftArrow();
    createPath();
    currentPath.add(new SVGPathSegMoveto(cx + rx * Math.cos(Math.toRadians(angle)), cy - ry * Math.sin(Math.toRadians(angle)), false));
    currentPath.add(new SVGPathSegArc(cx + rx * Math.cos(Math.toRadians(angle + length)), cy - ry * Math.sin(Math.toRadians(angle + length)), rx, ry, 0, false, sweepFlag, false));
    setPathStroke(strokeProp);
    setPathStrokeWidth(strokeWidthProp);
    setPathFill(null);
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegArc(net.sf.latexdraw.parser.svg.path.SVGPathSegArc)

Example 13 with SVGPathSegMoveto

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

the class SVGArrow method setArrow.

/**
 * Initialises the arrowhead using a path arrow.
 * @param path The path element.
 * @param owner The shape that has the arrow.
 */
final void setArrow(final SVGPathElement path, final Shape owner, final String svgMarker) {
    final SVGPathSegList list = path.getSegList();
    final SVGPathSegMoveto m = (SVGPathSegMoveto) list.get(0);
    final double lineWidth = owner.hasDbleBord() ? owner.getDbleBordSep() + 2d * owner.getThickness() : owner.getThickness();
    // == 4 is legacy code for 3.x
    if (list.size() == 2 || list.size() == 4 || list.size() == 6) {
        setArrowBarBracket(path, m, lineWidth, list.get(1), list, svgMarker);
    } else {
        // == 10 is legacy code for the 3.x branch. Now the double arrow has 12 elements.
        if (list.size() == 5 || list.size() == 10 || list.size() == 12) {
            setArrowArrow(path, m, lineWidth, list.get(1), list, svgMarker);
        }
    }
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegList(net.sf.latexdraw.parser.svg.path.SVGPathSegList)

Example 14 with SVGPathSegMoveto

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

the class SVGBezierCurve method pathToBezierCurve.

/**
 * Creates a bezier curve and initialises its path from an SVG element.
 */
private static BezierCurve pathToBezierCurve(final SVGElement elt) {
    if (!(elt instanceof SVGPathElement)) {
        return null;
    }
    final SVGPathSegList list = ((SVGPathElement) elt).getSegList();
    if (list.size() < 2 || !(list.get(0) instanceof SVGPathSegMoveto)) {
        return null;
    }
    final SVGPathSegMoveto m = (SVGPathSegMoveto) list.get(0);
    CtrlPointsSeg c;
    int i = 1;
    final int size = list.size();
    // Creating a point to support when the first path element is relative.
    Point2D pt = new Point2D.Double();
    final List<Point> pts = new ArrayList<>();
    final List<Point> ctrlpts = new ArrayList<>();
    final boolean closed;
    pt = m.getPoint(pt);
    pts.add(ShapeFactory.INST.createPoint(pt));
    if (list.get(1) instanceof CtrlPointsSeg) {
        // We set the control point of the first point.
        c = (CtrlPointsSeg) list.get(1);
        ctrlpts.add(ShapeFactory.INST.createPoint(c.getCtrl1(pt)));
    }
    while (i < size && list.get(i) instanceof CtrlPointsSeg) {
        c = (CtrlPointsSeg) list.get(i);
        final Point2D currPt = c.getPoint(pt);
        pts.add(ShapeFactory.INST.createPoint(currPt));
        ctrlpts.add(ShapeFactory.INST.createPoint(c.getCtrl2(pt)));
        pt = currPt;
        i++;
    }
    if (pts.size() > 2 && pts.get(pts.size() - 1).equals(pts.get(0), 0.00001)) {
        // We set the shape as closed
        pts.remove(pts.size() - 1);
        ctrlpts.remove(ctrlpts.size() - 1);
        closed = true;
    } else {
        // There is something else at the end of the path.
        closed = i < size && list.get(i) instanceof SVGPathSegClosePath;
    }
    final BezierCurve bc = ShapeFactory.INST.createBezierCurve(pts, ctrlpts);
    bc.setOpened(!closed);
    return bc;
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathElement(net.sf.latexdraw.parser.svg.SVGPathElement) ArrayList(java.util.ArrayList) Point(net.sf.latexdraw.model.api.shape.Point) SVGPathSegList(net.sf.latexdraw.parser.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath) Point(net.sf.latexdraw.model.api.shape.Point) Point2D(java.awt.geom.Point2D) CtrlPointsSeg(net.sf.latexdraw.parser.svg.path.CtrlPointsSeg) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve)

Example 15 with SVGPathSegMoveto

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

the class TestSVGPathSegArc 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 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());
    });
    assertTrue(done.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegArc(net.sf.latexdraw.parser.svg.path.SVGPathSegArc) 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