Search in sources :

Example 1 with SVGPolygonElement

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

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

the class SVGPolygonBased method setDbleBorderPolygon.

final void setDbleBorderPolygon(final SVGDocument doc, final SVGElement root, final String points) {
    if (shape.hasDbleBord()) {
        final SVGElement dblBord = new SVGPolygonElement(doc);
        dblBord.setAttribute(SVGAttributes.SVG_POINTS, points);
        setSVGDoubleBordersAttributes(dblBord);
        root.appendChild(dblBord);
    }
}
Also used : SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGPolygonElement(net.sf.latexdraw.parser.svg.SVGPolygonElement)

Example 3 with SVGPolygonElement

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

the class SVGPolygonBased method setShadowPolygon.

final void setShadowPolygon(final SVGDocument doc, final SVGElement root, final String points) {
    if (shape.hasShadow()) {
        final SVGElement elt = new SVGPolygonElement(doc);
        elt.setAttribute(SVGAttributes.SVG_POINTS, points);
        setSVGShadowAttributes(elt, true);
        root.appendChild(elt);
    }
    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 SVGElement elt = new SVGPolygonElement(doc);
        elt.setAttribute(SVGAttributes.SVG_POINTS, points);
        setSVGBorderBackground(elt, root);
    }
}
Also used : SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGPolygonElement(net.sf.latexdraw.parser.svg.SVGPolygonElement)

Example 4 with SVGPolygonElement

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

the class SVGRhombus method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    final Point tl = shape.getTopLeftPoint();
    final Point br = shape.getBottomRightPoint();
    final Point gc = shape.getGravityCentre();
    final Point p1 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, tl.getY());
    final Point p2 = ShapeFactory.INST.createPoint(br.getX(), (tl.getY() + br.getY()) / 2d);
    final Point p3 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, br.getY());
    final SVGElement root = new SVGGElement(doc);
    final double gap = getPositionGap() / 2d;
    final double cornerGap1 = MathUtils.INST.getCornerGap(gc, p1, p2, gap);
    double cornerGap2 = MathUtils.INST.getCornerGap(gc, p2, p3, gap);
    if (p2.getX() < p3.getX()) {
        cornerGap2 *= -1d;
    }
    final String points = String.valueOf(p1.getX()) + ',' + (p1.getY() - cornerGap1) + ' ' + (p2.getX() + cornerGap2) + ',' + p2.getY() + ' ' + p3.getX() + ',' + (p3.getY() + cornerGap1) + ' ' + (tl.getX() - cornerGap2) + ',' + p2.getY();
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_RHOMBUS);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    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, String.valueOf(tl.getX()) + ' ' + tl.getY() + ' ' + br.getX() + ' ' + tl.getY() + ' ' + tl.getX() + ' ' + br.getY() + ' ' + br.getX() + ' ' + br.getY());
    setDbleBorderPolygon(doc, root, points);
    setSVGAttributes(doc, elt, true);
    setSVGRotationAttribute(root);
    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 SVGPolygonElement

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

Aggregations

SVGElement (net.sf.latexdraw.parser.svg.SVGElement)5 SVGPolygonElement (net.sf.latexdraw.parser.svg.SVGPolygonElement)5 Point (net.sf.latexdraw.model.api.shape.Point)3 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)3 Point2D (java.awt.geom.Point2D)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 MathUtils (net.sf.latexdraw.model.MathUtils)1 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)1 Triangle (net.sf.latexdraw.model.api.shape.Triangle)1 SVGAttributes (net.sf.latexdraw.parser.svg.SVGAttributes)1 SVGDocument (net.sf.latexdraw.parser.svg.SVGDocument)1 SVGParserUtils (net.sf.latexdraw.parser.svg.SVGParserUtils)1 LNamespace (net.sf.latexdraw.util.LNamespace)1 NotNull (org.jetbrains.annotations.NotNull)1