Search in sources :

Example 6 with SVGPathSegLineto

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

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

the class SVGShape method getSVGHatchingsPath2.

private void getSVGHatchingsPath2(final SVGPathSegList path, final double hAngle, final IRectangle bound) {
    if (path == null || bound == null)
        return;
    double angle2 = hAngle % (Math.PI * 2.);
    final double halphPI = Math.PI / 2.;
    final double hatchingWidth = shape.getHatchingsWidth();
    final double hatchingSep = shape.getHatchingsSep();
    final IPoint nw = bound.getTopLeftPoint();
    final IPoint se = bound.getBottomRightPoint();
    final double nwx = nw.getX();
    final double nwy = nw.getY();
    final double sex = se.getX();
    final double sey = se.getY();
    // Computing the angle.
    if (angle2 > 0.) {
        if (angle2 > 3. * halphPI) {
            angle2 -= Math.PI * 2.;
        } else {
            if (angle2 > halphPI) {
                angle2 -= Math.PI;
            }
        }
    } else {
        if (angle2 < -3. * halphPI) {
            angle2 += Math.PI * 2.;
        } else {
            if (angle2 < -halphPI) {
                angle2 += Math.PI;
            }
        }
    }
    final double val = hatchingWidth + hatchingSep;
    if (MathUtils.INST.equalsDouble(angle2, 0.))
        // Drawing the hatchings vertically.
        for (double x = nwx; x < sex; x += val) {
            path.add(new SVGPathSegMoveto(x, nwy, false));
            path.add(new SVGPathSegLineto(x, sey, false));
        }
    else // Drawing the hatchings horizontally.
    if (MathUtils.INST.equalsDouble(angle2, halphPI) || MathUtils.INST.equalsDouble(angle2, -halphPI))
        for (double y = nwy; y < sey; y += val) {
            path.add(new SVGPathSegMoveto(nwx, y, false));
            path.add(new SVGPathSegLineto(sex, y, false));
        }
    else {
        // Drawing the hatchings by rotation.
        final double incX = val / Math.cos(angle2);
        final double incY = val / Math.sin(angle2);
        final double maxX;
        double y1;
        double x2;
        final double y2;
        final double x1;
        if (angle2 > 0.) {
            y1 = nwy;
            maxX = sex + (sey - (nwy < 0 ? nwy : 0)) * Math.tan(angle2);
        } else {
            y1 = sey;
            maxX = sex - sey * Math.tan(angle2);
        }
        x1 = nwx;
        x2 = x1;
        y2 = y1;
        if (incX < 0. || MathUtils.INST.equalsDouble(incX, 0.)) {
            return;
        }
        while (x2 < maxX) {
            x2 += incX;
            y1 += incY;
            path.add(new SVGPathSegMoveto(x1, y1, false));
            path.add(new SVGPathSegLineto(x2, y2, false));
        }
    }
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)

Example 8 with SVGPathSegLineto

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

the class SVGFreeHand method getPathLines.

/**
 * Fills the given SVG path with elements corresponding to the Freehand lined path.
 * @since 3.0
 */
protected void getPathLines(final SVGPathSegList path) {
    final IPoint p = shape.getPtAt(0);
    int i;
    final int size = shape.getNbPoints();
    final int interval = shape.getInterval();
    path.add(new SVGPathSegMoveto(p.getX(), p.getY(), false));
    for (i = interval; i < size; i += interval) {
        path.add(new SVGPathSegLineto(shape.getPtAt(i).getX(), shape.getPtAt(i).getY(), false));
    }
    if (i - interval < size) {
        path.add(new SVGPathSegLineto(shape.getPtAt(-1).getX(), shape.getPtAt(-1).getY(), false));
    }
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 9 with SVGPathSegLineto

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

the class SVGFreeHand method getPathCurves.

/**
 * Fills the given SVG path with elements corresponding to the Freehand curved path.
 * @since 3.0
 */
protected void getPathCurves(final SVGPathSegList path) {
    double prevx = shape.getPtAt(-1).getX();
    double prevy = shape.getPtAt(-1).getY();
    double curx = shape.getPtAt(0).getX();
    double cury = shape.getPtAt(0).getY();
    double midx = (curx + prevx) / 2d;
    double midy = (cury + prevy) / 2d;
    int i;
    final int size = shape.getNbPoints();
    final int interval = shape.getInterval();
    path.add(new SVGPathSegMoveto(curx, cury, false));
    if (size > interval) {
        prevx = curx;
        prevy = cury;
        curx = shape.getPtAt(interval).getX();
        cury = shape.getPtAt(interval).getY();
        midx = (curx + prevx) / 2d;
        midy = (cury + prevy) / 2d;
        path.add(new SVGPathSegLineto(midx, midy, false));
    }
    for (i = interval * 2; i < size; i += interval) {
        final double x1 = (midx + curx) / 2d;
        final double y1 = (midy + cury) / 2d;
        prevx = curx;
        prevy = cury;
        curx = shape.getPtAt(i).getX();
        cury = shape.getPtAt(i).getY();
        midx = (curx + prevx) / 2d;
        midy = (cury + prevy) / 2d;
        final double x2 = (prevx + midx) / 2d;
        final double y2 = (prevy + midy) / 2d;
        path.add(new SVGPathSegCurvetoCubic(midx, midy, x1, y1, x2, y2, false));
    }
    if (i - interval + 1 < size) {
        final double x1 = (midx + curx) / 2d;
        final double y1 = (midy + cury) / 2d;
        prevx = curx;
        prevy = cury;
        curx = shape.getPtAt(-1).getX();
        cury = shape.getPtAt(-1).getY();
        midx = (curx + prevx) / 2d;
        midy = (cury + prevy) / 2d;
        final double x2 = (prevx + midx) / 2d;
        final double y2 = (prevy + midy) / 2d;
        path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(-1).getX(), shape.getPtAt(-1).getY(), x1, y1, x2, y2, false));
    }
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 10 with SVGPathSegLineto

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

the class SVGPathParser method parserPathSeg.

private void parserPathSeg(final boolean isRelative) throws ParseException {
    while (!isEOC() && isNumber(false)) {
        final double x = parseNumber(false);
        skipWSPComma();
        final double y = parseNumber(false);
        skipWSPComma();
        handler.onPathSeg(new SVGPathSegLineto(x, y, isRelative));
    }
}
Also used : SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)

Aggregations

SVGPathSegLineto (net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto)12 SVGPathSegMoveto (net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto)7 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)5 SVGPathSegList (net.sf.latexdraw.parsers.svg.path.SVGPathSegList)4 SVGPathSegClosePath (net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath)3 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 ArcStyle (net.sf.latexdraw.models.interfaces.shape.ArcStyle)1 SVGDefsElement (net.sf.latexdraw.parsers.svg.SVGDefsElement)1 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)1 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)1 SVGPathElement (net.sf.latexdraw.parsers.svg.SVGPathElement)1 SVGPathParser (net.sf.latexdraw.parsers.svg.parsers.SVGPathParser)1 SVGPathSeg (net.sf.latexdraw.parsers.svg.path.SVGPathSeg)1 SVGPathSegArc (net.sf.latexdraw.parsers.svg.path.SVGPathSegArc)1 SVGPathSegCurvetoCubic (net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic)1 Before (org.junit.Before)1 Test (org.junit.Test)1