Search in sources :

Example 16 with SVGElement

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

the class SVGEllipse method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null || doc.getFirstChild().getDefs() == null)
        throw new IllegalArgumentException();
    final IPoint tl = shape.getTopLeftPoint();
    final IPoint 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() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE)) {
        // 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.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGEllipseElement(net.sf.latexdraw.parsers.svg.SVGEllipseElement)

Example 17 with SVGElement

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

Example 18 with SVGElement

use of net.sf.latexdraw.parsers.svg.SVGElement 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 * IShape.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.parsers.svg.SVGGElement) SVGCircleElement(net.sf.latexdraw.parsers.svg.SVGCircleElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement)

Example 19 with SVGElement

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

the class SVGGrid method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null)
        return null;
    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-1$
    root.setAttribute(prefix + LNamespace.XML_GRID_END, shape.getGridEndX() + " " + shape.getGridEndY());
    // $NON-NLS-1$
    root.setAttribute(prefix + LNamespace.XML_GRID_START, shape.getGridStartX() + " " + shape.getGridStartY());
    // $NON-NLS-1$
    root.setAttribute(prefix + LNamespace.XML_GRID_ORIGIN, shape.getOriginX() + " " + shape.getOriginY());
    createSVGGrid(root, doc);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement)

Example 20 with SVGElement

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

the class SVGGroup method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null)
        return null;
    if (!shape.isEmpty()) {
        final SVGElement root = new SVGGElement(doc);
        final List<IShape> shapes = shape.getShapes();
        root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GROUP);
        root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
        for (final IShape f : shapes) root.appendChild(SVGShapesFactory.INSTANCE.createSVGElement(f, doc));
        return root;
    }
    return null;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IShape(net.sf.latexdraw.models.interfaces.shape.IShape)

Aggregations

SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)39 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)24 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)15 SVGPolygonElement (net.sf.latexdraw.parsers.svg.SVGPolygonElement)5 Test (org.junit.Test)5 SVGDefsElement (net.sf.latexdraw.parsers.svg.SVGDefsElement)4 SVGPathElement (net.sf.latexdraw.parsers.svg.SVGPathElement)4 SVGCircleElement (net.sf.latexdraw.parsers.svg.SVGCircleElement)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 Color (net.sf.latexdraw.models.interfaces.shape.Color)2 IArrow (net.sf.latexdraw.models.interfaces.shape.IArrow)2 IPolyline (net.sf.latexdraw.models.interfaces.shape.IPolyline)2 SVGAttr (net.sf.latexdraw.parsers.svg.SVGAttr)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