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.
This PR introduces the concept of chunks. A chunk is a free-standing collection of indirect objects that can be written to independently from the main writer. It can then be added to it (or another chunk) later. This makes it possible to write two things at once. The main PDF writer derefs to a chunk so it exposes all its methods.
Moreover, this adds a renumbering routine to chunks. This routine remaps IDs of indirect objects and indirect references in a chunk after it has already been written. It does that with just enough knowledge of the PDF syntax to find indirect references and skip "false positives" (like
(2 0 R)
where a reference-like thing is in a string).The main motivation for renumbering is to be able to create a stable, memoizable chunk for an SVG in Typst and then only copy it over to the main PDF during writing, patching up IDs. However, it could also be potentially useful for including one PDF file in another without any ID collisions. For that to work, we'd need to add a routing that parses a full PDF file into a
Chunk
(which shouldn't be too hard since the top-level syntax is not that complex).In order to keep the naming consistent, this PR also renames the main
PdfWriter
toPdf
(in line withContent
and the newChunk
). TheWriter
suffix isn't used anywhere the crate anymore now. It also makes the written strings a bit nicer (motivated by being able to test unescaped balanced parentheses in the renumbering) and refactors the intergration tests into unit tests. As a final thing, it removes the unnecessary (and unexported)Type
trait.