Search in sources :

Example 6 with SVGGElement

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

the class SVGRectangle method toSVG.

@Override
public SVGElement toSVG(final SVGDocument document) {
    if (document == null || document.getFirstChild().getDefs() == null) {
        throw new IllegalArgumentException();
    }
    final double gap = getPositionGap();
    final IPoint tl = shape.getTopLeftPoint();
    final IPoint br = shape.getBottomRightPoint();
    SVGElement elt;
    final SVGElement root = new SVGGElement(document);
    final double width = Math.max(1d, br.getX() - tl.getX() + gap);
    final double height = Math.max(1d, br.getY() - tl.getY() + gap);
    final double x = tl.getX() - gap / 2d;
    final double y = tl.getY() - gap / 2d;
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_RECT);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    setShadowSVGRect(root, x, y, width, height, document);
    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 SVGRectElement(x, y, width, height, document);
        setSVGBorderBackground(elt, root);
        setSVGRoundCorner(elt);
    }
    elt = new SVGRectElement(x, y, width, height, document);
    root.appendChild(elt);
    setSVGAttributes(document, elt, true);
    setSVGRoundCorner(elt);
    setDbleBordSVGRect(root, x, y, width, height, document);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGRectElement(net.sf.latexdraw.parsers.svg.SVGRectElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 7 with SVGGElement

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

the class SVGShape method setSVGHatchings.

private void setSVGHatchings(final SVGDocument doc, final SVGElement root, final boolean shadowFills) {
    final SVGDefsElement defs = doc.getFirstChild().getDefs();
    final String id = SVGElements.SVG_PATTERN + shape.hashCode();
    final SVGPatternElement hatch = new SVGPatternElement(doc);
    final SVGGElement gPath = new SVGGElement(doc);
    final IPoint max = shape.getFullBottomRightPoint();
    final SVGPathElement path = new SVGPathElement(doc);
    root.setAttribute(SVGAttributes.SVG_FILL, SVG_URL_TOKEN_BEGIN + id + ')');
    hatch.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, shape.getFillingStyle().getLatexToken());
    hatch.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getHatchingsAngle()));
    hatch.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_SIZE, String.valueOf(shape.getHatchingsSep()));
    hatch.setAttribute(SVGAttributes.SVG_PATTERN_UNITS, SVGAttributes.SVG_UNITS_VALUE_USR);
    hatch.setAttribute(SVGAttributes.SVG_ID, id);
    hatch.setAttribute(SVGAttributes.SVG_X, "0");
    hatch.setAttribute(SVGAttributes.SVG_Y, "0");
    hatch.setAttribute(SVGAttributes.SVG_WIDTH, String.valueOf((int) max.getX()));
    hatch.setAttribute(SVGAttributes.SVG_HEIGHT, String.valueOf((int) max.getY()));
    gPath.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(shape.getHatchingsCol(), true));
    gPath.setAttribute(SVGAttributes.SVG_STROKE_WIDTH, String.valueOf(shape.getHatchingsWidth()));
    gPath.setAttribute(SVGAttributes.SVG_STROKE_DASHARRAY, SVGAttributes.SVG_VALUE_NONE);
    if (shape.getHatchingsCol().getO() < 1d) {
        gPath.setAttribute(SVGAttributes.SVG_STROKE_OPACITY, MathUtils.INST.format.format(shape.getHatchingsCol().getO()));
    }
    path.setAttribute(SVGAttributes.SVG_D, getSVGHatchingsPath().toString());
    gPath.appendChild(path);
    // Several shapes having hatching must have their shadow filled.
    if (shape.isFilled() || (shape.hasShadow() && shadowFills)) {
        final SVGRectElement fill = new SVGRectElement(doc);
        fill.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(shape.getFillingCol(), true));
        if (shape.getFillingCol().getO() < 1d) {
            fill.setAttribute(SVGAttributes.SVG_FILL_OPACITY, MathUtils.INST.format.format(shape.getFillingCol().getO()));
        }
        fill.setAttribute(SVGAttributes.SVG_STROKE, SVGAttributes.SVG_VALUE_NONE);
        fill.setAttribute(SVGAttributes.SVG_WIDTH, String.valueOf((int) max.getX()));
        fill.setAttribute(SVGAttributes.SVG_HEIGHT, String.valueOf((int) max.getY()));
        hatch.appendChild(fill);
    }
    defs.appendChild(hatch);
    hatch.appendChild(gPath);
}
Also used : SVGPatternElement(net.sf.latexdraw.parsers.svg.SVGPatternElement) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGRectElement(net.sf.latexdraw.parsers.svg.SVGRectElement) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGDefsElement(net.sf.latexdraw.parsers.svg.SVGDefsElement)

