Search in sources :

Example 1 with SVGPathSeg

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

the class SVGModifiablePointsShape method getLinePointsFromSVGPathElement.

/**
 * Gets the line points from the given SVGPathElement
 */
static List<Point> 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<Point> pts = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        final SVGPathSeg seg = segs.get(i);
        if (!(seg instanceof SVGPathSegLineto)) {
            // NON-NLS
            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.parser.svg.path.SVGPathSeg) Point2D(java.awt.geom.Point2D) ArrayList(java.util.ArrayList) Point(net.sf.latexdraw.model.api.shape.Point) SVGPathSegLineto(net.sf.latexdraw.parser.svg.path.SVGPathSegLineto) SVGPathSegList(net.sf.latexdraw.parser.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath) Point(net.sf.latexdraw.model.api.shape.Point)

Aggregations

Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 Point (net.sf.latexdraw.model.api.shape.Point)1 SVGPathSeg (net.sf.latexdraw.parser.svg.path.SVGPathSeg)1 SVGPathSegClosePath (net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath)1 SVGPathSegLineto (net.sf.latexdraw.parser.svg.path.SVGPathSegLineto)1 SVGPathSegList (net.sf.latexdraw.parser.svg.path.SVGPathSegList)1