Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinate precision issues in vector elements inside produced PDF #2

Open
istinnstudio opened this issue Jan 18, 2022 · 2 comments
Open

Comments

@istinnstudio
Copy link

istinnstudio commented Jan 18, 2022

It seems there is an issue when translating java2D graphics to PDF. Some lines are getting off their real precise coordinates. Same graphics exported to SVG from jfreeSVG are coordinate accurate. There might be some kind of optimization (or java variable type setting, float to double maybe) that actually reduces the number of coordinate digits and as a result some points are off their actual position in the used grid. I have noted such behavior in inkscape 's SAVE optimization algorithms that optionally can reduce the SVG size by reducing the number of digits used in coordinates. For some designs this might be and look OK, but for coordinate accurate or complex graphics this might lead to this artifact. You can consider this as a high priority bug as it can distort the produced graphics data with irreversible loss in specific cases.

There should be a way to improve the accuracy of the exported vectors, and this could be selectable scenarios by entering a new parameter hint value upon the fundamental call of graphics, something like
graphicsPDF.setRenderingHint(PDFHints.KEY_VECTOR_ACCURACY,
PDFHints.VALUE_DRAW_VECTOR_ACCURACY_LOW/MED/HIGH);

image
image

@istinnstudio
Copy link
Author

istinnstudio commented Jan 19, 2022

I've searched a bit the source and with a bit of luck I have found the coordinate digit accuracy setting.
I have tested translations to PDF with the new setting and they seem perfect.
It resides here:
package org.jfree.pdf.stream;
GraphicsStream.java

changed digit pattern from 2 to a higher value to increase coordinate precision
this.geometryFormat = new DecimalFormat("0.##", dfs);

to

this.geometryFormat = new DecimalFormat("0.############", dfs); // NEW 12 digit

There might be more changes to take place, but this one just eliminates the described artifact

@istinnstudio istinnstudio changed the title Coordinate accuracy issues in vector elements inside produced PDF Coordinate precision issues in vector elements inside produced PDF Jan 19, 2022
@jfree
Copy link
Owner

jfree commented Jan 19, 2022

Good spot! A while back there was also a pull request for JFreeSVG to increase performance in the formatting of coordinates, this might also be interesting to look at here: jfree/jfreesvg#30

@jfree jfree reopened this Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants