Hello, Ivhabe created some time ago an OpenSource project called jfcClnvertercwhichvtefurect the Jz aFX calls to a Graphics2D context. I don’t know if it answers at least partially to this need. The project is here: https://sourceforge.net/projects/jfxconverter/
Hervé Sent from my iPhone > On Nov 2, 2020, at 14:19, Bruce Johnson <nmrv...@mac.com> wrote: > > > A variety of packages (for example, VectorGraphics or JFreeSVG) exist that > allow redirecting Java2D drawing to output other than the Java2D canvas. > > These work by extending java.awt.Graphics2D. By passing the extended > Graphics2D object into a paint method, output can be redirected to a file > (.svg, .pdf, etc.). > > The GraphicsContext class of JavaFX serves a similar function to Graphics2D > of java.awt, but because it is a final class it cannot be extended to create > similar functionality as found in VectorgGraphics or JFreeSVG. > > This is a serious limitation (at least as far as I can tell) to JavaFX > applications. It would be highly desirable to be able to redirect drawing on > a Canvas to other output formats such as vector graphics files (.svg, .pdf > etc.). > > I currently work around this by using composition. I have a Java interface > that has most methods of GraphicsContext. Then a GraphicsContextProxy class > implements the interface and contains an instance of GraphicsContext. This > class is used for drawing to the Canvas. I’ve then created a > SVGGraphicsContext and PDFGraphicsContext that implement the interface and > these can be used to draw to .svg or .pdf files. > > This works, but means that all code that draws on the canvas has to be > rewritten to take the GraphicsContextInterface rather than the normal > GraphicsContext. > > It would be much simpler if > 1) GraphicsContext was not final and could be extended. > or > 2) A GraphicsContextInterface existed that GraphicsContext implemented. > Developers could then have alternative GraphicsContext implementations that > implemented that interface. This would require canvas drawing code to be > written to use the interface, but would still be very useful. > > Either solution could (I think) be easily implemented in JavaFX without > breaking existing code and add a significant advance to the toolkit. > > If there are alternative solutions to the problem, that would allow exporting > canvas drawing to vector graphics files without requiring a change to the > code that draws to the canvas, I’d appreciate hearing them. > > — Bruce >