use of net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath in project latexdraw by arnobl.
the class SVGPathParser method parseClosepath.
/**
* Parses an SVGPath closepath.
*/
protected void parseClosepath() {
handler.onPathSeg(new SVGPathSegClosePath());
nextChar();
}
use of net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath in project latexdraw by arnobl.
the class SVGBezierCurve method getPathSegList.
/**
* @return The SVG segment path list of the current Bézier curve.
* @since 2.0.0
*/
protected SVGPathSegList getPathSegList() {
if (shape.getNbPoints() < 2) {
return null;
}
final int size = shape.getNbPoints();
int i;
final SVGPathSegList path = new SVGPathSegList();
path.add(new SVGPathSegMoveto(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), false));
path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(1).getX(), shape.getPtAt(1).getY(), shape.getFirstCtrlPtAt(0).getX(), shape.getFirstCtrlPtAt(0).getY(), shape.getFirstCtrlPtAt(1).getX(), shape.getFirstCtrlPtAt(1).getY(), false));
for (i = 2; i < size; i++) {
path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(i).getX(), shape.getPtAt(i).getY(), shape.getSecondCtrlPtAt(i - 1).getX(), shape.getSecondCtrlPtAt(i - 1).getY(), shape.getFirstCtrlPtAt(i).getX(), shape.getFirstCtrlPtAt(i).getY(), false));
}
if (!shape.isOpened()) {
final IPoint ctrl1b = shape.getFirstCtrlPtAt(0).centralSymmetry(shape.getPtAt(0));
final IPoint ctrl2b = shape.getFirstCtrlPtAt(-1).centralSymmetry(shape.getPtAt(-1));
path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), ctrl2b.getX(), ctrl2b.getY(), ctrl1b.getX(), ctrl1b.getY(), false));
path.add(new SVGPathSegClosePath());
}
return path;
}
use of net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath in project latexdraw by arnobl.
the class SVGCircleArc 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 double rotationAngle = shape.getRotationAngle();
final double startAngle = shape.getAngleStart() % (2. * Math.PI);
final double endAngle = shape.getAngleEnd() % (2. * Math.PI);
final ArcStyle type = shape.getArcStyle();
final SVGElement root = new SVGGElement(doc);
final IPoint start = shape.getStartPoint();
final IPoint end = shape.getEndPoint();
final double radius = shape.getWidth() / 2.0;
final boolean largeArcFlag = Math.abs(endAngle - startAngle) >= Math.PI;
final boolean sweepFlag = startAngle >= endAngle;
final SVGPathSegList path = new SVGPathSegList();
SVGElement elt;
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_ARC);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
path.add(new SVGPathSegMoveto(start.getX(), start.getY(), false));
path.add(new SVGPathSegArc(end.getX(), end.getY(), radius, radius, 0, largeArcFlag, sweepFlag, false));
if (type == ArcStyle.CHORD) {
path.add(new SVGPathSegClosePath());
} else {
if (type == ArcStyle.WEDGE) {
final IPoint gravityCenter = shape.getGravityCentre();
path.add(new SVGPathSegLineto(gravityCenter.getX(), gravityCenter.getY(), false));
path.add(new SVGPathSegClosePath());
}
}
if (shape.hasShadow()) {
final SVGElement shad = new SVGPathElement(doc);
shad.setAttribute(SVGAttributes.SVG_D, path.toString());
setSVGShadowAttributes(shad, true);
root.appendChild(shad);
setSVGArrow(shape, shad, 0, true, doc, defs);
setSVGArrow(shape, shad, 1, true, doc, defs);
}
// The background of the borders must be filled is there is a shadow.
if (shape.hasShadow()) {
elt = new SVGPathElement(doc);
elt.setAttribute(SVGAttributes.SVG_D, path.toString());
setSVGBorderBackground(elt, root);
}
elt = new SVGPathElement(doc);
elt.setAttribute(SVGAttributes.SVG_D, path.toString());
root.appendChild(elt);
if (shape.hasDbleBord()) {
final SVGElement dble = new SVGPathElement(doc);
dble.setAttribute(SVGAttributes.SVG_D, path.toString());
setSVGDoubleBordersAttributes(dble);
root.appendChild(dble);
}
setSVGRotationAttribute(root);
setSVGAttributes(doc, elt, true);
elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(rotationAngle));
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.path.SVGPathSegClosePath in project latexdraw by arnobl.
the class SVGModifiablePointsShape method getLinePointsFromSVGPathElement.
/**
* Gets the line points from the given SVGPathElement
*/
static List<IPoint> getLinePointsFromSVGPathElement(final SVGPathElement elt) {
if (elt == null) {
return Collections.emptyList();
}
final SVGPathSegList segs = elt.getSegList();
final int size = segs.get(segs.size() - 1) instanceof SVGPathSegClosePath ? segs.size() - 1 : segs.size();
// Creating a point to support when the first path element is relative.
Point2D pt = new Point2D.Double();
final List<IPoint> pts = new ArrayList<>();
for (int i = 0; i < size; i++) {
final SVGPathSeg seg = segs.get(i);
if (!(seg instanceof SVGPathSegLineto)) {
// $NON-NLS-1$
throw new IllegalArgumentException("The given SVG path element is not a set of lines.");
}
pt = ((SVGPathSegLineto) seg).getPoint(pt);
pts.add(ShapeFactory.INST.createPoint(pt.getX(), pt.getY()));
}
return pts;
}
use of net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath in project latexdraw by arnobl.
the class SVGArrow method createClosePath.
@Override
public void createClosePath() {
createPath();
currentPath.add(new SVGPathSegClosePath());
}
Aggregations