knowm / XChart

XChart is a light-weight Java library for plotting data.
http://knowm.org/open-source/xchart
Apache License 2.0
1.5k stars 397 forks source link

Draw text as text rather than converting to curves first #499

Open PetrSlaby opened 4 years ago

PetrSlaby commented 4 years ago

In our software, we produce printer formats like PDF, PostScript, PCL or AFP. We have Graphics2D implementations for each of the supported formats. When I try to integrate XChart, all the texts it produces are generated using something like

public void paint(Graphics2D g) { ... Shape shape = textLayout.getOutline(null); ... g.fill(shape); }

Instead of drawing the text using textLayout.draw(Graphics2D g2d, float x, float y).

This way, I end up with a lot of curves and shapes produced in my output format, instead of simple instructions to set the font and print text. The output file grows bigger, more memory is needed to produce it and the printer needs more time and memory to consume it. Also, in PDF, the texts are not accessible - a screen reader cannot read them and it is not possible to select and copy the text.

Is there a reason for using textLayout.getOutline() instead of textLayout.paint()? Should I prepare a patch which makes this configurable so the user of the library could decide which of the two methods to use? (But that only makes sense if the current method of drawing the text has advantages in some situations). Or is this something you would not like to change in general and any attempt to prepare a patch/pull request would be a waste of time?

Mr14huashao commented 4 years ago

@PetrSlaby Please upload all your codes for the problem as an attachment, such as Demo or test cases or the whole project, and so on,to help you analyze this problem. Thank you. @timmolter Please help see if this plan is feasible.Thank you.

timmolter commented 4 years ago

@PetrSlaby It was years ago since I coded that and I cannot remember if there was a reason I chose getOutline. I did whatever worked. If you can change the code to use paint and it doesn't break things, I'm fine with that. I'd rather not have two methods to use and have the user need to choose. If you can make it better with paint, then I'm happy to accept the changes.