Search in sources :

Example 21 with SVGElement

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

the class SVGPicture method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null)
        return null;
    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.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGImageElement(net.sf.latexdraw.parsers.svg.SVGImageElement)

Example 22 with SVGElement

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

the class SVGPlot method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null || doc.getFirstChild().getDefs() == null) {
        return null;
    }
    final SVGElement root = new SVGGElement(doc);
    if (shape.hasShadow()) {
        final SVGGElement shad = new SVGGElement(doc);
        toSVGShape(doc, shad);
        setSVGShadowAttributes(shad, false);
        root.appendChild(shad);
    }
    if (shape.hasDbleBord()) {
        final SVGGElement dble = new SVGGElement(doc);
        toSVGShape(doc, dble);
        setSVGDoubleBordersAttributes(dble);
        root.appendChild(dble);
    }
    toSVGShape(doc, root);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, XML_TYPE_PLOT);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_POLAR, Boolean.toString(shape.isPolar()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_EQ, shape.getPlotEquation());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_STYLE, shape.getPlotStyle().getPSTToken());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_MIN, Double.toString(shape.getPlotMinX()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_MAX, Double.toString(shape.getPlotMaxX()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_NB_POINTS, Integer.toString(shape.getNbPlottedPoints()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_XSCALE, Double.toString(shape.getXScale()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_YSCALE, Double.toString(shape.getYScale()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POSITION_X, Double.toString(shape.getX()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POSITION_Y, Double.toString(shape.getY()));
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    setSVGAttributes(doc, root, true);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement)

Example 23 with SVGElement

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

the class SVGAxes method createArrows.

private void createArrows(final SVGElement elt, final SVGDocument document) {
    if (shape.getAxesStyle().supportsArrows() && shape.getNbArrows() == 4) {
        final double posX = shape.getPosition().getX();
        final double posY = shape.getPosition().getY();
        final IArrow arr0 = shape.getArrowAt(1);
        final IArrow arr1 = shape.getArrowAt(3);
        final double arr0Reduction = arr0.getArrowStyle().needsLineReduction() ? arr0.getArrowShapedWidth() : 0.;
        final double arr1Reduction = arr1.getArrowStyle().needsLineReduction() ? arr1.getArrowShapedWidth() : 0.;
        final IPolyline xLine = ShapeFactory.INST.createPolyline(Arrays.asList(ShapeFactory.INST.createPoint(posX + shape.getGridStartX() * IShape.PPC + arr0Reduction, posY), ShapeFactory.INST.createPoint(posX + shape.getGridEndX() * IShape.PPC - arr1Reduction, posY)));
        final IPolyline yLine = ShapeFactory.INST.createPolyline(Arrays.asList(ShapeFactory.INST.createPoint(posX, posY - shape.getGridStartY() * IShape.PPC - arr0Reduction), ShapeFactory.INST.createPoint(posX, posY - shape.getGridEndY() * IShape.PPC + arr1Reduction)));
        xLine.getArrowAt(0).copy(arr0);
        xLine.getArrowAt(1).copy(arr1);
        yLine.getArrowAt(0).copy(shape.getArrowAt(0));
        yLine.getArrowAt(1).copy(shape.getArrowAt(2));
        final SVGElement eltX = new SVGPolylines(xLine).toSVG(document);
        final SVGElement eltY = new SVGPolylines(yLine).toSVG(document);
        final String transform = "translate(" + MathUtils.INST.format.format(-shape.getPosition().getX()) + ',' + MathUtils.INST.format.format(-shape.getPosition().getY()) + ')';
        eltX.setAttribute(SVGAttributes.SVG_TRANSFORM, transform);
        eltY.setAttribute(SVGAttributes.SVG_TRANSFORM, transform);
        elt.appendChild(eltX);
        elt.appendChild(eltY);
    }
}
Also used : SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) IArrow(net.sf.latexdraw.models.interfaces.shape.IArrow)

Example 24 with SVGElement

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

the class SVGBezierCurve method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null || doc.getFirstChild().getDefs() == null) {
        return null;
    }
    final SVGDefsElement defs = doc.getFirstChild().getDefs();
    final SVGElement root = new SVGGElement(doc);
    SVGElement elt;
    final String path = getPathSegList().toString();
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_BEZIER_CURVE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    if (shape.hasShadow()) {
        final SVGElement shad = new SVGPathElement(doc);
        shad.setAttribute(SVGAttributes.SVG_D, path);
        setSVGShadowAttributes(shad, false);
        root.appendChild(shad);
        if (shape.isOpened()) {
            setSVGArrow(shape, shad, 0, true, doc, defs);
            setSVGArrow(shape, shad, 1, true, doc, defs);
        }
    }
    if (shape.hasShadow() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE) && shape.isFilled()) {
        // The background of the borders must be filled is there is a shadow.
        elt = new SVGPathElement(doc);
        elt.setAttribute(SVGAttributes.SVG_D, path);
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGPathElement(doc);
    elt.setAttribute(SVGAttributes.SVG_D, path);
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        final SVGElement dblBord = new SVGPathElement(doc);
        dblBord.setAttribute(SVGAttributes.SVG_D, path);
        setSVGDoubleBordersAttributes(dblBord);
        root.appendChild(dblBord);
    }
    setSVGAttributes(doc, elt, false);
    elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));
    if (shape.isOpened()) {
        setSVGArrow(shape, elt, 0, false, doc, defs);
        setSVGArrow(shape, elt, 1, false, doc, defs);
    }
    if (shape.isShowPts()) {
        root.appendChild(getShowPointsElement(doc));
    }
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) SVGDefsElement(net.sf.latexdraw.parsers.svg.SVGDefsElement)

Example 25 with SVGElement

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

the class SVGPolylines method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        return null;
    }
    final SVGElement root = new SVGGElement(doc);
    final SVGDefsElement defs = doc.getFirstChild().getDefs();
    final StringBuilder points = new StringBuilder();
    final List<IPoint> 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 IPoint 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);
        try {
            shad.setPoints(pointsStr);
        } catch (final ParseException ex) {
            BadaboomCollector.INSTANCE.add(ex);
        }
        setSVGShadowAttributes(shad, false);
        root.appendChild(shad);
        setSVGArrow(shape, shad, 0, true, doc, defs);
        setSVGArrow(shape, shad, 1, true, doc, defs);
    }
    if (shape.hasShadow() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE) && shape.isFilled()) {
        // The background of the borders must be filled is there is a shadow.
        elt = new SVGPolyLineElement(doc);
        try {
            elt.setPoints(pointsStr);
        } catch (final ParseException ex) {
            BadaboomCollector.INSTANCE.add(ex);
        }
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGPolyLineElement(doc);
    try {
        elt.setPoints(pointsStr);
    } catch (final ParseException ex) {
        BadaboomCollector.INSTANCE.add(ex);
    }
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        final SVGPolyLineElement dblBord = new SVGPolyLineElement(doc);
        try {
            dblBord.setPoints(pointsStr);
        } catch (final ParseException ex) {
            BadaboomCollector.INSTANCE.add(ex);
        }
        setSVGDoubleBordersAttributes(dblBord);
        root.appendChild(dblBord);
    }
    setSVGAttributes(doc, elt, false);
    elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));
    setSVGArrow(shape, elt, 0, false, doc, defs);
    setSVGArrow(shape, elt, shape.getNbArrows() - 1, false, doc, defs);
    return root;
}
Also used : SVGPolyLineElement(net.sf.latexdraw.parsers.svg.SVGPolyLineElement) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGDefsElement(net.sf.latexdraw.parsers.svg.SVGDefsElement) ParseException(java.text.ParseException)

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