Search in sources :

Example 11 with SVGGElement

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

Example 12 with SVGGElement

use of net.sf.latexdraw.parsers.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 * 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 13 with SVGGElement

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

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

Example 15 with SVGGElement

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

the class SVGPicture method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null)
        return null;
    final SVGElement root = new SVGGElement(doc);
    final SVGElement img;
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_PICTURE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    img = new SVGImageElement(doc, shape.getPathSource());
    img.setAttribute(SVGAttributes.SVG_X, String.valueOf(shape.getPosition().getX()));
    img.setAttribute(SVGAttributes.SVG_Y, String.valueOf(shape.getPosition().getY()));
    img.setAttribute(SVGAttributes.SVG_HEIGHT, String.valueOf(shape.getImage().getHeight()));
    img.setAttribute(SVGAttributes.SVG_WIDTH, String.valueOf(shape.getImage().getWidth()));
    setSVGRotationAttribute(root);
    root.appendChild(img);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGImageElement(net.sf.latexdraw.parsers.svg.SVGImageElement)

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