Permalink
Browse files

Extended handling of Even-Odd winding rule to PDF and EPS

  • Loading branch information...
davideby committed May 22, 2018
1 parent f45479b commit 485723d43975cec8bd9c0b879edf49d091f28370
@@ -31,6 +31,7 @@
import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
@@ -259,7 +260,12 @@ public void handle(Command<?> command) {
elements.add(getOutput(c.getValue(), c.getX(), c.getY()));
} else if (command instanceof FillShapeCommand) {
FillShapeCommand c = (FillShapeCommand) command;
elements.add(getOutput(c.getValue()) + " fill");
String fillMethod = " fill";
Shape shape = c.getValue();
if (shape instanceof Path2D && ((Path2D) shape).getWindingRule() == Path2D.WIND_EVEN_ODD) {
fillMethod = " eofill";
}
elements.add(getOutput(c.getValue()) + fillMethod);
} else if (command instanceof CreateCommand) {
elements.add("gsave");
} else if (command instanceof DisposeCommand) {
@@ -29,6 +29,7 @@
import java.awt.Stroke;
import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
@@ -505,9 +506,14 @@ private int getVersion(PDFObject object) {
}
} else if (command instanceof FillShapeCommand) {
FillShapeCommand c = (FillShapeCommand) command;
String fillMethod = " f";
Shape shape = c.getValue();
if (shape instanceof Path2D && ((Path2D) shape).getWindingRule() == Path2D.WIND_EVEN_ODD) {
fillMethod = " f*";
}
try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) {
ba.write(getOutput(c.getValue()));
ba.write(serialize(" f"));
ba.write(serialize(fillMethod));
s = ba.toByteArray();
} catch (IOException e) {
throw new IllegalStateException(e);

0 comments on commit 485723d

Please sign in to comment.