Search in sources :

Example 11 with SVGElement

use of net.sf.latexdraw.parser.svg.SVGElement 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 12 with SVGElement

use of net.sf.latexdraw.parser.svg.SVGElement 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 13 with SVGElement

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

Example 14 with SVGElement

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

the class SVGEllipse 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 root = new SVGGElement(doc);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_ELLIPSE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    final double gap = getPositionGap();
    final double width = Math.max(1., (brx - tlx + gap) / 2.);
    final double height = Math.max(1., (bry - tly + gap) / 2.);
    final double x = (brx + tlx) / 2.;
    final double y = (bry + tly) / 2.;
    if (shape.hasShadow()) {
        elt = new SVGEllipseElement(x, y, width, height, doc);
        setSVGShadowAttributes(elt, true);
        root.appendChild(elt);
    }
    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 SVGEllipseElement(x, y, width, height, doc);
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGEllipseElement(x, y, width, height, doc);
    setSVGAttributes(doc, elt, true);
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        elt = new SVGEllipseElement(x, y, width, height, doc);
        setSVGDoubleBordersAttributes(elt);
        root.appendChild(elt);
    }
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) Point(net.sf.latexdraw.model.api.shape.Point) SVGEllipseElement(net.sf.latexdraw.parser.svg.SVGEllipseElement)

Example 15 with SVGElement

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

the class SVGGrid method produceSVGGridYEastLabelsTexts.

private final void produceSVGGridYEastLabelsTexts(final SVGDocument document, final SVGElement texts, final double xorigin, final double tly, final double gridWidth, final double minY, final double maxY, final double labelHeight, final double absStep) {
    final double width = gridWidth / 2d;
    final int gridLabelsSize = shape.getLabelsSize();
    for (double i = tly + (shape.isXLabelSouth() ? -width - gridLabelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
        final String label = String.valueOf((int) j);
        final SVGElement 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);
    }
}
Also used : SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parser.svg.SVGTextElement) 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