Write rectangles with the precision of real numbers - #385
Open
AlexanderV wants to merge 1 commit into
Open
Conversation
Write(PdfRectangle) rounded the coordinates to three decimal places, while Write(double) and Write(PdfReal) use seven. Writing a document therefore changed its geometry, e.g. the /MediaBox of an ISO A4 page created by another producer became 595.276 instead of 595.2756. That is a change of the page for every digital signature the document already contains: adding a second signature to a signed document made validators report the pages of the first revision as changed. /MediaBox, /CropBox, /BleedBox, /TrimBox, /ArtBox, /Rect and /BBox now round-trip unchanged. Note that the coordinates are written as they are, while Write(double) converts a real number to a single first. Doing that for rectangles as well would defeat the purpose, because the single nearest to 595.2756 is 595.27557, which does not round-trip either. An alternative would be to write the value that was parsed, as PRESERVE_PARSED_VALUES does for numbers. That preserves every number of a file and not only rectangles, but it needs the parsed value to survive until the document is written, which is not the case for rectangles today.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PdfWriter.Write(PdfRectangle)rounds the coordinates to three decimal places, whileWrite(double)andWrite(PdfReal)use seven:Writing a document therefore changes its geometry. The
/MediaBoxof an ISO A4 page created by another producer becomes595.276instead of595.2756.For a signed document that is a changed page: adding a second signature to a document that already contains one makes validators report the pages of the first revision as changed.
With seven decimal places
/MediaBox,/CropBox,/BleedBox,/TrimBox,/ArtBox,/Rectand/BBoxround-trip unchanged.Why not convert to a single first, as
Write(double)does? That would defeat the purpose: the single nearest to595.2756is595.27557, which does not round-trip either.Alternative you may prefer: writing the value that was parsed, as
PRESERVE_PARSED_VALUESalready does for numbers. That preserves every number of a file and not only rectangles, but it needs the parsed value to survive until the document is written, which is not the case for rectangles today. Happy to go that way instead if you consider it the better fix.Test (
IO/WriterTests.cs): a page with a/MediaBoxof four decimal places is written and read back; the test checks both the bytes in the file and the values after reading.Verified on top of current
master: fullPdfSharp.Testssuite green (253 passed, 0 failed).This PR is independent of my other PRs; each of them applies to
masteron its own.