Search in sources :

Example 26 with SVGElement

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

the class SVGRectangular method initRectangle.

/**
 * Initialises the rectangle using an SVGGElement provided by a latexdraw SVG document.
 * @param elt The source element.
 * @throws IllegalArgumentException If the given element is null or not valid.
 */
protected void initRectangle(final SVGGElement elt, final boolean withTransformation) {
    final SVGElement elt2 = getLaTeXDrawElement(elt, null);
    if (elt == null || !(elt2 instanceof SVGRectElement)) {
        throw new IllegalArgumentException();
    }
    setSVGLatexdrawParameters(elt);
    setSVGRectParameters((SVGRectElement) elt2);
    setSVGShadowParameters(getLaTeXDrawElement(elt, LNamespace.XML_TYPE_SHADOW));
    setSVGDbleBordersParameters(getLaTeXDrawElement(elt, LNamespace.XML_TYPE_DBLE_BORDERS));
    if (withTransformation) {
        applyTransformations(elt);
    }
}
Also used : SVGRectElement(net.sf.latexdraw.parsers.svg.SVGRectElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement)

Example 27 with SVGElement

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

the class SVGRhombus method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        return null;
    }
    final IPoint tl = shape.getTopLeftPoint();
    final IPoint br = shape.getBottomRightPoint();
    final IPoint gc = shape.getGravityCentre();
    final IPoint p1 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, tl.getY());
    final IPoint p2 = ShapeFactory.INST.createPoint(br.getX(), (tl.getY() + br.getY()) / 2d);
    final IPoint 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.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)

Example 28 with SVGElement

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

the class SVGShape method setSVGArrow.

protected static void setSVGArrow(final IArrowableSingleShape shape, final SVGElement parent, final int arrowPos, final boolean isShadow, final SVGDocument doc, final SVGDefsElement defs) {
    final IArrow arrow = shape.getArrowAt(arrowPos);
    if (arrow.getArrowStyle() != ArrowStyle.NONE) {
        // NON-NLS
        final String arrowName = "arrow" + arrowPos + (isShadow ? "Shad-" : "-") + shape.hashCode();
        final SVGElement arrowSVG = new SVGArrow(arrow).toSVG(doc, isShadow);
        arrowSVG.setAttribute(SVGAttributes.SVG_ID, arrowName);
        defs.appendChild(arrowSVG);
        parent.setAttribute(arrowPos == 0 ? SVGAttributes.SVG_MARKER_START : SVGAttributes.SVG_MARKER_END, SVG_URL_TOKEN_BEGIN + arrowName + ')');
    }
}
Also used : SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IArrow(net.sf.latexdraw.models.interfaces.shape.IArrow)

Example 29 with SVGElement

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

the class SVGSquare 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 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() && !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, 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.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)

Example 30 with SVGElement

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

the class SVGDot method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        return null;
    }
    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.INSTANCE.createView(shape).ifPresent(vdot -> JFXToSVG.INSTANCE.shapesToElements(vdot.getChildren(), doc).forEach(elt -> root.appendChild(elt)));
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGPointsParser(net.sf.latexdraw.parsers.svg.parsers.SVGPointsParser) Point2D(java.awt.geom.Point2D) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) CSSColors(net.sf.latexdraw.parsers.svg.CSSColors) SVGDocument(net.sf.latexdraw.parsers.svg.SVGDocument) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) DotStyle(net.sf.latexdraw.models.interfaces.shape.DotStyle) List(java.util.List) Color(net.sf.latexdraw.models.interfaces.shape.Color) LNamespace(net.sf.latexdraw.util.LNamespace) JFXToSVG(net.sf.latexdraw.view.jfx.JFXToSVG) IDot(net.sf.latexdraw.models.interfaces.shape.IDot) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) BadaboomCollector(net.sf.latexdraw.badaboom.BadaboomCollector) SVGAttributes(net.sf.latexdraw.parsers.svg.SVGAttributes) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement)

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