Skip to content

Commit

Permalink
Fixed freehep#34
Browse files Browse the repository at this point in the history
setClip now takes over color to new state.
  • Loading branch information
benediktmu committed Mar 21, 2016
1 parent ffedf24 commit 734c9fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -798,16 +798,25 @@ protected void writeTransform(AffineTransform t) throws IOException {
* ================================================================================
*/
protected void writeSetClip(Shape s) throws IOException {

// clear old clip
// FIXME this code only clears the clip if the PDF graphics state stack has been
// kept so shallow that a single "pop" removes the clip. However, when using
// Graphics.create states are being pushed on the stack and this method doesn't
// successfully clear the clip any more. A solution requires clearing the whole
// stack, setting a new clip and reconstructing the stack when the state with the
// new clip gets popped some time later.
try {
AffineTransform at = getTransform();
Stroke stroke = getStroke();
Color color = getColor();

writeGraphicsRestore();
writeGraphicsSave();

writeStroke(stroke);
writeTransform(at);
writePaint(color);
} catch (IOException e) {
handleException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void paintComponent(Graphics g) {
vg.fillRect(0, 0, dim.width, dim.height);

int nx = 6;
int ny = 6;
int ny = 7;

int dw = dim.width / (nx + 1);
int dh = dim.height / ny;
Expand Down Expand Up @@ -216,8 +216,27 @@ public void paintComponent(Graphics g) {
svg2.fill(clippedPath);
svg2.dispose();
}
svg.dispose();

// Java setClip and Draw
svg = (VectorGraphics) vg.create();
svg.drawString("JavaSetClip", 10, 10 + 10 + 6 * dh);
svg.scale(factor, factor);
svg.translate(10 / factor, 10 / factor + 6 * dh / factor);
for (int i = 0; i < nx; i++) {
svg.translate(dw / factor, 0);
VectorGraphics svg2 = (VectorGraphics) svg.create();
svg2.setColor(Color.red);
svg2.setLineWidth(1.0 / factor);
svg2.draw(clip[i]);
svg2.setColor(Color.blue); // color is set before setClip to check that it is taken over
svg2.setClip(clip[i]);
svg2.setLineWidth(3.0 / factor);
svg2.draw(path[i]);
svg2.dispose();
}
svg.dispose();

}

public static void main(String[] args) throws Exception {
Expand Down

0 comments on commit 734c9fb

Please sign in to comment.