use of net.sf.latexdraw.parsers.svg.SVGPolyLineElement in project latexdraw by arnobl.
the class SVGPolylines method toSVG.
@Override
public SVGElement toSVG(final SVGDocument doc) {
if (doc == null) {
return null;
}
final SVGElement root = new SVGGElement(doc);
final SVGDefsElement defs = doc.getFirstChild().getDefs();
final StringBuilder points = new StringBuilder();
final List<IPoint> pts = shape.getPoints();
SVGPolyLineElement elt;
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_JOINED_LINES);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
for (final IPoint pt : pts) {
points.append(pt.getX()).append(',').append(pt.getY()).append(' ');
}
final String pointsStr = points.toString();
if (shape.hasShadow()) {
final SVGPolyLineElement shad = new SVGPolyLineElement(doc);
try {
shad.setPoints(pointsStr);
} catch (final ParseException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
setSVGShadowAttributes(shad, false);
root.appendChild(shad);
setSVGArrow(shape, shad, 0, true, doc, defs);
setSVGArrow(shape, shad, 1, true, doc, defs);
}
if (shape.hasShadow() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE) && shape.isFilled()) {
// The background of the borders must be filled is there is a shadow.
elt = new SVGPolyLineElement(doc);
try {
elt.setPoints(pointsStr);
} catch (final ParseException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
setSVGBorderBackground(elt, root);
}
elt = new SVGPolyLineElement(doc);
try {
elt.setPoints(pointsStr);
} catch (final ParseException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
root.appendChild(elt);
if (shape.hasDbleBord()) {
final SVGPolyLineElement dblBord = new SVGPolyLineElement(doc);
try {
dblBord.setPoints(pointsStr);
} catch (final ParseException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
setSVGDoubleBordersAttributes(dblBord);
root.appendChild(dblBord);
}
setSVGAttributes(doc, elt, false);
elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));
setSVGArrow(shape, elt, 0, false, doc, defs);
setSVGArrow(shape, elt, shape.getNbArrows() - 1, false, doc, defs);
return root;
}
Aggregations