Search in sources :

Example 21 with SVGGElement

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

the class SVGDot method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    final SVGElement root = new SVGGElement(doc);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_DOT);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_SIZE, String.valueOf(shape.getDiametre()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_DOT_SHAPE, shape.getDotStyle().getPSTToken());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POSITION, shape.getPosition().getX() + " " + shape.getPosition().getY());
    viewFactory.createView(shape).ifPresent(vdot -> JFXToSVG.INSTANCE.shapesToElements(vdot.getChildren(), doc).forEach(elt -> root.appendChild(elt)));
    setSVGRotationAttribute(root);
    return root;
}
Also used : Point2D(java.awt.geom.Point2D) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) Dot(net.sf.latexdraw.model.api.shape.Dot) List(java.util.List) SVGParserUtils(net.sf.latexdraw.parser.svg.SVGParserUtils) LNamespace(net.sf.latexdraw.util.LNamespace) Color(net.sf.latexdraw.model.api.shape.Color) JFXToSVG(net.sf.latexdraw.view.jfx.JFXToSVG) SVGDocument(net.sf.latexdraw.parser.svg.SVGDocument) DotStyle(net.sf.latexdraw.model.api.shape.DotStyle) CSSColors(net.sf.latexdraw.parser.svg.CSSColors) 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) SVGElement(net.sf.latexdraw.parser.svg.SVGElement)

Example 22 with SVGGElement

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

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