Search in sources :

Example 26 with SVGGElement

use of net.sf.latexdraw.parsers.svg.SVGGElement 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++) {
        line = new SVGLineElement(document);
        line.setAttribute(SVGAttributes.SVG_X1, String.valueOf(i + xSubStep * j));
        line.setAttribute(SVGAttributes.SVG_X2, String.valueOf(i + xSubStep * j));
        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++) {
        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 - ySubStep * j));
        line.setAttribute(SVGAttributes.SVG_Y2, String.valueOf(i - ySubStep * j));
        subgrids.appendChild(line);
    }
    elt.appendChild(subgrids);
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGLineElement(net.sf.latexdraw.parsers.svg.SVGLineElement)

Example 27 with SVGGElement

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

the class SVGText method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        return null;
    }
    final SVGElement root = new SVGGElement(doc);
    final String ltdPref = LNamespace.LATEXDRAW_NAMESPACE + ':';
    final Element txt = new SVGTextElement(doc);
    root.setAttribute(ltdPref + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TEXT);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    root.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(shape.getLineColour(), true));
    root.setAttribute(ltdPref + LNamespace.XML_POSITION, String.valueOf(shape.getTextPosition().getLatexToken()));
    txt.setAttribute(SVGAttributes.SVG_X, String.valueOf(shape.getX()));
    txt.setAttribute(SVGAttributes.SVG_Y, String.valueOf(shape.getY()));
    txt.appendChild(doc.createTextNode(shape.getText()));
    root.appendChild(txt);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parsers.svg.SVGTextElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) Element(org.w3c.dom.Element) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGTextElement(net.sf.latexdraw.parsers.svg.SVGTextElement)

Example 28 with SVGGElement

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

the class SVGTriangle method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null || doc.getFirstChild().getDefs() == null) {
        return null;
    }
    final SVGElement root = new SVGGElement(doc);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TRIANGLE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    final double gap = getPositionGap() / 2d;
    final IPoint pt1 = shape.getTopLeftPoint();
    final IPoint pt2 = shape.getBottomRightPoint();
    final IPoint p1 = ShapeFactory.INST.createPoint((pt1.getX() + pt2.getX()) / 2d, pt1.getY());
    final IPoint p2 = ShapeFactory.INST.createPoint(pt2.getX(), pt2.getY());
    final IPoint p3 = ShapeFactory.INST.createPoint(pt1.getX(), pt2.getY());
    final double p1x = p1.getX();
    final double p1y = p1.getY();
    final double p2x = p2.getX();
    final double p2y = p2.getY();
    final double p3x = p3.getX();
    double cornerGap1 = MathUtils.INST.getCornerGap(ShapeFactory.INST.createPoint(p1x, p2y), p1, p2, gap);
    double cornerGap2 = MathUtils.INST.getCornerGap(shape.getGravityCentre(), p2, p3, gap);
    if (p2x > p3x) {
        cornerGap2 *= -1d;
    }
    if (p1y > p2y) {
        cornerGap1 *= -1d;
    }
    final String points = p1x + "," + (p1y - cornerGap1) + " " + (p2x - cornerGap2) + "," + (p2y + (p1y < p2y ? gap : -gap)) + " " + (p3x + cornerGap2) + "," + (p2y + (p1y < p2y ? gap : -gap));
    final String ltdPoints = shape.getPoints().stream().map(pt -> Stream.of(String.valueOf(pt.getX()), String.valueOf(pt.getY()))).flatMap(s -> s).collect(Collectors.joining(" "));
    setShadowPolygon(doc, root, points);
    final SVGElement elt = new SVGPolygonElement(doc);
    elt.setAttribute(SVGAttributes.SVG_POINTS, points);
    root.appendChild(elt);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POINTS, ltdPoints);
    setDbleBorderPolygon(doc, root, points);
    setSVGAttributes(doc, elt, true);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGPointsParser(net.sf.latexdraw.parsers.svg.parsers.SVGPointsParser) ITriangle(net.sf.latexdraw.models.interfaces.shape.ITriangle) Point2D(java.awt.geom.Point2D) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) SVGDocument(net.sf.latexdraw.parsers.svg.SVGDocument) MathUtils(net.sf.latexdraw.models.MathUtils) Collectors(java.util.stream.Collectors) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) List(java.util.List) SVGPolygonElement(net.sf.latexdraw.parsers.svg.SVGPolygonElement) Stream(java.util.stream.Stream) LNamespace(net.sf.latexdraw.util.LNamespace) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGAttributes(net.sf.latexdraw.parsers.svg.SVGAttributes) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPolygonElement(net.sf.latexdraw.parsers.svg.SVGPolygonElement)

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