use of net.sf.latexdraw.parser.svg.SVGDocument in project latexdraw by arnobl.
the class SVGGroup method toSVG.
@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
if (shape.isEmpty()) {
return null;
}
final SVGElement root = new SVGGElement(doc);
final List<Shape> shapes = shape.getShapes();
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GROUP);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
shapes.stream().map(f -> shapeProducer.createSVGElement(f, doc)).forEach(newChild -> root.appendChild(newChild));
return root;
}
use of net.sf.latexdraw.parser.svg.SVGDocument in project latexdraw by arnobl.
the class TestSVGBase method setUp.
@BeforeEach
void setUp(final SVGShapesFactory svgfac) {
factory = svgfac;
doc = new SVGDocument();
final SVGSVGElement root = doc.getFirstChild();
root.setAttribute("xmlns:" + LNamespace.LATEXDRAW_NAMESPACE, LNamespace.LATEXDRAW_NAMESPACE_URI);
root.appendChild(new SVGDefsElement(doc));
root.setAttribute(SVGAttributes.SVG_VERSION, "1.1");
root.setAttribute(SVGAttributes.SVG_BASE_PROFILE, "full");
}
use of net.sf.latexdraw.parser.svg.SVGDocument in project latexdraw by arnobl.
the class SVGTriangle method toSVG.
@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
if (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 Point pt1 = shape.getTopLeftPoint();
final Point pt2 = shape.getBottomRightPoint();
final Point p1 = ShapeFactory.INST.createPoint((pt1.getX() + pt2.getX()) / 2d, pt1.getY());
final Point p2 = ShapeFactory.INST.createPoint(pt2.getX(), pt2.getY());
final Point 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 double value = p2y + (p1y < p2y ? gap : -gap);
final String points = p1x + "," + (p1y - cornerGap1) + " " + (p2x - cornerGap2) + "," + value + " " + (p3x + cornerGap2) + "," + value;
final String ltdPoints = shape.getPoints().stream().flatMap(pt -> Stream.of(String.valueOf(pt.getX()), String.valueOf(pt.getY()))).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;
}
use of net.sf.latexdraw.parser.svg.SVGDocument in project latexdraw by arnobl.
the class SVGDot method toSVG.
@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
final SVGElement root = new SVGGElement(doc);
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_DOT);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_SIZE, String.valueOf(shape.getDiametre()));
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_DOT_SHAPE, shape.getDotStyle().getPSTToken());
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POSITION, shape.getPosition().getX() + " " + shape.getPosition().getY());
viewFactory.createView(shape).ifPresent(vdot -> JFXToSVG.INSTANCE.shapesToElements(vdot.getChildren(), doc).forEach(elt -> root.appendChild(elt)));
setSVGRotationAttribute(root);
return root;
}
Aggregations