Search in sources :

Example 1 with SVGMarkerElement

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

the class SVGArrow method toSVG.

/**
 * Return the SVG tree of the arrowhead or null if this arrowhead has no style.
 * @param document The document used to create elements.
 * @param isShadow True: this operation is call to create the SVG shadow of the shape.
 * @return The SVG tree of the arrowhead or null
 */
SVGElement toSVG(@NotNull final SVGDocument document, final boolean isShadow) {
    if (!arrow.hasStyle()) {
        return null;
    }
    final Line line = arrow.getArrowLine();
    final double lineAngle = (-line.getLineAngle() + Math.PI * 2d) % (Math.PI * 2d);
    currentDoc = document;
    currentMarker = new SVGMarkerElement(document);
    currentMarker.setAttribute(SVGAttributes.SVG_OVERFLOW, SVGAttributes.SVG_VALUE_VISIBLE);
    currentMarker.setAttribute(SVGAttributes.SVG_MARKER_UNITS, SVGAttributes.SVG_UNITS_VALUE_USR);
    if (arrow.getArrowStyle() != ArrowStyle.NONE && !MathUtils.INST.equalsDouble(lineAngle, 0d)) {
        currentMarker.setAttribute(SVGAttributes.SVG_ORIENT, MathUtils.INST.format.format(Math.toDegrees(lineAngle)));
    } else {
        currentMarker.setAttribute(SVGAttributes.SVG_ORIENT, SVGAttributes.SVG_VALUE_AUTO);
    }
    updatePath(isShadow);
    if (currentPath != null) {
        createPathElement();
        currentPathElt.setAttribute(SVGAttributes.SVG_D, currentPath.toString());
        currentPathElt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ARROW_SIZE_NUM, MathUtils.INST.format.format(arrow.getArrowSizeNum()));
        currentPathElt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ARROW_TBAR_SIZE_NUM, MathUtils.INST.format.format(arrow.getTBarSizeNum()));
    }
    return currentMarker;
}
Also used : Line(net.sf.latexdraw.model.api.shape.Line) SVGMarkerElement(net.sf.latexdraw.parser.svg.SVGMarkerElement)

Aggregations

Line (net.sf.latexdraw.model.api.shape.Line)1 SVGMarkerElement (net.sf.latexdraw.parser.svg.SVGMarkerElement)1