Repository navigation
PDF: write each sheet's page as it is plotted, holding one display list at a time (part of #1068) - #1587
PDF: write each sheet's page as it is plotted, holding one display list at a time (part of #1068)#1587graficaeusebio-cloud wants to merge 2 commits into
Conversation
…st at a time (part of storytold#1068)
FredApps
left a comment
There was a problem hiding this comment.
The idea is sound, and I like the fallback: if the fonts at the end differ from the plan the pages were written with, it plots again. The measured gain is clear (447 MB → 134 MB). Two gaps in the tests keep me from approving a refactor of PDF output.
- Nothing shows the output is unchanged. The new test
sheets_written_one_by_one_share_the_fonts_of_the_file(crates/io/tests/pdf_text.rs) checks one font file, font indices and the text operators for one drawing. The old path (assembleover all pages) is still in the code. A test that builds a multi-sheet drawing, plots it both ways and compares the bytes would pin that the incremental writer gives the same file, including layers, page labels and annotations, whichWriter::pagenow writes per page. - The fallback is not run by any test.
Gather::addplans only againstMAX_FONTSand an empty subset (fonts.rs:120), whileFonts::buildalso appliesMAX_FONT_BYTES(line 67) and subsets with the real glyphs. A drawing that goes over the 64 MB font data cap, or whose subset fails, reaches theNonebranch inpdf_items, which re-plots and callsassemble. That branch is the one place the output could diverge, and it has no test. A small test that forces it (for example with a face whose subset fails once it has glyphs) would cover it.
With those two I'd approve. Hosted CI: only CodeRabbit has run on this head, so I would also ask for a local run of the cadcraft-io tests.
…cap fallback - tests/support/ttf.rs: the synthetic TrueType font, shared by tests/pdf_text.rs and the unit tests of src/pdf.rs. - pdf_items splits into write_items (pages written as plotted) and write_held (every sheet held, then assemble); the cap on font data is a parameter so a test can reach it. - A two-sheet drawing with real text, layers shared across pages (one off), page labels and link annotations gives the same bytes both ways, compressed or not. - With the font data cap at 1 byte the plan made while writing does not hold, and the output is the held file with the text drawn as outlines.
|
Thanks for the review, @FredApps. #2029 has since replaced the PDF writer with craft-pdf's krilla writer, so this branch no longer applies as it stands. I'll redo the page-by-page writing on top of the new writer and carry over the two tests you asked for: pages written as they are plotted match the file assembled from every sheet, and fonts over the data cap are planned as text and then plotted again as outlines. (Written by Claude Code, an AI agent, on behalf of belchiordameao-cmd.) |
|
Correction to my comment above: having read #2029 properly, there is nothing left to redo here. In main, The two tests you asked for, @FredApps, pinned this PR's mechanism: the incremental writer against the So this PR is superseded by #2029 and can be closed. Thanks for the review. (Written by Claude Code, an AI agent, on behalf of belchiordameao-cmd.) |
FredApps
left a comment
There was a problem hiding this comment.
Re-review of 5c0de15 (my last review was on 28dacbb).
Earlier findings: both fixed in this head.
- Same output both ways:
pages_written_as_plotted_match_the_file_assembled_from_every_sheetincrates/io/src/pdf.rsplots a two-sheet drawing with real text, shared and off layers, page labels and links throughwrite_itemsandwrite_held, compressed and not, and compares the bytes. - Fallback is tested:
fonts_over_the_data_cap_are_planned_as_text_then_plotted_again_as_outlinesmakes the font-data cap a parameter, sets it to 1 byte, checks that the plan does not hold, and checks that the result is the held file with the text drawn as outlines.
Thanks, that is what I asked for.
Still open: main already does this, and the PR conflicts in all three files.
The day after this commit, #2029 (merged 24 Oct, "PDF: plot with craft-pdf's krilla writer") replaced the hand-written PDF writer. Writer, assemble, Gather, the hand-written subsetter and the 64 MB MAX_FONT_BYTES this PR changes are gone from main. On main (11d66cc), write_pdf in crates/io/src/pdf.rs (lines 429-480) builds each sheet's display list, writes it as its page and drops it before the next sheet (line 464 loop, write_page at line 474). Fonts are now picked one face at a time as glyphs are written (Fonts::font in crates/io/src/pdf/fonts.rs), and krilla subsets them when the file is finished. So no plan is made early and no re-plot is needed. The only retry left is the text-as-outlines one for a font krilla refuses. #2029's description lists this PR as "Covered: pages are written one at a time".
git merge-tree with current main conflicts in crates/io/src/pdf.rs, crates/io/src/pdf/fonts.rs and crates/io/tests/pdf_text.rs, and GitHub reports the PR as CONFLICTING. A rebase would remove the whole change, because the code it edits no longer exists. The new tests can't carry over either: they compare two writer paths that main no longer has.
I suggest closing this PR as superseded by #2029. #1068 stays open for the rest of the plot memory work (PNG and Plot Preview). If you think the PDF path on main still holds more than one sheet's display list somewhere, please open a new PR against the krilla writer with a test that shows it.
CI: only CodeRabbit has reported on this head. The CI and SonarCloud runs are waiting for approval, and I have not approved them because the PR conflicts with main.
Multi-sheet PDF export kept every sheet's display list alive until the whole document was written. This writes each page right after it is plotted and drops its display list before the next sheet; fonts are tracked incrementally.
Measured on a synthetic 20-sheet / 200k-line drawing (release build, same 32.3 MB output): peak RSS delta 447 MB on main vs 134 MB with this change (~-70%).
Existing cadcraft-io tests pass; pdf_text tests extended.
Part of #1068.
🤖 Generated with Claude Code
Summary by CodeRabbit