use of net.sf.latexdraw.parsers.svg.SVGGElement in project latexdraw by arnobl.
the class SVGPlot method toSVG.
@Override
public SVGElement toSVG(final SVGDocument doc) {
if (doc == null || doc.getFirstChild().getDefs() == null) {
return null;
}
final SVGElement root = new SVGGElement(doc);
if (shape.hasShadow()) {
final SVGGElement shad = new SVGGElement(doc);
toSVGShape(doc, shad);
setSVGShadowAttributes(shad, false);
root.appendChild(shad);
}
if (shape.hasDbleBord()) {
final SVGGElement dble = new SVGGElement(doc);
toSVGShape(doc, dble);
setSVGDoubleBordersAttributes(dble);
root.appendChild(dble);
}
toSVGShape(doc, root);
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, XML_TYPE_PLOT);
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_POLAR, Boolean.toString(shape.isPolar()));
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_EQ, shape.getPlotEquation());
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_STYLE, shape.getPlotStyle().getPSTToken());
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_MIN, Double.toString(shape.getPlotMinX()));
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_MAX, Double.toString(shape.getPlotMaxX()));
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_NB_POINTS, Integer.toString(shape.getNbPlottedPoints()));
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_XSCALE, Double.toString(shape.getXScale()));
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + XML_YSCALE, Double.toString(shape.getYScale()));
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POSITION_X, Double.toString(shape.getX()));
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POSITION_Y, Double.toString(shape.getY()));
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
setSVGAttributes(doc, root, true);
setSVGRotationAttribute(root);
return root;
}
use of net.sf.latexdraw.parsers.svg.SVGGElement in project latexdraw by arnobl.
the class SVGBezierCurve method toSVG.
@Override
public SVGElement toSVG(final SVGDocument doc) {
if (doc == null || doc.getFirstChild().getDefs() == null) {
return null;
}
final SVGDefsElement defs = doc.getFirstChild().getDefs();
final SVGElement root = new SVGGElement(doc);
SVGElement elt;
final String path = getPathSegList().toString();
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_BEZIER_CURVE);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
if (shape.hasShadow()) {
final SVGElement shad = new SVGPathElement(doc);
shad.setAttribute(SVGAttributes.SVG_D, path);
setSVGShadowAttributes(shad, false);
root.appendChild(shad);
if (shape.isOpened()) {
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 SVGPathElement(doc);
elt.setAttribute(SVGAttributes.SVG_D, path);
setSVGBorderBackground(elt, root);
}
elt = new SVGPathElement(doc);
elt.setAttribute(SVGAttributes.SVG_D, path);
root.appendChild(elt);
if (shape.hasDbleBord()) {
final SVGElement dblBord = new SVGPathElement(doc);
dblBord.setAttribute(SVGAttributes.SVG_D, path);
setSVGDoubleBordersAttributes(dblBord);
root.appendChild(dblBord);
}
setSVGAttributes(doc, elt, false);
elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));
if (shape.isOpened()) {
setSVGArrow(shape, elt, 0, false, doc, defs);
setSVGArrow(shape, elt, 1, false, doc, defs);
}
if (shape.isShowPts()) {
root.appendChild(getShowPointsElement(doc));
}
return root;
}
use of net.sf.latexdraw.parsers.svg.SVGGElement 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;
}
use of net.sf.latexdraw.parsers.svg.SVGGElement in project latexdraw by arnobl.
the class SVGRhombus method toSVG.
@Override
public SVGElement toSVG(final SVGDocument doc) {
if (doc == null) {
return null;
}
final IPoint tl = shape.getTopLeftPoint();
final IPoint br = shape.getBottomRightPoint();
final IPoint gc = shape.getGravityCentre();
final IPoint p1 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, tl.getY());
final IPoint p2 = ShapeFactory.INST.createPoint(br.getX(), (tl.getY() + br.getY()) / 2d);
final IPoint p3 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, br.getY());
final SVGElement root = new SVGGElement(doc);
final double gap = getPositionGap() / 2d;
final double cornerGap1 = MathUtils.INST.getCornerGap(gc, p1, p2, gap);
double cornerGap2 = MathUtils.INST.getCornerGap(gc, p2, p3, gap);
if (p2.getX() < p3.getX()) {
cornerGap2 *= -1d;
}
final String points = String.valueOf(p1.getX()) + ',' + (p1.getY() - cornerGap1) + ' ' + (p2.getX() + cornerGap2) + ',' + p2.getY() + ' ' + p3.getX() + ',' + (p3.getY() + cornerGap1) + ' ' + (tl.getX() - cornerGap2) + ',' + p2.getY();
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_RHOMBUS);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
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, String.valueOf(tl.getX()) + ' ' + tl.getY() + ' ' + br.getX() + ' ' + tl.getY() + ' ' + tl.getX() + ' ' + br.getY() + ' ' + br.getX() + ' ' + br.getY());
setDbleBorderPolygon(doc, root, points);
setSVGAttributes(doc, elt, true);
setSVGRotationAttribute(root);
return root;
}
use of net.sf.latexdraw.parsers.svg.SVGGElement in project latexdraw by arnobl.
the class SVGSquare method toSVG.
@Override
public SVGElement toSVG(final SVGDocument document) {
if (document == null || document.getFirstChild().getDefs() == null) {
throw new IllegalArgumentException();
}
final double gap = getPositionGap();
final IPoint tl = shape.getTopLeftPoint();
final IPoint br = shape.getBottomRightPoint();
SVGElement elt;
final SVGElement root = new SVGGElement(document);
final double width = Math.max(1d, br.getX() - tl.getX() + gap);
final double x = tl.getX() - gap / 2d;
final double y = tl.getY() - gap / 2d;
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_SQUARE);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
setShadowSVGRect(root, x, y, width, width, document);
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 SVGRectElement(x, y, width, width, document);
setSVGBorderBackground(elt, root);
setSVGRoundCorner(elt);
}
elt = new SVGRectElement(x, y, width, width, document);
root.appendChild(elt);
setSVGAttributes(document, elt, true);
setSVGRoundCorner(elt);
setDbleBordSVGRect(root, x, y, width, width, document);
setSVGRotationAttribute(root);
return root;
}
Aggregations