Search in sources :

Example 6 with SVGPathSegList

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

the class SVGModifiablePointsShape method getLinePointsFromSVGPathElement.

/**
 * Gets the line points from the given SVGPathElement
 */
static List<IPoint> getLinePointsFromSVGPathElement(final SVGPathElement elt) {
    if (elt == null) {
        return Collections.emptyList();
    }
    final SVGPathSegList segs = elt.getSegList();
    final int size = segs.get(segs.size() - 1) instanceof SVGPathSegClosePath ? segs.size() - 1 : segs.size();
    // Creating a point to support when the first path element is relative.
    Point2D pt = new Point2D.Double();
    final List<IPoint> pts = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        final SVGPathSeg seg = segs.get(i);
        if (!(seg instanceof SVGPathSegLineto)) {
            // $NON-NLS-1$
            throw new IllegalArgumentException("The given SVG path element is not a set of lines.");
        }
        pt = ((SVGPathSegLineto) seg).getPoint(pt);
        pts.add(ShapeFactory.INST.createPoint(pt.getX(), pt.getY()));
    }
    return pts;
}
Also used : SVGPathSeg(net.sf.latexdraw.parsers.svg.path.SVGPathSeg) Point2D(java.awt.geom.Point2D) ArrayList(java.util.ArrayList) 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) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 7 with SVGPathSegList

use of net.sf.latexdraw.parsers.svg.path.SVGPathSegList 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.
 */
void setArrow(final SVGPathElement path, final IShape 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.parsers.svg.path.SVGPathSegMoveto) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList)

Example 8 with SVGPathSegList

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

the class SVGBezierCurve method pathToBezierCurve.

/**
 * Creates a bezier curve and initialises its path from an SVG element.
 */
private static IBezierCurve pathToBezierCurve(final SVGElement elt) {
    if (!(elt instanceof SVGPathElement)) {
        return null;
    }
    final SVGPathSegList list = ((SVGPathElement) elt).getSegList();
    if (list == null || 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<IPoint> pts = new ArrayList<>();
    final List<IPoint> 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 IBezierCurve bc = ShapeFactory.INST.createBezierCurve(pts, ctrlpts);
    bc.setOpened(!closed);
    return bc;
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) ArrayList(java.util.ArrayList) 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) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) Point2D(java.awt.geom.Point2D) CtrlPointsSeg(net.sf.latexdraw.parsers.svg.path.CtrlPointsSeg)

Example 9 with SVGPathSegList

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

the class SVGShape method getSVGHatchingsPath.

/**
 * @return The path of the hatchings of the shape.
 */
public SVGPathSegList getSVGHatchingsPath() {
    final SVGPathSegList path = new SVGPathSegList();
    if (!shape.hasHatchings()) {
        return path;
    }
    final String hatchingStyle = shape.getFillingStyle().getLatexToken();
    final double hatchingAngle = shape.getHatchingsAngle();
    final IRectangle bound = ShapeFactory.INST.createRectangle(shape.getFullTopLeftPoint(), shape.getFullBottomRightPoint());
    switch(hatchingStyle) {
        case PSTricksConstants.TOKEN_FILL_VLINES:
        case PSTricksConstants.TOKEN_FILL_VLINES_F:
            getSVGHatchingsPath2(path, hatchingAngle, bound);
            break;
        case PSTricksConstants.TOKEN_FILL_HLINES:
        case PSTricksConstants.TOKEN_FILL_HLINES_F:
            getSVGHatchingsPath2(path, hatchingAngle > 0 ? hatchingAngle - Math.PI / 2. : hatchingAngle + Math.PI / 2., bound);
            break;
        case PSTricksConstants.TOKEN_FILL_CROSSHATCH:
        case PSTricksConstants.TOKEN_FILL_CROSSHATCH_F:
            getSVGHatchingsPath2(path, hatchingAngle, bound);
            getSVGHatchingsPath2(path, hatchingAngle > 0 ? hatchingAngle - Math.PI / 2. : hatchingAngle + Math.PI / 2., bound);
            break;
    }
    return path;
}
Also used : SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) IRectangle(net.sf.latexdraw.models.interfaces.shape.IRectangle)

Example 10 with SVGPathSegList

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

the class JFXToSVG method pathToSVGPath.

/**
 * Converts a JFX path to an SVGPath.
 * @param path To JFX path to convert.
 * @param doc The SVG document.
 * @return The created SVGPath.
 * @throws NullPointerException If one of the given parameter is null.
 */
public SVGPathElement pathToSVGPath(final Path path, final SVGDocument doc) {
    final SVGPathElement svgPath = new SVGPathElement(doc);
    final SVGPathSegList list = new SVGPathSegList();
    list.addAll(path.getElements().stream().map(elt -> createSVGPathSeg(elt)).filter(elt -> elt != null).collect(Collectors.toList()));
    svgPath.setPathData(list);
    copyPropertiesToSVG(svgPath, path);
    return svgPath;
}
Also used : Path(javafx.scene.shape.Path) ClosePath(javafx.scene.shape.ClosePath) CubicCurveTo(javafx.scene.shape.CubicCurveTo) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) LineTo(javafx.scene.shape.LineTo) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) MoveTo(javafx.scene.shape.MoveTo) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGPathSeg(net.sf.latexdraw.parsers.svg.path.SVGPathSeg) SVGAttributes(net.sf.latexdraw.parsers.svg.SVGAttributes) Color(javafx.scene.paint.Color) Ellipse(javafx.scene.shape.Ellipse) Node(javafx.scene.Node) SVGDocument(net.sf.latexdraw.parsers.svg.SVGDocument) PathElement(javafx.scene.shape.PathElement) Group(javafx.scene.Group) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) Collectors(java.util.stream.Collectors) SVGEllipseElement(net.sf.latexdraw.parsers.svg.SVGEllipseElement) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) SVGPathSegClosePath(net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath) List(java.util.List) StrokeLineCap(javafx.scene.shape.StrokeLineCap) Collections(java.util.Collections) Shape(javafx.scene.shape.Shape) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList)

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