Search in sources :

Example 1 with SVGPathSeg

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

Aggregations

Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)1 SVGPathSeg (net.sf.latexdraw.parsers.svg.path.SVGPathSeg)1 SVGPathSegClosePath (net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath)1 SVGPathSegLineto (net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)1 SVGPathSegList (net.sf.latexdraw.parsers.svg.path.SVGPathSegList)1