You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The draw(Shape) method, when the RenderingHints.KEY_STROKE_CONTROL is set to something other than RenderingHints.VALUE_STROKE_PURE, alters the state of input Rectangle2D and Line2D shapes. The code below demonstrates this:
import java.awt.RenderingHints;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
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;
public class DrawNormalize extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("DrawStrokeNormalize");
Group root = new Group();
Canvas canvas = new Canvas(640, 480);
GraphicsContext gc = canvas.getGraphicsContext2D();
FXGraphics2D g2d = new FXGraphics2D(gc);
/*
* Set the stroke control rendering hint to something other than
* VALUE_STROKE_PURE to trigger the issue.
*/
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE);
Line2D.Double line = new Line2D.Double(10.15, 10.15, 470.92, 470.92);
printLine(line);
g2d.draw(line);
printLine(line); // line's state has changed
Rectangle2D.Double rect = new Rectangle2D.Double(20.57, 20.57, 590.01, 430.3);
printRect(rect);
g2d.draw(rect);
printRect(rect); // rect's state has changed
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
static void printLine(Line2D line) {
System.out.println(String.format("(%5.3f, %5.3f) -> (%5.3f, %5.3f)",
line.getX1(), line.getY1(), line.getX2(), line.getY2()));
}
static void printRect(Rectangle2D rect) {
System.out.println(String.format("(%5.3f, %5.3f) -> (%5.3f, %5.3f)",
rect.getMinX(), rect.getMinY(),
rect.getMaxX(), rect.getMaxY()));
}
}
It's not clear that this is exactly a problem that needs to be addressed, but we found the behavior surprising. It was straightforward enough to work around in our code, but I've attached a patch for your consideration that I believe corrects the issue while preserving the original intent of the source:
Thanks for the report. I fixed the issue in the same way that you suggested, but I made use of the existing 'recyclable' line and rect objects that are used elsewhere in the code (this should minimise garbage generation in cases where many shapes are drawn).
The draw(Shape) method, when the RenderingHints.KEY_STROKE_CONTROL is set to something other than RenderingHints.VALUE_STROKE_PURE, alters the state of input Rectangle2D and Line2D shapes. The code below demonstrates this:
It's not clear that this is exactly a problem that needs to be addressed, but we found the behavior surprising. It was straightforward enough to work around in our code, but I've attached a patch for your consideration that I believe corrects the issue while preserving the original intent of the source:
fxgraphics2d.patch.txt
The text was updated successfully, but these errors were encountered: