Repository navigation
A PDF cut short loses the share of its pages asked for #241
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package pdf | ||
|
|
||
| // The layout of a document a damage will cut: its padding split around the | ||
| // objects. | ||
|
|
||
| import "github.com/donislawdev/TestingFilesGenerator/internal/format" | ||
|
|
||
| // largestOffset is the largest offset a cross reference entry can carry. ISO | ||
| // 32000-1 section 7.5.4 writes each one in ten digits. | ||
| const largestOffset = 9_999_999_999 | ||
|
|
||
| // splitForACut is how much of the padding m has behind its trailer goes in | ||
| // front of its objects instead, for a document a damage will cut after its | ||
| // first cutAt bytes of whole, so that the cut keeps the share of the objects it | ||
| // keeps of the whole file (format.Request.CutAt). It returns the padding in | ||
| // front and the padding left behind, and none in front for a document nothing | ||
| // cuts. | ||
| // | ||
| // With all of the padding behind the trailer, as a document nothing cuts has | ||
| // it, a large document cut at any share kept every object and lost only | ||
| // padding. A comment may stand between the header lines and the first object as | ||
| // well, and the readers measured take it there as they take it behind the | ||
| // trailer (docs/TRUNCATE-2026-11-11.md section 12). | ||
| // | ||
| // The padding in front moves every object, so the offset startxref carries | ||
| // grows with it and can gain a digit, which the padding behind gives up. Each | ||
| // side is nothing or a comment of at least minComment bytes. Where the sides | ||
| // cannot land exactly the front takes a byte more, which cuts a byte more of | ||
| // the objects - the "at least" missing promises - or, where a digit gained | ||
| // leaves that no room, a byte less. Where the end is longer than the part the | ||
| // cut takes, all of the padding goes in front, and the cut falls in the end. | ||
| // An object can start no later than largestOffset, so in a document of more | ||
| // than about 9.3 GiB the front stops there and the cut keeps more of the | ||
| // objects than the share. | ||
| func splitForACut(m memo, whole, cutAt int64) (front, back int64) { | ||
| if m.padLen == 0 || cutAt <= 0 || cutAt >= whole { | ||
| return 0, m.padLen | ||
| } | ||
| want := format.PaddingInFront(m.at.objects, m.at.xref-m.at.objects, cutAt, whole) | ||
| if want <= 0 { | ||
| return 0, m.padLen | ||
| } | ||
| // padding is all of the padding with front of it in front: the closing | ||
| // lines carry the offset front moves. | ||
| padding := func(front int64) int64 { | ||
| return whole - int64(len(m.prefix)) - int64(len(closing(m.at.xref+front))) | ||
| } | ||
| fits := func(front int64) bool { | ||
| back := padding(front) - front | ||
| return front >= minComment && m.at.xref+front <= largestOffset && (back == 0 || back >= minComment) | ||
| } | ||
| front = min(max(want, minComment), largestOffset-m.at.xref) | ||
| if padding(front) < front { | ||
| front = padding(front) | ||
| } | ||
| for _, f := range []int64{front, front + 1, front - 1} { | ||
| if fits(f) { | ||
| return f, padding(f) - f | ||
| } | ||
| } | ||
| return 0, m.padLen | ||
| } |
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.