Search in sources :

Example 21 with SVGElement

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

the class SVGText method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    final SVGElement root = new SVGGElement(doc);
    final String ltdPref = LNamespace.LATEXDRAW_NAMESPACE + ':';
    final Element txt = new SVGTextElement(doc);
    root.setAttribute(ltdPref + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TEXT);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    root.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(shape.getLineColour(), true));
    root.setAttribute(ltdPref + LNamespace.XML_POSITION, shape.getTextPosition().getLatexToken());
    txt.setAttribute(SVGAttributes.SVG_X, String.valueOf(shape.getX()));
    txt.setAttribute(SVGAttributes.SVG_Y, String.valueOf(shape.getY()));
    txt.appendChild(doc.createTextNode(shape.getText()));
    root.appendChild(txt);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parser.svg.SVGTextElement) SVGTextElement(net.sf.latexdraw.parser.svg.SVGTextElement) SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) Element(org.w3c.dom.Element) SVGElement(net.sf.latexdraw.parser.svg.SVGElement)

Example 22 with SVGElement

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

the class SVGSquare method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument document) {
    if (document.getFirstChild().getDefs() == null) {
        return null;
    }
    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 x = tl.getX() - gap / 2d;
    final double y = tl.getY() - gap / 2d;
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_SQUARE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    setShadowSVGRect(root, x, y, width, width, 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, width, document);
        setSVGBorderBackground(elt, root);
        setSVGRoundCorner(elt);
    }
    elt = new SVGRectElement(x, y, width, width, document);
    root.appendChild(elt);
    setSVGAttributes(document, elt, true);
    setSVGRoundCorner(elt);
    setDbleBordSVGRect(root, x, y, width, width, 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)

Example 23 with SVGElement

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

the class SVGTriangle method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (doc.getFirstChild().getDefs() == null) {
        return null;
    }
    final SVGElement root = new SVGGElement(doc);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TRIANGLE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    final double gap = getPositionGap() / 2d;
    final Point pt1 = shape.getTopLeftPoint();
    final Point pt2 = shape.getBottomRightPoint();
    final Point p1 = ShapeFactory.INST.createPoint((pt1.getX() + pt2.getX()) / 2d, pt1.getY());
    final Point p2 = ShapeFactory.INST.createPoint(pt2.getX(), pt2.getY());
    final Point p3 = ShapeFactory.INST.createPoint(pt1.getX(), pt2.getY());
    final double p1x = p1.getX();
    final double p1y = p1.getY();
    final double p2x = p2.getX();
    final double p2y = p2.getY();
    final double p3x = p3.getX();
    double cornerGap1 = MathUtils.INST.getCornerGap(ShapeFactory.INST.createPoint(p1x, p2y), p1, p2, gap);
    double cornerGap2 = MathUtils.INST.getCornerGap(shape.getGravityCentre(), p2, p3, gap);
    if (p2x > p3x) {
        cornerGap2 *= -1d;
    }
    if (p1y > p2y) {
        cornerGap1 *= -1d;
    }
    final double value = p2y + (p1y < p2y ? gap : -gap);
    final String points = p1x + "," + (p1y - cornerGap1) + " " + (p2x - cornerGap2) + "," + value + " " + (p3x + cornerGap2) + "," + value;
    final String ltdPoints = shape.getPoints().stream().flatMap(pt -> Stream.of(String.valueOf(pt.getX()), String.valueOf(pt.getY()))).collect(Collectors.joining(" "));
    setShadowPolygon(doc, root, points);
    final SVGElement elt = new SVGPolygonElement(doc);
    elt.setAttribute(SVGAttributes.SVG_POINTS, points);
    root.appendChild(elt);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POINTS, ltdPoints);
    setDbleBorderPolygon(doc, root, points);
    setSVGAttributes(doc, elt, true);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGPolygonElement(net.sf.latexdraw.parser.svg.SVGPolygonElement) Point2D(java.awt.geom.Point2D) SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) Point(net.sf.latexdraw.model.api.shape.Point) Collectors(java.util.stream.Collectors) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) List(java.util.List) Stream(java.util.stream.Stream) SVGParserUtils(net.sf.latexdraw.parser.svg.SVGParserUtils) LNamespace(net.sf.latexdraw.util.LNamespace) SVGDocument(net.sf.latexdraw.parser.svg.SVGDocument) MathUtils(net.sf.latexdraw.model.MathUtils) SVGAttributes(net.sf.latexdraw.parser.svg.SVGAttributes) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) NotNull(org.jetbrains.annotations.NotNull) Triangle(net.sf.latexdraw.model.api.shape.Triangle) 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 24 with SVGElement

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

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

SVGElement (net.sf.latexdraw.parser.svg.SVGElement)27 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)20 Point (net.sf.latexdraw.model.api.shape.Point)13 SVGPolygonElement (net.sf.latexdraw.parser.svg.SVGPolygonElement)5 SVGTextElement (net.sf.latexdraw.parser.svg.SVGTextElement)4 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 SVGRectElement (net.sf.latexdraw.parser.svg.SVGRectElement)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 Collectors (java.util.stream.Collectors)1