Example 8 with SVGGElement

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

the class SVGCircle method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null || doc.getFirstChild().getDefs() == null) {
        return null;
    }
    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 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();
    if (shape.hasShadow()) {
        shad = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, Math.abs((brx - tlx + gap) / 2d), doc);
        setSVGShadowAttributes(shad, true);
        root.appendChild(shad);
    }
    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 SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, Math.abs((brx - tlx + gap) / 2d), doc);
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, Math.abs((brx - tlx + gap) / 2d), doc);
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        dblBord = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, Math.abs((brx - tlx + gap) / 2d), doc);
        setSVGDoubleBordersAttributes(dblBord);
        root.appendChild(dblBord);
    }
    setSVGAttributes(doc, elt, true);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGCircleElement(net.sf.latexdraw.parsers.svg.SVGCircleElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 9 with SVGGElement

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

the class SVGCircleArc method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null || doc.getFirstChild().getDefs() == null) {
        return null;
    }
    final SVGDefsElement defs = doc.getFirstChild().getDefs();
    final double rotationAngle = shape.getRotationAngle();
    final double startAngle = shape.getAngleStart() % (2. * Math.PI);
    final double endAngle = shape.getAngleEnd() % (2. * Math.PI);
    final ArcStyle type = shape.getArcStyle();
    final SVGElement root = new SVGGElement(doc);
    final IPoint start = shape.getStartPoint();
    final IPoint end = shape.getEndPoint();
    final double radius = shape.getWidth() / 2.0;
    final boolean largeArcFlag = Math.abs(endAngle - startAngle) >= Math.PI;
    final boolean sweepFlag = startAngle >= endAngle;
    final SVGPathSegList path = new SVGPathSegList();
    SVGElement elt;
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_ARC);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    path.add(new SVGPathSegMoveto(start.getX(), start.getY(), false));
    path.add(new SVGPathSegArc(end.getX(), end.getY(), radius, radius, 0, largeArcFlag, sweepFlag, false));
    if (type == ArcStyle.CHORD) {
        path.add(new SVGPathSegClosePath());
    } else {
        if (type == ArcStyle.WEDGE) {
            final IPoint gravityCenter = shape.getGravityCentre();
            path.add(new SVGPathSegLineto(gravityCenter.getX(), gravityCenter.getY(), false));
            path.add(new SVGPathSegClosePath());
        }
    }
    if (shape.hasShadow()) {
        final SVGElement shad = new SVGPathElement(doc);
        shad.setAttribute(SVGAttributes.SVG_D, path.toString());
        setSVGShadowAttributes(shad, true);
        root.appendChild(shad);
        setSVGArrow(shape, shad, 0, true, doc, defs);
        setSVGArrow(shape, shad, 1, true, doc, defs);
    }
    // The background of the borders must be filled is there is a shadow.
    if (shape.hasShadow()) {
        elt = new SVGPathElement(doc);
        elt.setAttribute(SVGAttributes.SVG_D, path.toString());
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGPathElement(doc);
    elt.setAttribute(SVGAttributes.SVG_D, path.toString());
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        final SVGElement dble = new SVGPathElement(doc);
        dble.setAttribute(SVGAttributes.SVG_D, path.toString());
        setSVGDoubleBordersAttributes(dble);
        root.appendChild(dble);
    }
    setSVGRotationAttribute(root);
    setSVGAttributes(doc, elt, true);
    elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(rotationAngle));
    setSVGArrow(shape, elt, 0, false, doc, defs);
    setSVGArrow(shape, elt, 1, false, doc, defs);
    if (shape.isShowPts()) {
        root.appendChild(getShowPointsElement(doc));
    }
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath) SVGPathSegArc(net.sf.latexdraw.parsers.svg.path.SVGPathSegArc) ArcStyle(net.sf.latexdraw.models.interfaces.shape.ArcStyle) SVGDefsElement(net.sf.latexdraw.parsers.svg.SVGDefsElement)

Example 10 with SVGGElement

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

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