@Override
public SVGElement toSVG(final SVGDocument doc) {
if(doc==null || doc.getFirstChild().getDefs()==null)
return null;
final SVGElement root = new SVGGElement(doc);
SVGElement elt;
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_TYPE, LNamespace.XML_TYPE_TRIANGLE);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
final double gap = getPositionGap()/2.;
final IPoint pt1 = shape.getTopLeftPoint();
final IPoint pt2 = shape.getBottomRightPoint();
final IPoint p1 = ShapeFactory.createPoint((pt1.getX()+pt2.getX())/2., pt1.getY());
final IPoint p2 = ShapeFactory.createPoint(pt2.getX(), pt2.getY());
final IPoint p3 = ShapeFactory.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 = GLibUtilities.getCornerGap(ShapeFactory.createPoint(p1x, p2y), p1, p2, gap);
double cornerGap2 = GLibUtilities.getCornerGap(shape.getGravityCentre(), p2, p3, gap);
if(p2x>p3x)
cornerGap2*=-1;
if(p1y>p2y)
cornerGap1*=-1;
final String points = p1x + "," + (p1y - cornerGap1) + " " + //$NON-NLS-1$//$NON-NLS-2$
(p2x - cornerGap2) + "," + (p2y + (p1y<p2y ? gap : -gap)) + " " + //$NON-NLS-1$//$NON-NLS-2$
(p3x + cornerGap2) + "," + (p2y + (p1y<p2y ? gap : -gap));//$NON-NLS-1$
final String ltdPoints = pt1.getX() + " " + pt1.getY() + " " + shape.getPtAt(1).getX() + " " + shape.getPtAt(1).getY() +//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
" " + shape.getPtAt(2).getX() + " " + shape.getPtAt(2).getY() + " " + pt2.getX() + " " + pt2.getY();//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
if(shape.hasShadow()){
final SVGElement shad = new SVGPolygonElement(doc);
shad.setAttribute(SVGAttributes.SVG_POINTS, points);
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 SVGPolygonElement(doc);
elt.setAttribute(SVGAttributes.SVG_POINTS, points);
setSVGBorderBackground(elt, root);
}
elt = new SVGPolygonElement(doc);
elt.setAttribute(SVGAttributes.SVG_POINTS, points);
root.appendChild(elt);
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_POINTS, ltdPoints);
if(shape.hasDbleBord()){
final SVGElement dblBord = new SVGPolygonElement(doc);
dblBord.setAttribute(SVGAttributes.SVG_POINTS, points);
setSVGDoubleBordersAttributes(dblBord);
root.appendChild(dblBord);
}
setSVGAttributes(doc, elt, true);