Search in sources :

Example 1 with SVGGElement

use of net.sf.latexdraw.parser.svg.SVGGElement 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 SVGGElement

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

the class SVGGroup method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (shape.isEmpty()) {
        return null;
    }
    final SVGElement root = new SVGGElement(doc);
    final List<Shape> shapes = shape.getShapes();
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GROUP);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    shapes.stream().map(f -> shapeProducer.createSVGElement(f, doc)).forEach(newChild -> root.appendChild(newChild));
    return root;
}
Also used : Group(net.sf.latexdraw.model.api.shape.Group) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) List(java.util.List) Shape(net.sf.latexdraw.model.api.shape.Shape) NodeList(org.w3c.dom.NodeList) LNamespace(net.sf.latexdraw.util.LNamespace) SVGDocument(net.sf.latexdraw.parser.svg.SVGDocument) SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGAttributes(net.sf.latexdraw.parser.svg.SVGAttributes) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) NotNull(org.jetbrains.annotations.NotNull) SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) Shape(net.sf.latexdraw.model.api.shape.Shape) SVGElement(net.sf.latexdraw.parser.svg.SVGElement)

Example 3 with SVGGElement

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

the class SVGPicture method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    final SVGElement root = new SVGGElement(doc);
    final SVGElement img;
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_PICTURE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    img = new SVGImageElement(doc, shape.getPathSource());
    img.setAttribute(SVGAttributes.SVG_X, String.valueOf(shape.getPosition().getX()));
    img.setAttribute(SVGAttributes.SVG_Y, String.valueOf(shape.getPosition().getY()));
    img.setAttribute(SVGAttributes.SVG_HEIGHT, String.valueOf(shape.getImage().getHeight()));
    img.setAttribute(SVGAttributes.SVG_WIDTH, String.valueOf(shape.getImage().getWidth()));
    setSVGRotationAttribute(root);
    root.appendChild(img);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGImageElement(net.sf.latexdraw.parser.svg.SVGImageElement)

Example 4 with SVGGElement

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

the class SVGPolygon method toSVG.

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

Example 5 with SVGGElement

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

the class SVGRectangle method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument document) {
    if (document.getFirstChild().getDefs() == null) {
        throw new IllegalArgumentException();
    }
    final double gap = getPositionGap();
    final Point tl = shape.getTopLeftPoint();
    final Point br = shape.getBottomRightPoint();
    SVGElement elt;
    final SVGElement root = new SVGGElement(document);
    final double width = Math.max(1d, br.getX() - tl.getX() + gap);
    final double height = Math.max(1d, br.getY() - tl.getY() + gap);
    final double x = tl.getX() - gap / 2d;
    final double y = tl.getY() - gap / 2d;
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_RECT);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    setShadowSVGRect(root, x, y, width, height, document);
    if (shape.hasShadow() && !PSTricksConstants.LINE_NONE_STYLE.equals(shape.getLineStyle().getLatexToken())) {
        // The background of the borders must be filled is there is a shadow.
        elt = new SVGRectElement(x, y, width, height, document);
        setSVGBorderBackground(elt, root);
        setSVGRoundCorner(elt);
    }
    elt = new SVGRectElement(x, y, width, height, document);
    root.appendChild(elt);
    setSVGAttributes(document, elt, true);
    setSVGRoundCorner(elt);
    setDbleBordSVGRect(root, x, y, width, height, document);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGRectElement(net.sf.latexdraw.parser.svg.SVGRectElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) Point(net.sf.latexdraw.model.api.shape.Point)

Aggregations

SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)22 SVGElement (net.sf.latexdraw.parser.svg.SVGElement)20 Point (net.sf.latexdraw.model.api.shape.Point)10 List (java.util.List)3 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)3 SVGAttributes (net.sf.latexdraw.parser.svg.SVGAttributes)3 SVGCircleElement (net.sf.latexdraw.parser.svg.SVGCircleElement)3 SVGDefsElement (net.sf.latexdraw.parser.svg.SVGDefsElement)3 SVGDocument (net.sf.latexdraw.parser.svg.SVGDocument)3 SVGPolygonElement (net.sf.latexdraw.parser.svg.SVGPolygonElement)3 LNamespace (net.sf.latexdraw.util.LNamespace)3 NotNull (org.jetbrains.annotations.NotNull)3 Point2D (java.awt.geom.Point2D)2 Color (net.sf.latexdraw.model.api.shape.Color)2 SVGLineElement (net.sf.latexdraw.parser.svg.SVGLineElement)2 SVGParserUtils (net.sf.latexdraw.parser.svg.SVGParserUtils)2 SVGPathElement (net.sf.latexdraw.parser.svg.SVGPathElement)2 SVGRectElement (net.sf.latexdraw.parser.svg.SVGRectElement)2 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1