use of net.sf.latexdraw.parsers.svg.SVGElement 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;
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class TestSVGDocument method testCreateElementOK.
@Test
public void testCreateElementOK() {
SVGElement elt = (SVGElement) doc1.createElement("test");
assertEquals("test", elt.getNodeName());
assertEquals(doc1, elt.getOwnerDocument());
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class TestSVGNodeList method testItemOK.
@Test
public void testItemOK() {
final SVGElement elt = (SVGElement) doc.createElement("elt");
list.getNodes().add(elt);
assertEquals(elt, list.item(0));
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class TestSVGBase method produceOutputShapeFrom.
T produceOutputShapeFrom(final T sh) {
final SVGElement elt = SVGShapesFactory.INSTANCE.createSVGElement(sh, doc);
doc.getFirstChild().appendChild(elt);
return (T) SVGShapesFactory.INSTANCE.createShape(elt);
}
Aggregations