JFreeSVG 1.3

A discussion forum for JFreeSVG (a fast, lightweight, SVG generator for the Java platform).
Locked
david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

JFreeSVG 1.3

Post by david.gilbert » Tue Sep 24, 2013 7:34 pm

A new version of JFreeSVG is now available to download. From the README file:

Code: Select all

Version 1.3 (24 September 2013)

- implemented getDeviceConfiguration() method;
- fixed clipping bug with transforms applied after clip is set;
- fixed bug with setClip(null);
- fixed "not well-formed" parsing issue for Firefox;
- set preserveAspectRatio attribute for images.
JFreeSVG is dual licensed under the GNU AGPL and a commercial licence (for a limited time, the commercial license is included free with purchases of the JFreeChart Developer Guide).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Fluxim
Posts: 4
Joined: Tue Oct 22, 2013 1:56 pm
antibot: No, of course not.

Font rendering/kerning

Post by Fluxim » Tue Oct 22, 2013 2:29 pm

Dear JFree developers

First, thank you for you effort!
We are using JFreeChart in our software and recently bought the developer guide including JFreeSVG. It was my hope that we could replace batik.
The library works nicely and easy so far, but there seems to be a problem with the font rendering. When exporting a PNG or an SVG generated with Batik the font looks fine. However with JFreeSVG (and OrsonPDF) the kerning or space between characters are off at some places. This image shows a comparison (SVG rendered in Firefox:

Image

Is there a way to improve the rendering quality? I have also noticed that JFree seems to convert text to vectors (which also increases the file size). The output from Batik contains this tag:

Code: Select all

text-rendering="optimizeLegibility"
Maybe setting it somewhere could help?

Thanks for your support!

Here is the same plot exported with different methods (the problem is visible best at the y axis label):

PNG:
Image

SVG (Batik):
Image

SVG (JFreeSVG):
Image
Last edited by Fluxim on Wed Oct 23, 2013 2:23 pm, edited 1 time in total.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: JFreeSVG 1.3

Post by david.gilbert » Wed Oct 23, 2013 10:07 am

Thanks for the feedback. I'll add the 'text-rendering' hint to the text element generated by the drawString() method, and provide a (Java2D) rendering hint to allow the value to be configured. But I think that will only help with horizontal text, since rotated text is being converted to vectors (as you noticed). I need to check, but I believe that's happening within JFreeChart because it is using a TextLayout somewhere. Hopefully we can find a way to improve this text.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: JFreeSVG 1.3

Post by david.gilbert » Thu Oct 24, 2013 10:25 am

I've uploaded a new version of JCommon (1.0.21) to the JFreeChart project page at SourceForge. This has modifications to the TextUtilities class which should result in some improvements for both JFreeSVG and OrsonPDF. Most strings were being drawn to the Graphics2D target using TextLayout - now by default they will go directly via the drawString() method. This results in much smaller SVG and PDF files, and hopefully should also improve the rendering quality for you.

JFreeSVG 1.4 will include the new rendering hint to control the 'text-rendering' attribute in the SVG output. I don't know if you'll need this to see quality improvements and, in any case, it will take me a bit longer to get a new JFreeSVG release done. Let me know if you see improvements just from the changes in JCommon.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: JFreeSVG 1.3

Post by david.gilbert » Thu Oct 24, 2013 4:14 pm

JFreeSVG 1.4 is now uploaded to SourceForge. It has the addition of the text-rendering attribute in the SVG text element, the rendering hints to configure this via SVGGraphics2D, plus a bug fix for the style attribute that was causing some bad output in Firefox (I found this while testing the changes). Let me know how it goes for you.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Fluxim
Posts: 4
Joined: Tue Oct 22, 2013 1:56 pm
antibot: No, of course not.

Re: JFreeSVG 1.3

Post by Fluxim » Tue Oct 29, 2013 11:33 am

Dear david.gilbert

Thank you very much for the prompt reaction!
Both JFreeSVG and OrsonPDF now generate beautiful images. :)

The only problem remaining is the font type when saving as SVG. In our case we would like to use a sans-serif font. When comparing the output with the batik SVG the difference seems to at "SansSerif" instead of "sans-serif".
With this workaround it works fine however:

