Search in sources :

Example 16 with SVGElement

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

the class SVGGrid method createSVGSubGridDiv.

/**
 * Creates the SVG element corresponding to the sub not-dotted part of the grid.
 */
private void createSVGSubGridDiv(final SVGDocument document, final SVGElement elt, final String prefix, final double subGridDiv, final double xSubStep, final double ySubStep, final double minX, final double maxX, final double minY, final double maxY, final int subGridDots, final double subGridWidth, final double tlx, final double tly, final double brx, final double bry, final Color subGridColour, final double posX, final double posY, final double xStep, final double yStep) {
    double i;
    double j;
    double k;
    final SVGElement subgrids = new SVGGElement(document);
    SVGElement line;
    subgrids.setAttribute(SVGAttributes.SVG_STROKE_WIDTH, String.valueOf(subGridWidth));
    subgrids.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(subGridColour, true));
    subgrids.setAttribute(SVGAttributes.SVG_STROKE_LINECAP, SVGAttributes.SVG_LINECAP_VALUE_ROUND);
    subgrids.setAttribute(prefix + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GRID_SUB);
    subgrids.setAttribute(prefix + LNamespace.XML_GRID_DOTS, String.valueOf(subGridDots));
    subgrids.setAttribute(prefix + LNamespace.XML_GRID_SUB_DIV, String.valueOf(subGridDiv));
    if (subGridColour.getO() < 1d) {
        subgrids.setAttribute(SVGAttributes.SVG_STROKE_OPACITY, MathUtils.INST.format.format(subGridColour.getO()));
    }
    for (k = minX, i = posX; k < maxX; i += xStep, k++) {
        for (j = 0; j <= subGridDiv; j++) {
            final String value = String.valueOf(i + xSubStep * j);
            line = new SVGLineElement(document);
            line.setAttribute(SVGAttributes.SVG_X1, value);
            line.setAttribute(SVGAttributes.SVG_X2, value);
            line.setAttribute(SVGAttributes.SVG_Y1, String.valueOf(bry));
            line.setAttribute(SVGAttributes.SVG_Y2, String.valueOf(tly));
            subgrids.appendChild(line);
        }
    }
    for (k = minY, i = posY; k < maxY; i -= yStep, k++) {
        for (j = 0; j <= subGridDiv; j++) {
            final String value = String.valueOf(i - ySubStep * j);
            line = new SVGLineElement(document);
            line.setAttribute(SVGAttributes.SVG_X1, String.valueOf(tlx));
            line.setAttribute(SVGAttributes.SVG_X2, String.valueOf(brx));
            line.setAttribute(SVGAttributes.SVG_Y1, value);
            line.setAttribute(SVGAttributes.SVG_Y2, value);
            subgrids.appendChild(line);
        }
    }
    elt.appendChild(subgrids);
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGLineElement(net.sf.latexdraw.parser.svg.SVGLineElement)

Example 17 with SVGElement

use of net.sf.latexdraw.parser.svg.SVGElement 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 Color gridLabelsColor = shape.getGridLabelsColour();
    final SVGElement texts = new SVGGElement(document);
    final double originX = shape.getOriginX();
    final double originY = shape.getOriginY();
    final double xorigin = xStep * originX;
    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 yorigin = shape.isXLabelSouth() ? yStep * originY + labelHeight : yStep * originY - 2d;
    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()));
    }
    produceSVGGridLabelsTexts(document, texts, gridWidth, xorigin, yorigin, fooText, minX, maxX, minY, maxY, tlx, tly, labelWidth, labelHeight, absStep);
    elt.appendChild(texts);
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) Color(net.sf.latexdraw.model.api.shape.Color) Text(javafx.scene.text.Text) Font(javafx.scene.text.Font)

Example 18 with SVGElement

use of net.sf.latexdraw.parser.svg.SVGElement 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 * Shape.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.parser.svg.SVGGElement) SVGCircleElement(net.sf.latexdraw.parser.svg.SVGCircleElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) Point(net.sf.latexdraw.model.api.shape.Point)

Example 19 with SVGElement

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

the class SVGBezierCurve method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (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()) {
            parameteriseSVGArrow(shape, shad, 0, true, doc, defs);
            parameteriseSVGArrow(shape, shad, 1, true, doc, defs);
        }
    }
    if (shape.hasShadow() && !PSTricksConstants.LINE_NONE_STYLE.equals(shape.getLineStyle().getLatexToken()) && 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()) {
        parameteriseSVGArrow(shape, elt, 0, false, doc, defs);
        parameteriseSVGArrow(shape, elt, 1, false, doc, defs);
    }
    if (shape.isShowPts()) {
        root.appendChild(getShowPointsElement(doc));
    }
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGPathElement(net.sf.latexdraw.parser.svg.SVGPathElement) SVGDefsElement(net.sf.latexdraw.parser.svg.SVGDefsElement)

Example 20 with SVGElement

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

the class SVGRhombus method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    final Point tl = shape.getTopLeftPoint();
    final Point br = shape.getBottomRightPoint();
    final Point gc = shape.getGravityCentre();
    final Point p1 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, tl.getY());
    final Point p2 = ShapeFactory.INST.createPoint(br.getX(), (tl.getY() + br.getY()) / 2d);
    final Point 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.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGPolygonElement(net.sf.latexdraw.parser.svg.SVGPolygonElement) Point(net.sf.latexdraw.model.api.shape.Point)

Aggregations

SVGElement (net.sf.latexdraw.parser.svg.SVGElement)27 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)20 Point (net.sf.latexdraw.model.api.shape.Point)13 SVGPolygonElement (net.sf.latexdraw.parser.svg.SVGPolygonElement)5 SVGTextElement (net.sf.latexdraw.parser.svg.SVGTextElement)4 List (java.util.List)3 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)3 SVGAttributes (net.sf.latexdraw.parser.svg.SVGAttributes)3 SVGCircleElement (net.sf.latexdraw.parser.svg.SVGCircleElement)3 SVGDefsElement (net.sf.latexdraw.parser.svg.SVGDefsElement)3 SVGDocument (net.sf.latexdraw.parser.svg.SVGDocument)3 SVGRectElement (net.sf.latexdraw.parser.svg.SVGRectElement)3 LNamespace (net.sf.latexdraw.util.LNamespace)3 NotNull (org.jetbrains.annotations.NotNull)3 Point2D (java.awt.geom.Point2D)2 Color (net.sf.latexdraw.model.api.shape.Color)2 SVGLineElement (net.sf.latexdraw.parser.svg.SVGLineElement)2 SVGParserUtils (net.sf.latexdraw.parser.svg.SVGParserUtils)2 SVGPathElement (net.sf.latexdraw.parser.svg.SVGPathElement)2 Collectors (java.util.stream.Collectors)1