Open AlexGeller1 opened 1 month ago
What library are you using, which defines a stroke other than the BasicStroke? I would at least like to have a possibility to test this.
Thanks for the quick response. It is not due to a library, it is my own code that has that issue. I derived strokes from the interface java.awt.Stroke because I need the stroke to be serializable and BasicStroke isn't (https://bugs.openjdk.org/browse/JDK-4305099). I can provide a test.
Hmm, why are you not just deriving from BasicStroke and let that subclass implement Serializable?
If you could just provide a very simple test, this would be helpful.
Regarding a test case, I modified the test PdfBoxGraphics2dTest.testLineWithRotation() as follows:
diff --git a/dev/lib-rototor-graphics2d/pdfbox-graphics2d/graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2dTest.java b/dev/lib-rototor-graphics2d/pdfbox-graphics2d/graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2dTest.java
index b60f8b1679..a72bee6fb3 100644
--- a/dev/lib-rototor-graphics2d/pdfbox-graphics2d/graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2dTest.java
+++ b/dev/lib-rototor-graphics2d/pdfbox-graphics2d/graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2dTest.java
@@ -470,7 +470,7 @@ public class PdfBoxGraphics2dTest extends PdfBoxGraphics2DTestBase
@Override
public void draw(Graphics2D gfx)
{
- gfx.setStroke(new BasicStroke(5f));
+ gfx.setStroke(new MyBasicStroke(5f));
float centerX = 200;
float centerY = 200;
@@ -485,5 +485,17 @@ public class PdfBoxGraphics2dTest extends PdfBoxGraphics2DTestBase
}
});
}
+ static class MyBasicStroke implements java.awt.Stroke
+ {
+ final BasicStroke stroke;
+ MyBasicStroke(float width)
+ {
+ stroke=new BasicStroke(width);
+ }
+ public java.awt.Shape createStrokedShape(java.awt.Shape p)
+ {
+ return stroke.createStrokedShape(p);
+ }
+ }
}
Regarding implementing Serializable, yes it is possible but the class is immutable making it clunky. But yes, that is definitely an option.
It seems that currently only java.awt.BasicStroke is supported. Something like this could perhaps be added to the code: