Description
PDFGraphics2D has two bugs which share a root cause: 1. When two draw calls are in different clips but share the same color (identical rgba values), the second one is drawn black. 2. Related but slightly different: Colors set before the clip don't affect the clipped objects.
These effects happen because in writeSetClip
, a new state is opened which is unaffected by the previously set color. This issue gets more pronounced by the fact that AbstractVectorGraphicsIO
optimizes writePaint
calls away if the previous current color is the same as the one for the new call - then even setting a color after setting a clip can fail.
The fix is simple: writeSetClip
needs to take over the current color to the new state, like it already does for transform and stroke:
protected void writeSetClip(Shape s) throws IOException {
// clear old clip
try {
AffineTransform at = getTransform();
Stroke stroke = getStroke();
Color color = getColor(); // fix
writeGraphicsRestore();
writeGraphicsSave();
writeStroke(stroke);
writeTransform(at);
writePaint(color); // fix
} catch (IOException e) {
handleException(e);
}
// write clip
writeClip(s);
}