Search in sources :

Example 1 with SVGPathSegList

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

the class SVGPathElement method getSegList.

/**
 * @return the segList.
 * @since 0.1
 */
public SVGPathSegList getSegList() {
    final String path = getPathData();
    final SVGPathSegList segList = new SVGPathSegList();
    final SVGPathParser pp = new SVGPathParser(path, segList);
    try {
        pp.parse();
    }// $NON-NLS-1$ //$NON-NLS-2$
     catch (final ParseException e) {
        throw new IllegalArgumentException(e + " But : \"" + path + "\" found.");
    }
    return segList;
}
Also used : SVGPathParser(net.sf.latexdraw.parsers.svg.parsers.SVGPathParser) ParseException(java.text.ParseException) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList)

Example 2 with SVGPathSegList

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

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

the class SVGAxes method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        return null;
    }
    currentDoc = doc;
    currentPath = new SVGPathSegList();
    currentTicks = new SVGGElement(doc);
    final SVGElement root = new SVGGElement(doc);
    final String pref = LNamespace.LATEXDRAW_NAMESPACE + ':';
    final SVGPathElement path = new SVGPathElement(doc);
    setSVGAttributes(doc, root, false);
    root.setAttribute(SVGAttributes.SVG_TRANSFORM, "translate(" + MathUtils.INST.format.format(shape.getPosition().getX()) + ',' + MathUtils.INST.format.format(shape.getPosition().getY()) + ')');
    root.setAttribute(pref + LNamespace.XML_STYLE, shape.getAxesStyle().toString());
    root.setAttribute(pref + LNamespace.XML_GRID_START, shape.getGridStartX() + " " + shape.getGridStartY());
    root.setAttribute(pref + LNamespace.XML_GRID_END, shape.getGridEndX() + " " + shape.getGridEndY());
    root.setAttribute(pref + LNamespace.XML_GRID_ORIGIN, shape.getOriginX() + " " + shape.getOriginY());
    root.setAttribute(pref + LNamespace.XML_AXE_INCREMENT, shape.getIncrementX() + " " + shape.getIncrementY());
    root.setAttribute(pref + LNamespace.XML_AXE_DIST_LABELS, shape.getDistLabelsX() + " " + shape.getDistLabelsY());
    root.setAttribute(pref + LNamespace.XML_AXE_TICKS_SIZE, String.valueOf(shape.getTicksSize()));
    root.setAttribute(pref + LNamespace.XML_AXE_SHOW_ORIGIN, String.valueOf(shape.isShowOrigin()));
    root.setAttribute(pref + LNamespace.XML_AXE_SHOW_TICKS, shape.getTicksDisplayed().toString());
    root.setAttribute(pref + LNamespace.XML_AXE_LABELS_STYLE, shape.getLabelsDisplayed().toString());
    root.setAttribute(pref + LNamespace.XML_AXE_TICKS_STYLE, shape.getTicksStyle().toString());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_AXE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    createSVGAxe(root, doc);
    setSVGRotationAttribute(root);
    updatePathTicks();
    updatePathLabels();
    root.appendChild(currentTicks);
    path.setPathData(currentPath);
    root.appendChild(path);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList)

Example 4 with SVGPathSegList

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

the class SVGBezierCurve method getPathSegList.

/**
 * @return The SVG segment path list of the current Bézier curve.
 * @since 2.0.0
 */
protected SVGPathSegList getPathSegList() {
    if (shape.getNbPoints() < 2) {
        return null;
    }
    final int size = shape.getNbPoints();
    int i;
    final SVGPathSegList path = new SVGPathSegList();
    path.add(new SVGPathSegMoveto(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), false));
    path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(1).getX(), shape.getPtAt(1).getY(), shape.getFirstCtrlPtAt(0).getX(), shape.getFirstCtrlPtAt(0).getY(), shape.getFirstCtrlPtAt(1).getX(), shape.getFirstCtrlPtAt(1).getY(), false));
    for (i = 2; i < size; i++) {
        path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(i).getX(), shape.getPtAt(i).getY(), shape.getSecondCtrlPtAt(i - 1).getX(), shape.getSecondCtrlPtAt(i - 1).getY(), shape.getFirstCtrlPtAt(i).getX(), shape.getFirstCtrlPtAt(i).getY(), false));
    }
    if (!shape.isOpened()) {
        final IPoint ctrl1b = shape.getFirstCtrlPtAt(0).centralSymmetry(shape.getPtAt(0));
        final IPoint ctrl2b = shape.getFirstCtrlPtAt(-1).centralSymmetry(shape.getPtAt(-1));
        path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), ctrl2b.getX(), ctrl2b.getY(), ctrl1b.getX(), ctrl1b.getY(), false));
        path.add(new SVGPathSegClosePath());
    }
    return path;
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 5 with SVGPathSegList

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

SVGPathSegList (net.sf.latexdraw.parsers.svg.path.SVGPathSegList)12 SVGPathSegMoveto (net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto)8 SVGPathSegClosePath (net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath)7 SVGPathSegLineto (net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)5 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)4 SVGPathElement (net.sf.latexdraw.parsers.svg.SVGPathElement)4 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)3 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)3 SVGPathSegCurvetoCubic (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic)3 Point2D (java.awt.geom.Point2D)2 ArrayList (java.util.ArrayList)2 SVGPathSeg (net.sf.latexdraw.parsers.svg.path.SVGPathSeg)2 ParseException (java.text.ParseException)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Group (javafx.scene.Group)1 Node (javafx.scene.Node)1 Color (javafx.scene.paint.Color)1 ClosePath (javafx.scene.shape.ClosePath)1