public SVGElement toSVG(final SVGDocument doc) {
if(doc==null)
throw new IllegalArgumentException();
final SVGElement root = new SVGGElement(doc);
SVGPolygonElement elt;
final StringBuilder pointsBuilder = new StringBuilder();
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_TYPE, LNamespace.XML_TYPE_POLYGON);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
for(final IPoint pt : shape.getPoints())
pointsBuilder.append(pt.getX()).append(',').append(pt.getY()).append(' ');
final String points = pointsBuilder.toString();
if(shape.hasShadow()) {
final SVGPolygonElement shad = new SVGPolygonElement(doc);
try { shad.setPoints(points); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
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);
try { elt.setPoints(points); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
setSVGBorderBackground(elt, root);
}
elt = new SVGPolygonElement(doc);
try { elt.setPoints(points); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
root.appendChild(elt);
setSVGAttributes(doc, elt, true);
elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE +':'+ LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));
if(shape.hasDbleBord()) {
final SVGPolygonElement dblBord = new SVGPolygonElement(doc);
try { dblBord.setPoints(points); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
setSVGDoubleBordersAttributes(dblBord);
root.appendChild(dblBord);
}
return root;