Search in sources :

Example 6 with SVGElement

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

the class SVGAxes method setAxesStyleFromSVG.

private void setAxesStyleFromSVG(final SVGGElement elt) {
    /* Looking for the two axe in order to get the position of the axes. */
    final SVGNodeList nl = elt.getChildren(SVGElements.SVG_G);
    int i = 0;
    final int size = nl.getLength();
    SVGGElement l1 = null;
    SVGGElement l2 = null;
    SVGElement element;
    while ((l1 == null || l2 == null) && i < size) {
        element = nl.item(i);
        if (element instanceof SVGGElement) {
            if (l1 == null) {
                l1 = (SVGGElement) element;
            } else {
                l2 = (SVGGElement) element;
            }
        }
        i++;
    }
    if (l1 != null && l2 != null) {
        try {
            final IPolyline la = new SVGPolylines(l1, false).shape;
            final IPolyline lb = new SVGPolylines(l2, false).shape;
            // now, a translation is used.
            if (elt.getTransform().stream().noneMatch(tr -> tr.isTranslation())) {
                shape.setPosition(ShapeFactory.INST.createPoint(lb.getPtAt(0).getX(), la.getPtAt(0).getY()));
            }
            // End of legacy
            shape.setLineStyle(la.getLineStyle());
            shape.getArrowAt(1).setArrowStyle(la.getArrowAt(0).getArrowStyle());
            shape.getArrowAt(3).setArrowStyle(la.getArrowAt(1).getArrowStyle());
            shape.getArrowAt(0).setArrowStyle(lb.getArrowAt(0).getArrowStyle());
            shape.getArrowAt(2).setArrowStyle(lb.getArrowAt(1).getArrowStyle());
        } catch (final IllegalArgumentException ex) {
            BadaboomCollector.INSTANCE.add(ex);
        }
    }
}
Also used : SVGNodeList(net.sf.latexdraw.parsers.svg.SVGNodeList) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 7 with SVGElement

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

the class SVGPolygon method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        throw new IllegalArgumentException();
    }
    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 IPoint 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);
        try {
            shad.setPoints(points);
        } catch (final ParseException ex) {
            BadaboomCollector.INSTANCE.add(ex);
        }
        setSVGShadowAttributes(shad, true);
        root.appendChild(shad);
    }
    if (shape.hasShadow() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE)) {
        // The background of the borders must be filled is there is a shadow.
        final SVGPolygonElement elt = new SVGPolygonElement(doc);
        try {
            elt.setPoints(points);
        } catch (final ParseException ex) {
            BadaboomCollector.INSTANCE.add(ex);
        }
        setSVGBorderBackground(elt, root);
    }
    final SVGPolygonElement elt = new SVGPolygonElement(doc);
    try {
        elt.setPoints(points);
    } catch (final ParseException ex) {
        BadaboomCollector.INSTANCE.add(ex);
    }
    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);
        try {
            dblBord.setPoints(points);
        } catch (final ParseException ex) {
            BadaboomCollector.INSTANCE.add(ex);
        }
        setSVGDoubleBordersAttributes(dblBord);
        root.appendChild(dblBord);
    }
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPolygonElement(net.sf.latexdraw.parsers.svg.SVGPolygonElement) ParseException(java.text.ParseException)

Example 8 with SVGElement

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

the class SVGPolygonBased method setShadowPolygon.

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() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE)) {
        // 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.parsers.svg.SVGElement) SVGPolygonElement(net.sf.latexdraw.parsers.svg.SVGPolygonElement)

Example 9 with SVGElement

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

the class SVGPolygonBased method setDbleBorderPolygon.

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.parsers.svg.SVGElement) SVGPolygonElement(net.sf.latexdraw.parsers.svg.SVGPolygonElement)

Example 10 with SVGElement

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

the class SVGRectangle method toSVG.

@Override
public SVGElement toSVG(final SVGDocument document) {
    if (document == null || document.getFirstChild().getDefs() == null) {
        throw new IllegalArgumentException();
    }
    final double gap = getPositionGap();
    final IPoint tl = shape.getTopLeftPoint();
    final IPoint 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() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE)) {
        // 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.parsers.svg.SVGGElement) SVGRectElement(net.sf.latexdraw.parsers.svg.SVGRectElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Aggregations

SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)39 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)24 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)15 SVGPolygonElement (net.sf.latexdraw.parsers.svg.SVGPolygonElement)5 Test (org.junit.Test)5 SVGDefsElement (net.sf.latexdraw.parsers.svg.SVGDefsElement)4 SVGPathElement (net.sf.latexdraw.parsers.svg.SVGPathElement)4 SVGCircleElement (net.sf.latexdraw.parsers.svg.SVGCircleElement)3 SVGRectElement (net.sf.latexdraw.parsers.svg.SVGRectElement)3 Point2D (java.awt.geom.Point2D)2 ParseException (java.text.ParseException)2 List (java.util.List)2 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)2 Color (net.sf.latexdraw.models.interfaces.shape.Color)2 IArrow (net.sf.latexdraw.models.interfaces.shape.IArrow)2 IPolyline (net.sf.latexdraw.models.interfaces.shape.IPolyline)2 SVGAttr (net.sf.latexdraw.parsers.svg.SVGAttr)2 SVGAttributes (net.sf.latexdraw.parsers.svg.SVGAttributes)2 SVGDocument (net.sf.latexdraw.parsers.svg.SVGDocument)2 SVGLineElement (net.sf.latexdraw.parsers.svg.SVGLineElement)2