Search in sources :

Example 1 with SVGGElement

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

the class JFXToSVG method groupToSVGGElement.

public SVGGElement groupToSVGGElement(final Group group, final SVGDocument doc) {
    final SVGGElement g = new SVGGElement(doc);
    shapesToElements(group.getChildren(), doc).forEach(elt -> g.appendChild(elt));
    return g;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement)

Example 2 with SVGGElement

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

the class SVGAxes method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        return null;
    }
    currentDoc = doc;
    currentPath = new SVGPathSegList();
    currentTicks = new SVGGElement(doc);
    final SVGElement root = new SVGGElement(doc);
    final String pref = LNamespace.LATEXDRAW_NAMESPACE + ':';
    final SVGPathElement path = new SVGPathElement(doc);
    setSVGAttributes(doc, root, false);
    root.setAttribute(SVGAttributes.SVG_TRANSFORM, "translate(" + MathUtils.INST.format.format(shape.getPosition().getX()) + ',' + MathUtils.INST.format.format(shape.getPosition().getY()) + ')');
    root.setAttribute(pref + LNamespace.XML_STYLE, shape.getAxesStyle().toString());
    root.setAttribute(pref + LNamespace.XML_GRID_START, shape.getGridStartX() + " " + shape.getGridStartY());
    root.setAttribute(pref + LNamespace.XML_GRID_END, shape.getGridEndX() + " " + shape.getGridEndY());
    root.setAttribute(pref + LNamespace.XML_GRID_ORIGIN, shape.getOriginX() + " " + shape.getOriginY());
    root.setAttribute(pref + LNamespace.XML_AXE_INCREMENT, shape.getIncrementX() + " " + shape.getIncrementY());
    root.setAttribute(pref + LNamespace.XML_AXE_DIST_LABELS, shape.getDistLabelsX() + " " + shape.getDistLabelsY());
    root.setAttribute(pref + LNamespace.XML_AXE_TICKS_SIZE, String.valueOf(shape.getTicksSize()));
    root.setAttribute(pref + LNamespace.XML_AXE_SHOW_ORIGIN, String.valueOf(shape.isShowOrigin()));
    root.setAttribute(pref + LNamespace.XML_AXE_SHOW_TICKS, shape.getTicksDisplayed().toString());
    root.setAttribute(pref + LNamespace.XML_AXE_LABELS_STYLE, shape.getLabelsDisplayed().toString());
    root.setAttribute(pref + LNamespace.XML_AXE_TICKS_STYLE, shape.getTicksStyle().toString());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_AXE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    createSVGAxe(root, doc);
    setSVGRotationAttribute(root);
    updatePathTicks();
    updatePathLabels();
    root.appendChild(currentTicks);
    path.setPathData(currentPath);
    root.appendChild(path);
    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) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList)

Example 3 with SVGGElement

use of net.sf.latexdraw.parsers.svg.SVGGElement 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 4 with SVGGElement

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

the class SVGBezierCurve method getShowPointsElement.

/**
 * Creates an SVG g element that contains the 'show points' plotting.
 * @param doc The owner document.
 * @return The created g element or null if the shape has not the 'show points' option activated.
 * @since 2.0.0
 */
protected SVGGElement getShowPointsElement(final SVGDocument doc) {
    if (!shape.isShowPts() || doc == null) {
        return null;
    }
    final double blackDash = shape.getDashSepBlack();
    final double whiteDash = shape.getDashSepWhite();
    final boolean hasDble = shape.hasDbleBord();
    final Color col = shape.getLineColour();
    final boolean isClosed = !shape.isOpened();
    final SVGGElement showPts = new SVGGElement(doc);
    final IArrow arrow1 = shape.getArrowAt(0);
    final IArrow arrow2 = shape.getArrowAt(-1);
    final double doubleSep = shape.getDbleBordSep();
    final double thick = (hasDble ? shape.getDbleBordSep() + shape.getThickness() * 2. : shape.getThickness()) / 2.;
    final double rad = (PSTricksConstants.DEFAULT_ARROW_DOTSIZE_DIM * IShape.PPC + PSTricksConstants.DEFAULT_ARROW_DOTSIZE_NUM * thick * 2.) / 2.;
    int i;
    final int size = shape.getNbPoints();
    showPts.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_SHOW_PTS);
    /* Plotting the lines. */
    for (i = 3; i < size; i += 2) {
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getPtAt(i - 1), shape.getSecondCtrlPtAt(i - 1), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getSecondCtrlPtAt(i - 1), shape.getFirstCtrlPtAt(i), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getFirstCtrlPtAt(i), shape.getPtAt(i), blackDash, whiteDash, hasDble, 1., doubleSep));
    }
    for (i = 2; i < size; i += 2) {
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getPtAt(i - 1), shape.getSecondCtrlPtAt(i - 1), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getSecondCtrlPtAt(i - 1), shape.getFirstCtrlPtAt(i), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getFirstCtrlPtAt(i), shape.getPtAt(i), blackDash, whiteDash, hasDble, 1., doubleSep));
    }
    if (isClosed) {
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getPtAt(-1), shape.getSecondCtrlPtAt(-1), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getSecondCtrlPtAt(-1), shape.getSecondCtrlPtAt(0), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getSecondCtrlPtAt(0), shape.getPtAt(0), blackDash, whiteDash, hasDble, 1., doubleSep));
    }
    showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getPtAt(0), shape.getFirstCtrlPtAt(0), blackDash, whiteDash, hasDble, 1., doubleSep));
    showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getFirstCtrlPtAt(0), shape.getFirstCtrlPtAt(1), blackDash, whiteDash, hasDble, 1., doubleSep));
    showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getFirstCtrlPtAt(1), shape.getPtAt(1), blackDash, whiteDash, hasDble, 1., doubleSep));
    // Plotting the dots.
    if (!arrow1.hasStyle() || isClosed) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getPtAt(0), col));
    }
    if (!arrow2.hasStyle() || isClosed) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getPtAt(-1), col));
    }
    for (i = 1; i < size - 1; i++) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getPtAt(i), col));
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getSecondCtrlPtAt(i), col));
    }
    for (i = 0; i < size; i++) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getFirstCtrlPtAt(i), col));
    }
    if (isClosed) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getSecondCtrlPtAt(-1), col));
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getSecondCtrlPtAt(0), col));
    }
    return showPts;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) Color(net.sf.latexdraw.models.interfaces.shape.Color) IArrow(net.sf.latexdraw.models.interfaces.shape.IArrow) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 5 with SVGGElement

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

Aggregations

SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)28 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)24 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)15 SVGPathElement (net.sf.latexdraw.parsers.svg.SVGPathElement)5 SVGDefsElement (net.sf.latexdraw.parsers.svg.SVGDefsElement)4 Color (net.sf.latexdraw.models.interfaces.shape.Color)3 SVGCircleElement (net.sf.latexdraw.parsers.svg.SVGCircleElement)3 SVGPolygonElement (net.sf.latexdraw.parsers.svg.SVGPolygonElement)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 SVGAttributes (net.sf.latexdraw.parsers.svg.SVGAttributes)2 SVGDocument (net.sf.latexdraw.parsers.svg.SVGDocument)2 SVGLineElement (net.sf.latexdraw.parsers.svg.SVGLineElement)2 SVGTextElement (net.sf.latexdraw.parsers.svg.SVGTextElement)2 SVGPointsParser (net.sf.latexdraw.parsers.svg.parsers.SVGPointsParser)2 SVGPathSegList (net.sf.latexdraw.parsers.svg.path.SVGPathSegList)2 LNamespace (net.sf.latexdraw.util.LNamespace)2