Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setClip incorrectly restores prior font, paint, color, and stroke #6

Closed
turnef opened this issue Jul 2, 2018 · 2 comments
Closed

Comments

@turnef
Copy link

turnef commented Jul 2, 2018

The setClip() method, when invoked after font, paint, color or stroke details are altered, incorrectly restores the prior state. The following code demonstrates the issue:

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Rectangle;

import org.jfree.fx.FXGraphics2D;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.Stage;

/**
 * Simple code example demonstrating the issue with setClip()
 */
public class SetClipIssue extends Application {

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		primaryStage.setTitle("SetClipIssue");
		Group root = new Group();
		Canvas canvas = new Canvas(640, 480);
		GraphicsContext gc = canvas.getGraphicsContext2D();

		FXGraphics2D g2d = new FXGraphics2D(gc);
		g2d.setFont(g2d.getFont().deriveFont(20f));
		g2d.setColor(Color.RED);
		g2d.setStroke(new BasicStroke(2.0f));
		g2d.setClip(new Rectangle(50, 50, 540, 380));
		g2d.drawString("Red 20pt", 100, 100);
		g2d.draw(new Rectangle(55, 75, 25, 25));

		g2d.setFont(g2d.getFont().deriveFont(30f));
		g2d.setColor(Color.BLUE);
		g2d.setStroke(new BasicStroke(1.0f));

		/*
		 * This clip set incorrectly restores the previous state of color, font, and
		 * stroke.
		 */
		g2d.setClip(new Rectangle(49, 49, 542, 382));
		g2d.drawString("Blue 30pt?", 100, 200);
		g2d.draw(new Rectangle(55, 175, 25, 25));

		root.getChildren().add(canvas);
		primaryStage.setScene(new Scene(root));
		primaryStage.show();
	}

}

This patch resolved the issue in both the sample code above and in our application where we originally discovered the problem:

fxgraphics2d_patch.txt

@jfree
Copy link
Owner

jfree commented Jul 4, 2018

Good catch, your fix also looks good.

@jfree
Copy link
Owner

jfree commented Jul 4, 2018

Fix will be included in the 1.7 release.

@jfree jfree closed this as completed Jul 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants