use of net.sf.latexdraw.parsers.svg.path.SVGPathSegArc in project latexdraw by arnobl.
the class TestSVGPathSegArc method testToString.
@Test
public void testToString() throws ParseException {
SVGPathSegMoveto m = new SVGPathSegMoveto(0, 0, false);
SVGPathParser parser = new SVGPathParser(m.toString() + " " + seg.toString(), pathSeg -> {
if (pathSeg instanceof SVGPathSegMoveto && cpt == 0) {
cpt++;
return;
}
assertTrue(pathSeg instanceof SVGPathSegArc);
SVGPathSegArc seg2 = (SVGPathSegArc) pathSeg;
assertEquals(seg.getAngle(), seg2.getAngle(), 0.0001);
assertEquals(seg.getRX(), seg2.getRX(), 0.0001);
assertEquals(seg.getRY(), seg2.getRY(), 0.0001);
assertEquals(seg.getX(), seg2.getX(), 0.0001);
assertEquals(seg.getY(), seg2.getY(), 0.0001);
assertEquals(seg.isLargeArcFlag(), seg2.isLargeArcFlag());
assertEquals(seg.isRelative(), seg2.isRelative());
assertEquals(seg.isSweepFlag(), seg2.isSweepFlag());
});
parser.parse();
}
use of net.sf.latexdraw.parsers.svg.path.SVGPathSegArc in project latexdraw by arnobl.
the class TestSVGPathSegArc method setUp.
@Before
public void setUp() {
seg = new SVGPathSegArc(1, 2, 3, 4, 5, true, false, true);
cpt = 0;
}
use of net.sf.latexdraw.parsers.svg.path.SVGPathSegArc 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.SVGPathSegArc in project latexdraw by arnobl.
the class SVGArrow method createArc.
@Override
public void createArc(final double cx, final double cy, final double rx, final double ry, final double angle, final double length, final ObservableValue<Color> strokeProp, final ObservableDoubleValue strokeWidthProp) {
final boolean sweepFlag = angle < 0d ^ arrow.isInverted() ^ !arrow.isLeftArrow();
createPath();
currentPath.add(new SVGPathSegMoveto(cx + rx * Math.cos(Math.toRadians(angle)), cy - ry * Math.sin(Math.toRadians(angle)), false));
currentPath.add(new SVGPathSegArc(cx + rx * Math.cos(Math.toRadians(angle + length)), cy - ry * Math.sin(Math.toRadians(angle + length)), rx, ry, 0, false, sweepFlag, false));
setPathStroke(strokeProp);
setPathStrokeWidth(strokeWidthProp);
setPathFill(null);
}
use of net.sf.latexdraw.parsers.svg.path.SVGPathSegArc in project latexdraw by arnobl.
the class SVGPathParser method parseEllipticalArcto.
/**
* Parses an SVGPath arc.
* @param isRelative True if segment is relative.
* @throws ParseException If a problem occurs.
*/
protected void parseEllipticalArcto(final boolean isRelative) throws ParseException {
nextChar();
skipWSP();
do {
final Tuple<Double, Double> pr = parsePoint();
skipWSPComma();
final double angle = parseNumber(false);
skipWSPComma();
final boolean laf = parseFlag();
skipWSPComma();
final boolean sf = parseFlag();
skipWSPComma();
final Tuple<Double, Double> pt = parsePoint();
skipWSPComma();
handler.onPathSeg(new SVGPathSegArc(pt.a, pt.b, pr.a, pr.b, angle, laf, sf, isRelative));
} while (!isEOC() && isNumber(true));
}
Aggregations