Skip to content

Commit

Permalink
Fixed freehep#33
Browse files Browse the repository at this point in the history
Repaired SVG clipping: Non-working PathIterator reuse is replaced by
creating two PathIterators from a shape.
  • Loading branch information
benediktmu committed Mar 21, 2016
1 parent 25e9edc commit ffedf24
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public void draw(Shape shape) {
style.put("fill", "none");
style.putAll(getStrokeProperties(getStroke(), false));

writePathIterator(path, style);
writePathIterator(shape, style);
} else if (getStroke() != null) {
// fill the shape created by stroke
fill(getStroke().createStrokedShape(shape));
Expand Down Expand Up @@ -486,18 +486,18 @@ public void fill(Shape shape) {
// no border
style.put("stroke", "none");

writePathIterator(path, style);
writePathIterator(shape, style);
}
}

/**
* writes a path using {@link #getPath(java.awt.geom.PathIterator)}
* writes a shape's path using {@link #getPath(java.awt.geom.PathIterator)}
* and the given style
*
* @param pi PathIterator
* @param shape The shape to get a PathIterator from
* @param style Properties for <g> tag
*/
private void writePathIterator(PathIterator pi, Properties style) {
private void writePathIterator(Shape shape, Properties style) {
StringBuffer result = new StringBuffer();

// write style
Expand All @@ -506,6 +506,7 @@ private void writePathIterator(PathIterator pi, Properties style) {
result.append(">\n ");

// draw shape
PathIterator pi = shape.getPathIterator(null);
result.append(getPath(pi));

// close style
Expand All @@ -516,6 +517,8 @@ private void writePathIterator(PathIterator pi, Properties style) {
// test if clip intersects pi
if (getClip() != null) {
GeneralPath gp = new GeneralPath();

pi = shape.getPathIterator(null);
gp.append(pi, true);
// create the stroked shape
Stroke stroke = getStroke() == null? defaultStroke : getStroke();
Expand Down

0 comments on commit ffedf24

Please sign in to comment.