Hello,
I have a complicated shape form which is based of arcs and lines.
It is possible to connect this arcs and lines to a closed path?
I only see drawPolygon or drawPolyline . And draw(Shape)
My problem is following:
If I transfer the lines and arcs to svg,
Inkscape and other svg editors do not see it as a shape.
So as example I can not fill this shape in Inkscape like an rectangle.
Is there a possible way to append several lines and arcs to make a closed path?
Many thanks in advance,
Geduldspiele
Shape based of Lines and Arcs
-
- Posts: 2
- Joined: Fri Oct 03, 2014 3:36 pm
- antibot: No, of course not.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Shape based of Lines and Arcs
Have you looked at the class java.awt.geom.Path2D ? This class allows to produce a closed shape consisting of lines and arcs.
-
- JFreeChart Project Leader
- Posts: 11718
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Shape based of Lines and Arcs
Paradoxoff makes a good suggestion to study Java's Path2D class. JFreeSVG maps Path2D objects from Java2D to the equivalent Path element in SVG:
It is the getSVGPathData() method in JFreeSVG that does the conversion (in this code, the geomDP() method just formats the values to a fixed number of decimal places):
Code: Select all
this.sb.append("<path ").append(getSVGPathData(path)).append("/>");
Code: Select all
/**
* Creates an SVG path string for the supplied Java2D path.
*
* @param path the path ({@code null} not permitted).
*
* @return An SVG path string.
*/
private String getSVGPathData(Path2D path) {
StringBuilder b = new StringBuilder("d=\"");
float[] coords = new float[6];
boolean first = true;
PathIterator iterator = path.getPathIterator(null);
while (!iterator.isDone()) {
int type = iterator.currentSegment(coords);
if (!first) {
b.append(" ");
}
first = false;
switch (type) {
case (PathIterator.SEG_MOVETO):
b.append("M ").append(geomDP(coords[0])).append(" ")
.append(geomDP(coords[1]));
break;
case (PathIterator.SEG_LINETO):
b.append("L ").append(geomDP(coords[0])).append(" ")
.append(geomDP(coords[1]));
break;
case (PathIterator.SEG_QUADTO):
b.append("Q ").append(geomDP(coords[0]))
.append(" ").append(geomDP(coords[1]))
.append(" ").append(geomDP(coords[2]))
.append(" ").append(geomDP(coords[3]));
break;
case (PathIterator.SEG_CUBICTO):
b.append("C ").append(geomDP(coords[0])).append(" ")
.append(geomDP(coords[1])).append(" ")
.append(geomDP(coords[2])).append(" ")
.append(geomDP(coords[3])).append(" ")
.append(geomDP(coords[4])).append(" ")
.append(geomDP(coords[5]));
break;
case (PathIterator.SEG_CLOSE):
b.append("Z ");
break;
default:
break;
}
iterator.next();
}
return b.append("\"").toString();
}
David Gilbert
JFreeChart Project Leader
Read my blog
Ask your company to buy the JFreeChart Developer Guide
Check out other products sold by my company Object Refinery Limited
JFreeChart Project Leader


