Search in sources :

Example 6 with SVGDocument

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

Example 7 with SVGDocument

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

the class JFXToSVG method pathToSVGPath.

/**
 * Converts a JFX path to an SVGPath.
 * @param path To JFX path to convert.
 * @param doc The SVG document.
 * @return The created SVGPath.
 * @throws NullPointerException If one of the given parameter is null.
 */
public SVGPathElement pathToSVGPath(final Path path, final SVGDocument doc) {
    final SVGPathElement svgPath = new SVGPathElement(doc);
    final SVGPathSegList list = new SVGPathSegList();
    list.addAll(path.getElements().stream().map(elt -> createSVGPathSeg(elt)).filter(elt -> elt != null).collect(Collectors.toList()));
    svgPath.setPathData(list);
    copyPropertiesToSVG(svgPath, path);
    return svgPath;
}
Also used : Path(javafx.scene.shape.Path) ClosePath(javafx.scene.shape.ClosePath) CubicCurveTo(javafx.scene.shape.CubicCurveTo) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) SVGPathSegMoveto(net.sf.latexdraw.parsers.svg.path.SVGPathSegMoveto) LineTo(javafx.scene.shape.LineTo) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) MoveTo(javafx.scene.shape.MoveTo) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGPathSeg(net.sf.latexdraw.parsers.svg.path.SVGPathSeg) SVGAttributes(net.sf.latexdraw.parsers.svg.SVGAttributes) Color(javafx.scene.paint.Color) Ellipse(javafx.scene.shape.Ellipse) Node(javafx.scene.Node) SVGDocument(net.sf.latexdraw.parsers.svg.SVGDocument) PathElement(javafx.scene.shape.PathElement) Group(javafx.scene.Group) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) SVGPathSegCurvetoCubic(net.sf.latexdraw.parsers.svg.path.SVGPathSegCurvetoCubic) Collectors(java.util.stream.Collectors) SVGEllipseElement(net.sf.latexdraw.parsers.svg.SVGEllipseElement) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) SVGPathSegClosePath(net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath) List(java.util.List) StrokeLineCap(javafx.scene.shape.StrokeLineCap) Collections(java.util.Collections) Shape(javafx.scene.shape.Shape) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList)

Example 8 with SVGDocument

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

the class TestSVGAttr method setUp.

@Before
public void setUp() {
    SVGDocument doc = new SVGDocument();
    node = (SVGElement) doc.createElement("tag1");
}
Also used : SVGDocument(net.sf.latexdraw.parsers.svg.SVGDocument) Before(org.junit.Before)

Example 9 with SVGDocument

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

the class TestSVGDocument method setUp.

@Before
public void setUp() throws MalformedSVGDocument, URISyntaxException, IOException {
    doc1 = new SVGDocument();
    doc2 = new SVGDocument(new URI("src/test/resources/test.svg"));
}
Also used : SVGDocument(net.sf.latexdraw.parsers.svg.SVGDocument) MalformedSVGDocument(net.sf.latexdraw.parsers.svg.MalformedSVGDocument) URI(java.net.URI) Before(org.junit.Before)

Example 10 with SVGDocument

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

the class TestSVGDocument method testIsEqualNodeURI.

@Test
public void testIsEqualNodeURI() throws MalformedSVGDocument, URISyntaxException, IOException {
    SVGDocument doc = new SVGDocument(new URI("src/test/resources/test.svg"));
    assertTrue(doc2.isEqualNode(doc));
    assertFalse(doc2.isEqualNode(null));
    assertFalse(doc2.isEqualNode(doc1));
}
Also used : SVGDocument(net.sf.latexdraw.parsers.svg.SVGDocument) MalformedSVGDocument(net.sf.latexdraw.parsers.svg.MalformedSVGDocument) URI(java.net.URI) Test(org.junit.Test)

Aggregations

SVGDocument (net.sf.latexdraw.parsers.svg.SVGDocument)12 MalformedSVGDocument (net.sf.latexdraw.parsers.svg.MalformedSVGDocument)5 Before (org.junit.Before)5 URI (java.net.URI)3 List (java.util.List)3 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)3 SVGAttributes (net.sf.latexdraw.parsers.svg.SVGAttributes)3 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)3 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)3 Test (org.junit.Test)3 Point2D (java.awt.geom.Point2D)2 Collectors (java.util.stream.Collectors)2 SVGPointsParser (net.sf.latexdraw.parsers.svg.parsers.SVGPointsParser)2 LNamespace (net.sf.latexdraw.util.LNamespace)2 Collections (java.util.Collections)1 Stream (java.util.stream.Stream)1 Group (javafx.scene.Group)1 Node (javafx.scene.Node)1 Color (javafx.scene.paint.Color)1 ClosePath (javafx.scene.shape.ClosePath)1