Search in sources :

Example 21 with SVGGElement

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

the class SVGCircleArc 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 SVGGElement showPts = new SVGGElement(doc);
    final double thickness = shape.getThickness() / 2.;
    showPts.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_SHOW_PTS);
    showPts.appendChild(getShowPointsLine(doc, thickness, shape.getLineColour(), shape.getGravityCentre(), shape.getStartPoint(), shape.getDashSepBlack(), shape.getDashSepWhite(), false, 1, 0));
    showPts.appendChild(getShowPointsLine(doc, thickness, shape.getLineColour(), shape.getGravityCentre(), shape.getEndPoint(), shape.getDashSepBlack(), shape.getDashSepWhite(), false, 1, 0));
    return showPts;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement)

Example 22 with SVGGElement

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

Example 23 with SVGGElement

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

the class SVGFreeHand method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        return null;
    }
    final SVGElement root = new SVGGElement(doc);
    SVGElement elt;
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_FREEHAND);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_PATH_TYPE, String.valueOf(shape.getType()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_INTERVAL, String.valueOf(shape.getInterval()));
    final String path = getPath().toString();
    final StringBuilder pts = new StringBuilder();
    for (final IPoint pt : shape.getPoints()) {
        pts.append(pt.getX()).append(' ').append(pt.getY()).append(' ');
    }
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POINTS, pts.toString());
    if (shape.hasShadow()) {
        final SVGElement shad = new SVGPathElement(doc);
        shad.setAttribute(SVGAttributes.SVG_D, path);
        setSVGShadowAttributes(shad, false);
        root.appendChild(shad);
    }
    // The background of the borders must be filled is there is a shadow.
    if (shape.hasShadow() && shape.isFilled()) {
        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);
    setSVGAttributes(doc, elt, false);
    setSVGRotationAttribute(root);
    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) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 24 with SVGGElement

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

the class SVGGrid method createSVGGridDots.

/**
 * Creates the SVG element corresponding to the main dotted part of the grid.
 */
private void createSVGGridDots(final SVGDocument document, final SVGElement elt, final String prefix, final double absStep, final double minX, final double maxX, final double minY, final double maxY, final double tlx, final double tly, final double brx, final double bry, final double unit, final double posX, final double posY, final double xStep, final double yStep, final double gridWidth, final Color linesColour) {
    double k;
    double i;
    double m;
    double n;
    double l;
    double j;
    final int gridDots = shape.getGridDots();
    final double dotStep = unit * IShape.PPC / gridDots;
    final SVGElement gridDotsElt = new SVGGElement(document);
    SVGElement dot;
    gridDotsElt.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(linesColour, true));
    gridDotsElt.setAttribute(prefix + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GRID);
    gridDotsElt.setAttribute(prefix + LNamespace.XML_GRID_DOTS, String.valueOf(gridDots));
    gridDotsElt.setAttribute(prefix + LNamespace.XML_GRID_WIDTH, String.valueOf(gridWidth));
    if (linesColour.getO() < 1d) {
        gridDotsElt.setAttribute(SVGAttributes.SVG_FILL_OPACITY, MathUtils.INST.format.format(linesColour.getO()));
    }
    for (k = minX, i = posX; k <= maxX; i += xStep, k++) for (m = tly, n = minY; n < maxY; n++, m += absStep) for (l = 0, j = m; l < gridDots; l++, j += dotStep) {
        dot = new SVGCircleElement(document);
        dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(i));
        dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(j));
        dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(gridWidth / 2.));
        gridDotsElt.appendChild(dot);
    }
    for (k = minY, i = posY; k <= maxY; i -= yStep, k++) for (m = tlx, n = minX; n < maxX; n++, m += absStep) for (l = 0, j = m; l < gridDots; l++, j += dotStep) {
        dot = new SVGCircleElement(document);
        dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(j));
        dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(i));
        dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(gridWidth / 2.));
        gridDotsElt.appendChild(dot);
    }
    dot = new SVGCircleElement(document);
    dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(brx));
    dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(bry));
    dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(gridWidth / 2.));
    gridDotsElt.appendChild(dot);
    elt.appendChild(gridDotsElt);
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGCircleElement(net.sf.latexdraw.parsers.svg.SVGCircleElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 25 with SVGGElement

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

the class SVGGrid method createSVGGridLabels.

/**
 * Creates the SVG element corresponding to the labels of the grid.
 */
private void createSVGGridLabels(final SVGDocument document, final SVGElement elt, final String prefix, final double minX, final double maxX, final double minY, final double maxY, final double tlx, final double tly, final double xStep, final double yStep, final double gridWidth, final double absStep) {
    final int gridLabelsSize = shape.getLabelsSize();
    final boolean isXLabelSouth = shape.isXLabelSouth();
    final boolean isYLabelWest = shape.isYLabelWest();
    final double originX = shape.getOriginX();
    final double originY = shape.getOriginY();
    final Color gridLabelsColor = shape.getGridLabelsColour();
    final Text fooText = new Text(String.valueOf((int) maxX));
    fooText.setFont(new Font(null, shape.getLabelsSize()));
    final double labelHeight = fooText.getBaselineOffset();
    final double labelWidth = fooText.getBoundsInLocal().getWidth();
    final double xorigin = xStep * originX;
    final double yorigin = isXLabelSouth ? yStep * originY + labelHeight : yStep * originY - 2d;
    final double width = gridWidth / 2d;
    final double tmp = isXLabelSouth ? width : -width;
    final SVGElement texts = new SVGGElement(document);
    SVGElement text;
    String label;
    double i;
    double j;
    texts.setAttribute(SVGAttributes.SVG_FONT_SIZE, String.valueOf(shape.getLabelsSize()));
    texts.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(gridLabelsColor, true));
    texts.setAttribute(prefix + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TEXT);
    if (gridLabelsColor.getO() < 1d) {
        texts.setAttribute(SVGAttributes.SVG_OPACITY, MathUtils.INST.format.format(gridLabelsColor.getO()));
    }
    for (i = tlx + (isYLabelWest ? width + gridLabelsSize / 4d : -width - labelWidth - gridLabelsSize / 4d), j = minX; j <= maxX; i += absStep, j++) {
        text = new SVGTextElement(document);
        text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int) i));
        text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int) (yorigin + tmp)));
        text.setTextContent(String.valueOf((int) j));
        texts.appendChild(text);
    }
    if (isYLabelWest) {
        for (i = tly + (isXLabelSouth ? -width - gridLabelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
            label = String.valueOf((int) j);
            text = new SVGTextElement(document);
            fooText.setText(label);
            text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int) (xorigin - fooText.getLayoutBounds().getWidth() - gridLabelsSize / 4d - width)));
            text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int) i));
            text.setTextContent(label);
            texts.appendChild(text);
        }
    } else {
        for (i = tly + (isXLabelSouth ? -width - gridLabelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
            label = String.valueOf((int) j);
            text = new SVGTextElement(document);
            text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int) (xorigin + gridLabelsSize / 4d + width)));
            text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int) i));
            text.setTextContent(label);
            texts.appendChild(text);
        }
    }
    elt.appendChild(texts);
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parsers.svg.SVGTextElement) Color(net.sf.latexdraw.models.interfaces.shape.Color) Text(javafx.scene.text.Text) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Font(javafx.scene.text.Font)

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