Search in sources :

Example 1 with SVGDefsElement

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

the class SVGCircleArc method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (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 Point start = shape.getStartPoint();
    final Point 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 Point 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);
        parameteriseSVGArrow(shape, shad, 0, true, doc, defs);
        parameteriseSVGArrow(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));
    parameteriseSVGArrow(shape, elt, 0, false, doc, defs);
    parameteriseSVGArrow(shape, elt, 1, false, doc, defs);
    if (shape.isShowPts()) {
        root.appendChild(getShowPointsElement(doc));
    }
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathElement(net.sf.latexdraw.parser.svg.SVGPathElement) 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) SVGPathSegArc(net.sf.latexdraw.parser.svg.path.SVGPathSegArc) ArcStyle(net.sf.latexdraw.model.api.shape.ArcStyle) SVGDefsElement(net.sf.latexdraw.parser.svg.SVGDefsElement)

Example 2 with SVGDefsElement

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

the class TestSVGBase method setUp.

@BeforeEach
void setUp(final SVGShapesFactory svgfac) {
    factory = svgfac;
    doc = new SVGDocument();
    final SVGSVGElement root = doc.getFirstChild();
    root.setAttribute("xmlns:" + LNamespace.LATEXDRAW_NAMESPACE, LNamespace.LATEXDRAW_NAMESPACE_URI);
    root.appendChild(new SVGDefsElement(doc));
    root.setAttribute(SVGAttributes.SVG_VERSION, "1.1");
    root.setAttribute(SVGAttributes.SVG_BASE_PROFILE, "full");
}
Also used : SVGDefsElement(net.sf.latexdraw.parser.svg.SVGDefsElement) SVGDocument(net.sf.latexdraw.parser.svg.SVGDocument) SVGSVGElement(net.sf.latexdraw.parser.svg.SVGSVGElement) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with SVGDefsElement

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

the class SVGBezierCurve method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (doc.getFirstChild().getDefs() == null) {
        return null;
    }
    final SVGDefsElement defs = doc.getFirstChild().getDefs();
    final SVGElement root = new SVGGElement(doc);
    SVGElement elt;
    final String path = getPathSegList().toString();
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_BEZIER_CURVE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    if (shape.hasShadow()) {
        final SVGElement shad = new SVGPathElement(doc);
        shad.setAttribute(SVGAttributes.SVG_D, path);
        setSVGShadowAttributes(shad, false);
        root.appendChild(shad);
        if (shape.isOpened()) {
            parameteriseSVGArrow(shape, shad, 0, true, doc, defs);
            parameteriseSVGArrow(shape, shad, 1, true, doc, defs);
        }
    }
    if (shape.hasShadow() && !PSTricksConstants.LINE_NONE_STYLE.equals(shape.getLineStyle().getLatexToken()) && shape.isFilled()) {
        // The background of the borders must be filled is there is a shadow.
        elt = new SVGPathElement(doc);
        elt.setAttribute(SVGAttributes.SVG_D, path);
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGPathElement(doc);
    elt.setAttribute(SVGAttributes.SVG_D, path);
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        final SVGElement dblBord = new SVGPathElement(doc);
        dblBord.setAttribute(SVGAttributes.SVG_D, path);
        setSVGDoubleBordersAttributes(dblBord);
        root.appendChild(dblBord);
    }
    setSVGAttributes(doc, elt, false);
    elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));
    if (shape.isOpened()) {
        parameteriseSVGArrow(shape, elt, 0, false, doc, defs);
        parameteriseSVGArrow(shape, elt, 1, false, doc, defs);
    }
    if (shape.isShowPts()) {
        root.appendChild(getShowPointsElement(doc));
    }
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGPathElement(net.sf.latexdraw.parser.svg.SVGPathElement) SVGDefsElement(net.sf.latexdraw.parser.svg.SVGDefsElement)

Example 4 with SVGDefsElement

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

the class SVGPolylines method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    final SVGElement root = new SVGGElement(doc);
    final SVGDefsElement defs = doc.getFirstChild().getDefs();
    final StringBuilder points = new StringBuilder();
    final List<Point> pts = shape.getPoints();
    SVGPolyLineElement elt;
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_JOINED_LINES);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    for (final Point pt : pts) {
        points.append(pt.getX()).append(',').append(pt.getY()).append(' ');
    }
    final String pointsStr = points.toString();
    if (shape.hasShadow()) {
        final SVGPolyLineElement shad = new SVGPolyLineElement(doc);
        shad.setPoints(pointsStr);
        setSVGShadowAttributes(shad, false);
        root.appendChild(shad);
        parameteriseSVGArrow(shape, shad, 0, true, doc, defs);
        parameteriseSVGArrow(shape, shad, 1, true, doc, defs);
    }
    if (shape.hasShadow() && !PSTricksConstants.LINE_NONE_STYLE.equals(shape.getLineStyle().getLatexToken()) && shape.isFilled()) {
        // The background of the borders must be filled is there is a shadow.
        elt = new SVGPolyLineElement(doc);
        elt.setPoints(pointsStr);
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGPolyLineElement(doc);
    elt.setPoints(pointsStr);
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        final SVGPolyLineElement dblBord = new SVGPolyLineElement(doc);
        dblBord.setPoints(pointsStr);
        setSVGDoubleBordersAttributes(dblBord);
        root.appendChild(dblBord);
    }
    setSVGAttributes(doc, elt, false);
    elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));
    parameteriseSVGArrow(shape, elt, 0, false, doc, defs);
    parameteriseSVGArrow(shape, elt, shape.getNbArrows() - 1, false, doc, defs);
    return root;
}
Also used : SVGPolyLineElement(net.sf.latexdraw.parser.svg.SVGPolyLineElement) SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGDefsElement(net.sf.latexdraw.parser.svg.SVGDefsElement) Point(net.sf.latexdraw.model.api.shape.Point)

Aggregations

SVGDefsElement (net.sf.latexdraw.parser.svg.SVGDefsElement)4 SVGElement (net.sf.latexdraw.parser.svg.SVGElement)3 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)3 Point (net.sf.latexdraw.model.api.shape.Point)2 SVGPathElement (net.sf.latexdraw.parser.svg.SVGPathElement)2 ArcStyle (net.sf.latexdraw.model.api.shape.ArcStyle)1 SVGDocument (net.sf.latexdraw.parser.svg.SVGDocument)1 SVGPolyLineElement (net.sf.latexdraw.parser.svg.SVGPolyLineElement)1 SVGSVGElement (net.sf.latexdraw.parser.svg.SVGSVGElement)1 SVGPathSegArc (net.sf.latexdraw.parser.svg.path.SVGPathSegArc)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 SVGPathSegMoveto (net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1