Search in sources :

Example 1 with SVGLineElement

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

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

Aggregations

SVGElement (net.sf.latexdraw.parser.svg.SVGElement)2 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)2 SVGLineElement (net.sf.latexdraw.parser.svg.SVGLineElement)2