Search in sources :

Example 6 with SVGGElement

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

the class SVGGrid method createSVGSubGridDots.

/**
 * Creates the SVG element corresponding to the sub dotted part of the grid.
 */
private void createSVGSubGridDots(final SVGDocument document, final SVGElement elt, final String prefix, final double subGridDiv, final double unit, 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 dotStep = unit * Shape.PPC / (subGridDots * subGridDiv);
    final double nbX = (maxX - minX) * subGridDiv;
    final double nbY = (maxY - minY) * subGridDiv;
    final SVGElement subgridDots = new SVGGElement(document);
    SVGElement dot;
    subgridDots.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(subGridColour, true));
    subgridDots.setAttribute(prefix + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GRID_SUB);
    subgridDots.setAttribute(prefix + LNamespace.XML_GRID_DOTS, String.valueOf(subGridDots));
    subgridDots.setAttribute(prefix + LNamespace.XML_GRID_SUB_DIV, String.valueOf(subGridDiv));
    subgridDots.setAttribute(prefix + LNamespace.XML_GRID_WIDTH, String.valueOf(subGridWidth));
    if (subGridColour.getO() < 1d) {
        subgridDots.setAttribute(SVGAttributes.SVG_FILL_OPACITY, MathUtils.INST.format.format(subGridColour.getO()));
    }
    for (double i = 0, n = tlx; i < nbX; i++, n += xSubStep) {
        for (double j = 0, m = tly; j <= nbY; j++, m += ySubStep) {
            for (double k = 0; k < subGridDots; k++) {
                dot = new SVGCircleElement(document);
                dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(n + k * dotStep));
                dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(m));
                dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(subGridWidth / 2.));
                subgridDots.appendChild(dot);
            }
        }
    }
    for (double j = 0, n = tly; j < nbY; j++, n += ySubStep) {
        for (double i = 0, m = tlx; i <= nbX; i++, m += xSubStep) {
            for (double k = 0; k < subGridDots; k++) {
                dot = new SVGCircleElement(document);
                dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(m));
                dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(n + k * dotStep));
                dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(subGridWidth / 2.));
                subgridDots.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(subGridWidth / 2.));
    elt.appendChild(subgridDots);
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGCircleElement(net.sf.latexdraw.parser.svg.SVGCircleElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement)

Example 7 with SVGGElement

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

the class SVGGrid method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    final String prefix = LNamespace.LATEXDRAW_NAMESPACE + ':';
    final SVGElement root = new SVGGElement(doc);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    root.setAttribute(prefix + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GRID);
    root.setAttribute(prefix + LNamespace.XML_GRID_X_SOUTH, String.valueOf(shape.isXLabelSouth()));
    root.setAttribute(prefix + LNamespace.XML_GRID_Y_WEST, String.valueOf(shape.isYLabelWest()));
    root.setAttribute(prefix + LNamespace.XML_GRID_UNIT, String.valueOf(shape.getUnit()));
    // NON-NLS
    root.setAttribute(prefix + LNamespace.XML_GRID_END, shape.getGridEndX() + " " + shape.getGridEndY());
    // NON-NLS
    root.setAttribute(prefix + LNamespace.XML_GRID_START, shape.getGridStartX() + " " + shape.getGridStartY());
    // NON-NLS
    root.setAttribute(prefix + LNamespace.XML_GRID_ORIGIN, shape.getOriginX() + " " + shape.getOriginY());
    createSVGGrid(root, doc);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement)

Example 8 with SVGGElement

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

the class SVGGrid method createSVGGridDiv.

/**
 * Creates the SVG element corresponding to the main not-dotted part of the grid.
 */
private void createSVGGridDiv(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 brx, final double bry, final double posX, final double posY, final double xStep, final double yStep, final double gridWidth, final Color linesColour) {
    double k;
    double i;
    final SVGElement grids = new SVGGElement(document);
    SVGElement line;
    grids.setAttribute(SVGAttributes.SVG_STROKE_WIDTH, String.valueOf(gridWidth));
    grids.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(linesColour, true));
    grids.setAttribute(SVGAttributes.SVG_STROKE_LINECAP, SVGAttributes.SVG_LINECAP_VALUE_SQUARE);
    grids.setAttribute(prefix + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GRID);
    if (linesColour.getO() < 1d) {
        grids.setAttribute(SVGAttributes.SVG_STROKE_OPACITY, MathUtils.INST.format.format(linesColour.getO()));
    }
    for (k = minX, i = posX; k <= maxX; i += xStep, k++) {
        line = new SVGLineElement(document);
        line.setAttribute(SVGAttributes.SVG_X1, String.valueOf(i));
        line.setAttribute(SVGAttributes.SVG_X2, String.valueOf(i));
        line.setAttribute(SVGAttributes.SVG_Y1, String.valueOf(bry));
        line.setAttribute(SVGAttributes.SVG_Y2, String.valueOf(tly));
        grids.appendChild(line);
    }
    for (k = minY, i = posY; k <= maxY; i -= yStep, k++) {
        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, String.valueOf(i));
        line.setAttribute(SVGAttributes.SVG_Y2, String.valueOf(i));
        grids.appendChild(line);
    }
    elt.appendChild(grids);
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGLineElement(net.sf.latexdraw.parser.svg.SVGLineElement)

Example 9 with SVGGElement

use of net.sf.latexdraw.parser.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.
 */
SVGGElement getShowPointsElement(@NotNull final SVGDocument doc) {
    if (!shape.isShowPts()) {
        return null;
    }
    final boolean hasDble = shape.hasDbleBord();
    final SVGGElement showPts = new SVGGElement(doc);
    final double thick = (hasDble ? shape.getDbleBordSep() + shape.getThickness() * 2d : shape.getThickness()) / 2d;
    showPts.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_SHOW_PTS);
    // Plotting the lines
    produceShowPointsLines(doc, showPts, thick);
    // Plotting the dots
    produceShowPointsDots(doc, showPts, thick);
    return showPts;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement)

Example 10 with SVGGElement

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

the class SVGCircle method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (doc.getFirstChild().getDefs() == null) {
        return null;
    }
    final Point tl = shape.getTopLeftPoint();
    final Point br = shape.getBottomRightPoint();
    final double tlx = tl.getX();
    final double tly = tl.getY();
    final double brx = br.getX();
    final double bry = br.getY();
    SVGElement elt;
    final SVGElement shad;
    final SVGElement dblBord;
    final SVGElement root = new SVGGElement(doc);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_CIRCLE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    final double gap = getPositionGap();
    final double abs = Math.abs((brx - tlx + gap) / 2d);
    if (shape.hasShadow()) {
        shad = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, abs, doc);
        setSVGShadowAttributes(shad, true);
        root.appendChild(shad);
    }
    if (shape.hasShadow() && !PSTricksConstants.LINE_NONE_STYLE.equals(shape.getLineStyle().getLatexToken())) {
        // The background of the borders must be filled is there is a shadow.
        elt = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, abs, doc);
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, abs, doc);
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        dblBord = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, abs, doc);
        setSVGDoubleBordersAttributes(dblBord);
        root.appendChild(dblBord);
    }
    setSVGAttributes(doc, elt, true);
    setSVGRotationAttribute(root);
    return root;
}
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)

Aggregations

SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)22 SVGElement (net.sf.latexdraw.parser.svg.SVGElement)20 Point (net.sf.latexdraw.model.api.shape.Point)10 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 SVGPolygonElement (net.sf.latexdraw.parser.svg.SVGPolygonElement)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 SVGRectElement (net.sf.latexdraw.parser.svg.SVGRectElement)2 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1