Code: Select all

g2.getSVGDocument().replaceAll("SansSerif", "sans-serif")
Best regards,
Fluxim

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: JFreeSVG 1.3

Post by remiohead » Tue Dec 17, 2013 2:52 pm

Some feedback/ideas based on scenarios I've come across in my own usage:

1. To be able to specify a url for an image (possibly a setImageUrl(String url) method in SVGGraphics2D). It would be the responsibility of the caller to set the image source prior to calling drawImage() and clear afterwards.

2. To be able to specify an ID for the next element drawn (for example, useful for attaching event handlers in the browser). Perhaps an interface IdProvider with a method called getId(Object context) or something like that which can be set in SVGGraphics2D.

3. Not all of the gradients supported in JFreeChart work yet (GradientPaintTransformType.CENTER_VERTICAL and GradientPaintTransformType.CENTER_HORIZONTAL).

What is the best way for us to support this project? We brought the JFreeChart developer guide a few years back, but we will gladly purchase it again if that's how you're taking contributions.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: JFreeSVG 1.3

Post by david.gilbert » Wed Dec 18, 2013 12:12 pm

Fluxim wrote:The only problem remaining is the font type when saving as SVG. In our case we would like to use a sans-serif font. When comparing the output with the batik SVG the difference seems to at "SansSerif" instead of "sans-serif".
Thanks for the feedback. This will be fixed for the JFreeSVG 1.5 release, I've introduced a FontMapper (assigned to the SVGGraphics2D) and the default implementation will map the Java logical fonts ("Dialog", "DialogInput", "SansSerif", "Serif" and "Monospaced") to the equivalent SVG generic fonts ("serif", "sans-serif", "monospace").
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: JFreeSVG 1.3

Post by david.gilbert » Wed Dec 18, 2013 12:33 pm

remiohead wrote:1. To be able to specify a url for an image (possibly a setImageUrl(String url) method in SVGGraphics2D). It would be the responsibility of the caller to set the image source prior to calling drawImage() and clear afterwards.
At the moment there is a RenderingHint (SVGHints.KEY_IMAGE_HANDLING) to control whether the image is embedded or referenced. The referencing option isn't very flexible (there isn't a way to specify a custom URL) but I think it could be modified to support what you are looking for. I'll try some options.
remiohead wrote:2. To be able to specify an ID for the next element drawn (for example, useful for attaching event handlers in the browser). Perhaps an interface IdProvider with a method called getId(Object context) or something like that which can be set in SVGGraphics2D.
This could also be achieved by adding a new rendering hint (the advantage of using RenderingHints is that you can add them to any Graphics2D and they will be silently ignored by different Graphics2D implementations, so your code doesn't need to check for SVGGraphics2D specifically). I'm undecided yet about whether to validate the ids (for uniqueness) or leave that as a responsibility for the caller. Any thoughts?
remiohead wrote:3. Not all of the gradients supported in JFreeChart work yet (GradientPaintTransformType.CENTER_VERTICAL and GradientPaintTransformType.CENTER_HORIZONTAL).
I'll take a look at this. I have a feeling it is not completely straightforward, but I'll see.
remiohead wrote:What is the best way for us to support this project? We brought the JFreeChart developer guide a few years back, but we will gladly purchase it again if that's how you're taking contributions.
I've created a couple of products for sale so please take a look at those and see if there is something that would be useful for you. Orson Charts is a 3D chart library for Java (and soon Android), and OrsonPDF is similar to JFreeSVG but generates PDF output. Another useful contribution is just to make people aware of JFreeChart, JFreeSVG, Orson Charts and Orson PDF (via word-of-mouth, blogs, Twitter etc). I have a limited advertising budget and, in any case, word of mouth is the best.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: JFreeSVG 1.3

Post by remiohead » Wed Dec 18, 2013 2:40 pm

Thanks for your replies David.
david.gilbert wrote:I'm undecided yet about whether to validate the ids (for uniqueness) or leave that as a responsibility for the caller. Any thoughts?
The id is required to be unique so validating them is the right thing to do.

Locked