Skip to content

Drawing export: a sheet as a vector PDF, geometry only, as a starting point for the PDF work (#4890) - #7626

Merged
bherbruck merged 11 commits into
tangency-labs:drawingsfrom
CamWight:paper-pdf-4890-p1
Nov 17, 2026
Merged

bherbruck merged 11 commits into
tangency-labs:drawingsfrom
CamWight:paper-pdf-4890-p1

Conversation

@CamWight

@CamWight CamWight commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Change

A drawing sheet can now be written as a vector PDF: one page the sheet's size, with its lines, arcs, curves, dashes and fills. io::paper::paper_pdf(scene, options) sits beside paper_svg and paper_png and reads the same prepared paper scene. Text, pictures and the drawing.export command come in their own PRs (below).

Part of #4890. This is the first of a series. #9647 (the pages of one PDF) stacks on it, and then come text (P2, @0xlillith) and the drawing.export PDF command (EX3, @DevonHope).

  • The file. A catalog and one page whose MediaBox is the sheet in points (A3 is [0 0 1190.5511 841.8898]).
    • The content stream is deflated.
    • The Info dictionary has the Producer ("SolidCraft "), and the Title when one is given.
    • CreationDate and ModDate come only from PdfOptions::output_time, never from the clock, so a scene always gives the same bytes.
  • Numbers. The scene is written on a 10 nm grid, as millimetres with up to five decimals (ISO 32000-1 Annex C's precision), inside one cm that scales millimetres to points. y is up on the page as in the scene, so nothing flips.
  • Curves.
    • Lines and cubics are written as they are, and a parabola is raised to a cubic.
    • An arc is cut into cubics that stay within 1e-4 mm of it, with the rounding onto the grid included: 3 a quarter turn at r = 40 mm, 5 at 5 m.
  • Paint. Strokes have their width, butt caps, miter joins and a miter limit of 4, as SVG and PNG draw them, and dashes are written with d. Fills are black and even-odd. Each width and dash pattern is written only when it changes.
  • Layers (@0xlillith's work). Each paper object kind that paints something is one optional-content layer, named as in DXF, and all start visible. Groups of one kind in a row share one marked run. PdfOptions::layers = false writes the same marks without layers.
  • Limits. Every append is checked against the drawing's byte limit before the buffer grows, so a refusal returns no partial PDF. A page under 3 pt a side, a title over 1,000 characters, and a date past the year 9999 are refused.
  • Text and pictures in the scene are passed over: geometry only, for now.

Changes a default: no

This adds a new writer, and nothing that exists writes differently.

crates/geom shrinks. There were two choices: keep the line flattener in geom, or move it to io. @CamWight chose the move, and it is commit 15b7937e98. The flattener (paper/flatten.rs) and the rule that turns a walked piece into its curve (Piece::seg) move from geom into io/src/paper/flatten.rs. They are pub(super) there, so io's public API gains nothing. Their only callers are io's PNG and PDF writers, so geom loses them with no copy left behind (+13/−186 lines). The 10 nm grid is now io's own Grid::new(1e5), and a refusal of it is a typed IoError.

Test change: slivers_and_radii_are_in_the_grids_own_steps (crates/geom/src/paper_tests.rs) checked the walked cubics against an ellipse by flattening them. The flattener is now in io, so the test samples 101 points on each cubic directly, with the same bound (error * 1.2).

Decisions

Each was read first-hand in ISO 32000-1.

  1. Numbers are our own text on a 10 nm grid, not pdf-writer's 32-bit numbers. pdf-writer's content calls take f32: 1.2e-4 mm coarse at A0, too coarse for 1e-4 mm curves. pdf-writer still writes everything around the content: objects, cross-references, page, Info and dates. SVG and PDF share one number rule (io::paper::push_mm).
  2. Arcs are cut by their radius. One cubic a quarter turn is about 2.7e-4 × the radius off (0.027 mm at r = 100 mm). So each piece gets as many 4/3·tan(θ/4) cubics as keep the exact largest error, r·(2/27)·sin⁶(θ/4)/cos²(θ/4), plus rounding, within 1e-4 mm. A piece may turn a little past a quarter once its ends are rounded onto the grid (@DevonHope's finding, 16 Nov), so up to a half turn is accepted, in cubics of at most a quarter turn each.
  3. No minimum width beyond the walk's. A PDF has no pixels, and w is never 0: 8.4.3.2 says 0 means one device pixel.
  4. Two new crates: pdf-writer 0.15.0 (MIT OR Apache-2.0) and ryu 1.0.23 (Apache-2.0 OR BSL-1.0). flate2 was already in the tree. They are covered by cargo xtask licences.
  5. No PDF reader as a test dependency. The tests read the file with their own small reader: inflate, operators, numbers and cross-references by byte offset.
  6. Curve maths in io. The arc-to-cubic conversion uses sin/tan in io, as the SVG and PNG writers turn paper curves into their own formats in io. Drawing maths stays in drawing code, not solidcore.

What the tests can't reach

  • Other readers. pdf.js, pypdf and PDFium have read the files (below). Chrome has opened a sheet. No other viewer has.
  • Printing. The page size is checked in the MediaBox, not on paper.
  • The drawing size cap needs a scene of tens of millions of numbers. The same check is tested with small limits instead.

Validation

Targeted checks, in --profile ci. The head is 15b7937e98, on drawings 76eb8bfc98:

  • The move commit on its earlier base: io paper tests 80 passed, geom paper tests 71 passed.
  • The whole stack rebased, with Drawing export: a drawing's sheets as the pages of one PDF (#4890) #9647 on top (f870531442): io paper 85 passed and geom paper 71 passed. This head builds on its own (cargo check -p solidcraft-io).
  • The byte pins are unchanged. The A3 sample is still 1,063 bytes with the same SHA-256. One page through Drawing export: a drawing's sheets as the pages of one PDF (#4890) #9647 gives the same bytes as the one-page call.
  • 4 planted faults, each caught, then a clean run passed:
    • the moved arc's sign;
    • the centre's side;
    • PNG's flatten tolerance;
    • the grid constant set to 1e6.
  • clippy -D warnings and the wasm check pass for geom and io. The move adds no crate edge or dependency: io already depends on geom.
  • The full cargo xtask ci runs in CI.

Screenshots of the behavior (when observable)

No command writes a PDF yet; that comes with EX3. Below is a sheet through this writer: a plate with two Ø16 holes, Top view at 1:1 on A3, opened in Chrome. Before 72e23c8fb9 it failed with "an arc needs too many cubics".

The drilled plate's sheet written as a PDF: the A3 border, the plate in Top view with both holes, and the title-block lines

A test A3 scene (border, rectangle, circle, dash-dot centre lines, a quarter arc) as drawn by pdf.js:

A test A3 scene written as a PDF and drawn by pdf.js: border, rectangle, circle with centre lines and a quarter arc

Integration status

Earlier increments, with each one's own evidence (kept as written)

Earlier increments:

Additional P2 source-only preparation

The font prototype backup now includes a six-object resource-only font emitter and an alternative read-only subset adapter. Identity-H codes/CIDs, subset GIDs, widths and ToUnicode are kept distinct. Explicit descriptor metrics are required; synthetic fixtures do not establish B1/font-provider fidelity.

Production source review closed without an actionable finding in its scope. A weak width-test oracle was corrected and independently reviewed, with production unchanged. The emitter has 11 written, unrun tests; the selected P2 source proposals total52 declarations, zero executed. They remain outside this PR's product source: no module/Cargo adoption, page resources/content, provider integration, PDF-text/viewer acceptance or CI result is claimed. The qualified P1/P3 head stays 506d4190; its earlier results do not transfer to these proposals.


28 October - adjacent PDF layer runs published

Current head: 506d419084a1cd6463c3117ea34d15f805a6ce37, normal forward continuation of be22b97b. Only paper/pdf.rs and its existing tests changed; all earlier commits and 21 tests are retained.

Consecutive painted groups of the same kind now share one optional-content run. Empty groups do not interrupt it. An A/A/B/A sequence still paints all four objects in order, with three runs and two independently switchable layers. Shared widths and dashes, fill order, flat output and content limits are preserved.

Exact current source: complete IO 169 passed, 0 failed, 2 unchanged ignored; all 25 PDF tests passed, strict IO Clippy and wasm PASS. Three independent pypdf/PDFium checks passed: the existing five-kind layer fixture, flat/layered full-raster equality, and the actual new A/A/B/A test export with three runs/four paints/two layers. Its flat and layered 2100x2971 RGB rasters match; hiding either layer retains precisely the other marks. Original and hidden-layer PNGs inspected. The previous default layered fixture remains byte-identical (SHA 86be624b).

All eight validation phases exited zero. Current Cargo JSON/executable and all 2348 precommit source files were bound and unchanged; owned processes ended and leases released. No test ignore/tolerance/baseline change. The earlier flat metadata-oracle failure and its separate corrected run remain documented below.

This is an incremental task commit to the existing draft under our agreed batch workflow. Full cargo xtask ci, editor/print/two-viewer UI acceptance, text/fonts and integrated nonprinting filtering remain pending. No W22 completion, ready-for-review or merge claim.


Previous source-specific increments and evidence:

28 October - explicit flat vector output published

Current head: be22b97b70f31d1a0d79ed79fb1fc6c03b7f1011, normal forward continuation of effaf491 in this existing draft. Only pdf.rs, its existing pdf_tests.rs and the mutation test's options literal changed. Cam's commits and the original tests are preserved.

PdfOptions.layers defaults to true. Explicit false writes the same ordered vector geometry/styles/metadata without optional-content objects or BDC/EMC wrappers. Both paths use the same content-growth budget. No paper scene, text/font, schema, kernel or dependency change.

Final source executed: complete IO 165 passed, 0 failed, 2 unchanged ignored, all 21 PDF cases passed, strict IO Clippy and wasm PASS. The default layered five-kind export is still byte-identical (SHA86be624b); all five independently hidden-layer checks pass. Strict pypdf read-back and PDFium254dpi rendering show the flat877-byte fixture and its layered counterpart have identical full2100x2971 RGB pixels (SHAa4eccba298c4b026a08fe2b748e0a1cefa4814d15ecdedae2152c986be6b55e7). Original A3 flat sample remains1063bytes with its original SHA. The flat image was inspected.

An earlier run is preserved as 164 passed /1 failed /2 existing ignored: a new metadata oracle incorrectly required dictionary keys at column zero. Actual dictionaries are indented. The repair reads raw exact-key bytes and requires each of five fields exactly once with literal expected values in both PDFs, including UTF16 title bytes. Production was unchanged by that repair; no tolerance, ignore, expectation blessing or old-test removal. A fresh current native build and complete scoped validation then passed. All owned children ended and leases released.

Commands/profile/cache match the scoped commands below; current actual CargoJSON/executable and all2348 precommit RAW files were bound and remained unchanged through commit. Full cargo xtask ci, editor/print/two-viewer UI acceptance, text/fonts and integrated nonprinting filtering remain incomplete. This is saved qualified draft progress, not W22/M3/project completion or a ready/merge claim. Partial follow-ups preserve that distinction.


Previous source-specific increments and evidence:

28 October — P3 layers published, focused validation complete

Current head: effaf49113dadafc2e16663972ed97e015cb5bf4, a normal forward commit from dc911d80 in this existing PR. Cam's original commits and stack are retained. Only crates/io/src/paper/pdf.rs and its existing pdf_tests.rs changed in this increment. This remains draft, with full repository CI and Drawing-editor acceptance outstanding.

The writer now assigns each nonempty paper object kind one optional-content group using the shared layer names. Catalog order/default-ON, page properties and bounded BDC/EMC markers are explicit. Empty groups add no layers; repeated noncontiguous groups preserve paint order and share their layer. Stroke/fill/dash state and the existing content-growth cap remain enforced. All 17 earlier cases were retained; one original acceptance case covers all five kinds, repeated groups, empty groups, exact names/references and paint/style preservation.

Executed on the final precommit source, which remained unchanged through commit:

  • Complete unfiltered native IO library: 162 passed, 0 failed, 2 existing ignored (the two storage benchmarks); all 18 PDF cases passed.
  • Strict IO Clippy (--lib --tests -- -D warnings) and IO wasm check: PASS.
  • Independent strict pypdf 6.10.0 read-back and PDFium 5.14.0 rendering at 254 dpi: PASS. The actual 1440-byte five-kind export has SHA-256 86be624bba735e2d8e739bb1150e7d8bcf61308b96ae5389a856cb0807cac3f5. Each of the five OCGs was independently disabled in a derived copy; its marks disappear and the other layers' probes remain identical. Decoded content and document semantics other than default visibility are preserved. Original and hidden-layer PNGs were inspected.
  • Native compilation succeeded with current Cargo JSON and exact executable binding. The first private runner then stopped at its child-drain guard before tests; that failure is preserved separately. A new serial continuation reused that exact successful native artifact, without rebuilding it, and completed the checks above. Owned children ended and all leases were released.

Commands use the existing cache, +stable-x86_64-pc-windows-msvc, --profile ci --locked --offline --jobs 1: cargo test -p solidcraft-io --lib --target x86_64-pc-windows-msvc --no-run --message-format=json, then that exact test executable unfiltered with --test-threads=1; cargo clippy -p solidcraft-io --lib --tests --target x86_64-pc-windows-msvc -- -D warnings; cargo check -p solidcraft-io --target wasm32-unknown-unknown. Profile/lock/offline/job arguments apply to each Cargo invocation.

Still incomplete: full cargo xtask ci/merge-queue qualification, P2 fonts/text, general shared-layer controls/flat-output option, integrated scene filtering and Drawing-editor/physical-print acceptance. This P3 foundation is not completion of W22, M3 or the Drawings project. No browser/viewer interoperability or archival/accessibility claim is inferred from the independent reader test.

Previous P1 source-specific evidence and owner handoff follow unchanged.


27 October - bounded content generation, not only a final size check

Current head: dc911d80d100028b349b3e1a05c238b11a4acf2e, continuing the original P1 stack in this same PR. Changes a default: no. This increment changes only crates/io/src/paper/pdf.rs and its existing pdf_tests.rs.

The previous writer checked its 64 MiB uncompressed-content limit only after a complete stroke/fill. A single long path or an arc expanded into many cubics could grow the buffer beyond that allowance first. The header and final Q were not both covered by that late check.

Every content append now checks cumulative byte arithmetic before growing the string. This applies to coordinates, widths, dash operands, operators, each cubic inside an arc, all fill loops/groups and the final graphics-state restore. Reservations use try_reserve_exact, with bounded geometric growth and an explicit allocation error. The existing shared number formatter uses one reused small scratch buffer; number formatting, curve conversion, public options and the file structure are unchanged. Refusal returns no partial successful PDF.

This bounds the content buffer's logical bytes, not total export memory: the prepared scene, grid data, compression and PDF structure have their own costs. No whole-application out-of-memory guarantee is claimed.

Executed evidence

A private limit-injection seam, retaining the original late-check policy and default production limit, first ran four new regressions: 0 passed / 4 failed. The fix plus two further guard tests then passed on unchanged final source:

Check Result
Complete native IO library, no filtering 159 passed / 0 failed / 2 existing ignored
PDF tests within that total 15 passed, including all nine previous cases and six content-budget cases
Existing PDF mutation case PASS, included above
Scoped formatting and diff check PASS
Scoped strict geom/IO library and test Clippy PASS
Scoped geom/IO wasm check PASS (compilation, not browser runtime)
Original public-safe A3 sample, twice 1063 bytes, SHA-256 0de09bc342566206514754fc2ed7836156fbe10ba444e8ebb66427b10dd89c02; identical to Cam's original and the prior independently rendered sample
Full workspace CI / physical printing / editor acceptance Not qualified by this increment

The six small-bound tests exercise header/trailer accounting, early stop inside one path and one arc expansion, cumulative groups/fill accounting, non-mutating refused appends and exact formatting including both i64 extremes. Test limits can only tighten the production ceiling; no huge allocation, relaxed tolerance, new ignore, generated golden or source-dependent expected geometry is used. All original tests remain unchanged.

Checks ran sequentially in the existing cache, one Cargo job and one libtest thread, native CI profile, locked/offline. Source manifests and Cargo.lock remained fixed during each run. The A3 example was compiled against this source, run twice and removed afterwards; its unchanged bytes reuse the previous read-back/render evidence rather than claiming a new renderer run.

This remains draft WIP. The existing shared-walk/A5 stack and resource-bounded full repository gate remain outstanding; no runner or CI change, approval label or waiver is included. The earlier mutation campaign remains source-specific author evidence, not a rerun. P2/P3 and drawing.export integration remain separate.


Previous P1 continuation and original handoff (source-specific history)

27 October - P1 handoff continued; both failing test oracles repaired

Current head: 4ae2e1db656c0a39b1897d9ab7ad954857320639. This continues CamWight's exact 7dc82dc7 handoff in the existing #7626, preserving both original P1 commits and its A5/shared-walk stack. Only crates/io/src/paper/pdf_tests.rs changes in our continuation. The production PDF writer, curve helpers, date rule, dependencies, lockfile and previously emitted output remain unchanged.

Correction and independent regression checks

  • The cross-reference oracle now reads raw bytes: startxref and each object offset are byte positions, not positions in lossy UTF-8 text. It verifies the emitted six-entry subsection, fixed-size records, generation/in-use fields and each exact object header. ASCII, PDFDocEncoding, UTF-16/non-BMP and escaped titles are covered. Deliberate byte insertion and an object offset pointing into the header are refused by the oracle.
  • The 10 nm grid belongs to geometry and paint operands, not the page's unit-conversion matrix. The writer retains its nine-decimal cm. The oracle separately requires exactly one uniform, untranslated, unflipped transform and bounds its scale-only error across 5,000 mm by 1e-6 mm using the independent rational 360/127. Geometry, widths and dash parameters still have at most five decimals. Six-decimal geometry/paint, low-precision scale, exponents, nonfinite values, negative zero and duplicate/missing transforms are rejected.
  • Arc acceptance uses the agreed literal 1e-4 mm, not the implementation's tolerance constant. Original arc/parabola cases remain, and negative sweep plus a 5,000 mm radius quarter-circle add endpoint and sampled radial checks. These runtime samples are acceptance evidence, not a proof of continuous Hausdorff error or a printer's accuracy.

Executed on the exact final test source

Check Result
Complete native solidcraft-io --lib, CI profile, no filtering 153 passed, 0 failed, 2 existing ignored
PDF tests included in that suite All nine passed, including the two original failing tests and two new oracle-guard tests
Existing PDF mutation case PASS, included above
Scoped IO rustfmt and git diff --check PASS
Strict scoped geom/IO LIB + test Clippy (-D warnings) PASS
Scoped geom/IO wasm32-unknown-unknown compilation PASS (compilation, not browser runtime)
Actual original A3 sample and independent read-back PASS: 1063 bytes, SHA-256 0de09bc342566206514754fc2ed7836156fbe10ba444e8ebb66427b10dd89c02, byte-identical to Cam's sample and to a second run. pypdf 5.9.0 strict read-back and PDFium rendering checked externally; A3 size, metadata and geometry-only resources verified.
Full repository CI / browser editor / physical printing Not qualified by this continuation

Checks used stable native MSVC, --profile ci --locked --offline --jobs 1, one libtest thread, and the existing shared target; source manifests and the lockfile stayed unchanged. The new PDF dependency cache was filled once with cargo fetch --locked, without updating the lockfile. The full repository gate was not launched on this PDF head: the stacked drawings receiver still has the unbounded test runner previously raised with its shepherd, and the shared host is memory-constrained. No runner, skip, lint allowance, infrastructure change or gate waiver is included. This remains a draft, not merge-qualified.

Cam's earlier mutation campaign remains author evidence on its original head. This continuation does not claim that the five previously inconclusive mutation cases or the non-building mutation were rerun. The now-passing literal-tolerance/endpoint/parabola checks are stronger, but mutation coverage must be stated separately from ordinary test success.

P2 searchable text/fonts, P3 layers, images, integration with drawing.export, full CI and later end-to-end Drawing acceptance remain separate work. The unrelated X1 53 byte pins, W38d source and paused kernel are untouched. No new screenshot of the Drawing editor or completed workspace is implied by a geometry PDF sample.


Original CamWight handoff and head-bound evidence (preserved)

@0xlillith, this is a starting point handed to you and your team. PDF export (P1 to P3 of #4890) stays yours, as handed over on #4890, and your team continues it from here. We started on it by mistake after the handover; rather than throw it away, here is what is done, as a draft for you to take, change or drop as you like. We won't push to it again unless you ask.

For @0xlillith's list

  • Branch and commit: CamWight:paper-pdf-4890-p1 at 7dc82dc7. Both commits are by @CamWight, kept as they are (no squash).

  • Base and stack: into drawings, stacked on Drawing export A5: dashed lines draw dashed in SVG and PNG (#4890) #7430 (A5, dashed lines, 1aaff713), on Paper scene: a sheet PNG at a chosen dpi and colour (#4890 A4) #7429 (A4, dadb5f00), on Paper scene: one walk onto a writer's number grid, for every writer (#4890) #7255 (the shared paper walk, d2fcae51), on the current drawings. Until those land, this PR also shows their commits. Only the last two commits are this PR:

    1. 884fc537 io: the date rule crash reports use, for other writers too. civil moves from engine::crash to solidcraft_io, unchanged, and crash reports call it from there. It is its own commit so other crash-report work can rebase past it easily.
    2. 7dc82dc7 the PDF writer.
  • Implemented: P1's geometry: a sheet's lines, arcs, curves, dashes and fills as a one-page vector PDF (details below).

  • Not implemented: text and fonts (P2, after Sketch text: a line's width and the line pitch are worked out only while drawing it, so nothing can measure text to fit a box #4813's text metrics), layers (P3), and a full gate.

  • Commands run (on Windows, --profile ci, in this order):

    Command Result
    cargo test -p solidcraft-geom --lib -- paper 22 passed
    cargo test -p solidcraft-io --lib -- paper 26 passed, 2 failed (below)
    cargo test -p solidcraft-engine --lib -- crash (the moved date rule) 22 passed
    21 planted faults in the PDF writer, each a separate io test run, then a clean run 15 caught; 5 not proven (below); 1 doesn't build
    cargo clippy -p solidcraft-geom -p solidcraft-io -p solidcraft-engine --all-targets -- -D warnings clean
    cargo fmt --all -- --check clean
    cargo check -p solidcraft-geom -p solidcraft-io --target wasm32-unknown-unknown builds
  • Remaining failures:

    • paper::pdf::tests::arcs_are_cubics_within_a_ten_thousandth_of_a_millimetre (pdf_tests.rs:148). The arcs themselves pass. The last check, "every number has at most five decimals", also reads the page's scale q 2.834645669 0 0 2.834645669 0 0 cm, which has nine. Either the check skips the cm line, or the scale is written with five decimals (a relative change of about 2e-6, so up to 0.002 mm across A0). That choice is yours.
    • paper::pdf::tests::every_cross_reference_points_at_its_object (pdf_tests.rs:122). The test reads the file as lossy UTF-8. The title Ç is one byte in the file, and the lossy reading turns it into the three-byte U+FFFD, so the byte offsets after it no longer line up with the text, and slicing panics on a character boundary. The fault is in the test, not the writer: comparing bytes instead of text fixes it. The sample below checks the same offsets byte by byte, and they are right.
    • Faults: 5 of the 21 make only the two failing tests fail, so they aren't proven caught until those tests pass. They are 13 to 17: the parabola's controls, one cubic per arc piece, the error bound, the end tangent and the handle length. Fault 6 (dates never written) doesn't build. Each of the other 15 is caught by a test that otherwise passes.
  • PDF evidence: a public-safe A3 sample, made by a throwaway example (not committed; source below):

    • a 0.7 mm border, two trimming-mark fills, a 0.5 mm rectangle and circle, dash-dot centre lines and a quarter arc;
    • title "A3 sample", output time 1,800,000,000;
    • 1,063 bytes, SHA-256 0de09bc342566206514754fc2ed7836156fbe10ba444e8ebb66427b10dd89c02. The same scene always gives these bytes.

    Read back two ways:

    1. By bytes, with a separate script that checks the header, startxref, every cross-reference entry at its N 0 obj, the MediaBox and the inflated content:
      • %PDF-1.7, ends %%EOF;
      • 6 cross-reference entries, each at its object;
      • MediaBox [0 0 1190.5511 841.8898] = 420.000 × 297.000 mm;
      • content 1,018 characters: m 8, l 14, c 14, h 2, S 3, f* 2, w 4, d 2, one q … cm … Q;
      • Title "A3 sample", CreationDate and ModDate D:20270115080000Z.
    2. In pdf.js 3.11.174 (Mozilla's reader): 1 page, 420.00 × 297.00 mm, PDF 1.7, the title and date as written. Its drawing is below: y is up, the fills sit top-left and bottom-right where the scene puts them, and the arcs are round.

    The sample A3 PDF drawn by pdf.js

    The sample's source (an example in crates/io/examples/, run with cargo run -p solidcraft-io --example p1_sample -- sample-a3.pdf)
//! A public-safe A3 sample for the PDF writer (not committed).
use solidcraft_geom::paper::{Dashes, Group, Item, ObjectKind, Scene};
use solidcraft_geom::{Loop2, Region2, Seg2, Vec2};
use solidcraft_io::paper::{PdfOptions, paper_pdf};

fn p(x: f64, y: f64) -> Vec2 {
    Vec2::new(x, y)
}

fn rect(a: Vec2, b: Vec2) -> Vec<Seg2> {
    let c = [a, p(b.x, a.y), b, p(a.x, b.y)];
    (0..4).map(|i| Seg2::Line { a: c[i], b: c[(i + 1) % 4] }).collect()
}

fn stroke(path: Vec<Seg2>, closed: bool, width_mm: f64, pattern: Option<Dashes>) -> Item {
    Item::Stroke { path, closed, width_mm, pattern }
}

fn main() {
    let centre = Some(Dashes { lengths_mm: vec![12.0, 3.0, 1.0, 3.0], phase_mm: 0.0 });
    let border = vec![
        stroke(rect(p(20.0, 10.0), p(410.0, 287.0)), true, 0.7, None),
        Item::Fill { region: Region2 { outer: Loop2 { segs: rect(p(0.0, 287.0), p(10.0, 297.0)) }, holes: vec![] } },
        Item::Fill { region: Region2 { outer: Loop2 { segs: rect(p(410.0, 0.0), p(420.0, 10.0)) }, holes: vec![] } },
    ];
    let part = vec![
        stroke(rect(p(120.0, 90.0), p(300.0, 210.0)), true, 0.5, None),
        stroke(Loop2::circle(p(210.0, 150.0), 40.0).segs, true, 0.5, None),
        stroke(vec![Seg2::Line { a: p(160.0, 150.0), b: p(260.0, 150.0) }], false, 0.25, centre.clone()),
        stroke(vec![Seg2::Line { a: p(210.0, 100.0), b: p(210.0, 200.0) }], false, 0.25, centre),
        stroke(vec![Seg2::Arc { center: p(120.0, 90.0), radius: 15.0, start: 0.0, sweep: std::f64::consts::FRAC_PI_2 }], false, 0.35, None),
    ];
    let scene = Scene {
        size_mm: p(420.0, 297.0),
        groups: vec![
            Group { object: 1, kind: ObjectKind::DrawingBorder, items: border },
            Group { object: 2, kind: ObjectKind::DrawingBorder, items: part },
        ],
    };
    let options = PdfOptions { title: Some("A3 sample".into()), output_time: Some(1_800_000_000) };
    let out = std::env::args().nth(1).unwrap_or_else(|| "sample-a3.pdf".into());
    let scene = scene.prepare().unwrap();
    let (bytes, report) = paper_pdf(&scene, &options).unwrap();
    std::fs::write(&out, &bytes).unwrap();
    println!("{} bytes, {report:?}", bytes.len());
}

Changes a default: no
This adds a new writer; nothing that exists writes differently.

What it does

  • io::paper::paper_pdf(scene, options) writes the sheet as a one-page PDF, beside paper_svg and paper_png. It reads the same walk, so it draws the same joints, closures and merges.
  • The file: a catalog and one page, whose MediaBox is the sheet in points (A3 is [0 0 1190.5511 841.8898]).
    • The content stream is deflated.
    • The Info dictionary has the Producer ("SolidCraft ") and the Title when one is given.
    • CreationDate and ModDate come only from PdfOptions::output_time (seconds since 1970, written in UTC), never from the clock, so a scene always gives the same bytes.
  • The drawing: the content runs inside one q 2.834645669 0 0 2.834645669 0 0 cm … Q, so its numbers are the scene's own millimetres with y up, and nothing flips.
    • Strokes: their width, butt caps, miter joins and a miter limit of 4 (0 J 0 j 4 M), as SVG and PNG draw them.
    • A5's dashes as d. Each width and dash pattern is written only when it changes.
    • Closed outlines with s; fills even-odd with f*.
    • Black on no background, as SVG.
  • Refused:
    • a page under 3 pt a side (ISO 32000-1 Annex C's smallest page; the scene's own 5000 mm limit keeps every page under Annex C's 14,400 pt);
    • a title over 1,000 characters;
    • a date past the year 9999.

Decisions

Each was read first-hand in Adobe's copy of ISO 32000-1.

  1. Numbers are our own text on a 10 nm grid, not pdf-writer's 32-bit numbers. Grid::TEN_NANOMETRES gives at most five decimals of a millimetre, Annex C's precision, and every number is exact. pdf-writer's content calls take f32, which is 1.2e-4 mm coarse at A0 and 2.4e-4 mm at the scene's 5 m limit: too coarse for the curves' 1e-4 mm. pdf-writer still writes the file around the content: objects, cross-references, page, Info and dates. The SVG writer's number rule moved to io::paper::push_mm, which takes the decimals, so both writers read one rule.
  2. Arcs are cut by their radius. One cubic per quarter turn is about 2.7e-4 × the radius off (0.027 mm at r = 100 mm). So each of the walk's quarter-turn pieces is cut into as many 4/3·tan(θ/4) cubics as keep it within 1e-4 mm, rounding onto the grid included:
    • The bound is the cubic's exact largest error, r·(2/27)·sin⁶(θ/4)/cos²(θ/4).
    • That's 3 cubics a quarter at r = 40 mm and 5 at 5 m.
    • The arc's centre comes from Piece::seg, the rule A4's flattener used, now on Piece so both read it.
    • Parabolas are raised to cubics.
  3. No minimum width beyond the walk's. A4's hairline floor is in device pixels, and a PDF has no pixels. w is never 0, because the walk gives every line at least one step: 8.4.3.2 says a 0 width means one device pixel and shouldn't be used.
  4. Licences: the two new crates are pdf-writer 0.15.0 (MIT OR Apache-2.0) and ryu 1.0.23 (Apache-2.0 OR BSL-1.0). flate2 was already in the tree through zip. They are covered by cargo xtask licences, and THIRD-PARTY-LICENSES is regenerated on main after the merge. ATTRIBUTION.md is for asset files, and this adds none.
  5. No PDF reader as a test dependency. hayro-syntax was considered. With its default features off it builds only itself, but Cargo.lock gains three more entries (its image decoders, never built). The tests read the file with their own small reader instead: inflate, operators and numbers.

What the tests can't reach

  • Other readers: the tests read the file with their own reader. pdf.js has opened the sample above; no other viewer has.
  • Printing: the page size is checked in the MediaBox, not on paper.
  • The drawing size cap (the content over MAX_DRAWING_BYTES) needs a scene of tens of millions of numbers, so no test builds it. It is the same check as SVG's.

Tests

  • The A3 MediaBox and the Producer, with no Title unless one is asked for.
  • 50 mm on paper (a 100 mm edge at 1:2) is 141.732 pt.
  • The same bytes twice. Dates only from output_time: 2000-02-29 and 9999-12-31 23:59:59.
  • Every cross-reference entry at its N 0 obj (fails today: see above).
  • Arcs from 0.5 mm to 2 m radius within 1e-4 mm, a parabola on its cubic, and every number with at most five decimals (fails today on the scale: see above).
  • Widths, dashes, closes and fills as SVG and PNG paint them.
  • The refusals.
  • One fuzz scene now feeds the SVG, PNG and PDF mutation tests (it was two copies).

No full gate: only the targeted checks above.

P2 source preservation — 28 October 2026

Bundled-font admission guard, ToUnicode serializer and original unrun acceptance, saved as source-only WIP. The new ToUnicode module has eleven inline tests plus six independent acceptance cases, all unrun; module/caller integration is pending. This does not implement embedding/subsetting or replace B1's prepared-text contract. Complete team WIP index. Existing P1–P3 results and remaining gates above are unchanged.

P2 source-only adapter backup

The existing P2 source packet now also preserves the real subsetter0.2.6 adapter and its bounded preflight/readback source, with eighteen unrun closure/adapter tests and separate source/oracle reviews. This is not applied to this PR, has not produced a subset font, and has not been compiled/run. B1, descriptor/layout metrics, resource-object emission, actual PDF text integration and all runtime gates remain pending. Existing P1–P3 results above qualify only their recorded source; they do not qualify these new proposals.

One grid value per writer (17 Nov)

Change: each paper writer's precision is now one value in io/src/paper.rs: its decimals, which give both the grid it
puts the scene on and the text of its numbers. SVG and PNG use whole nanometres (6 decimals), PDF uses 10 nm (5
decimals). Before, PDF kept PER_MM and DECIMALS as two constants that had to agree, and SVG had its own pair.

  • io now lists the writers' grids (solidcraft_io::paper::writer_grids()). The hatch-dot check in
    engine/src/drawing_scene/fill.rs (from @0xlillith's saved fills) loops over that list. It no longer keeps its own
    copy of the PDF grid (Grid::new(1e5)), so it can't fall behind a writer.
  • Doc fixes: the flattener's notes no longer say PDF flattens curves; its cap is renamed MAX_PATH_POINTS, so it isn't
    confused with the PNG writer's MAX_POINTS; two geom doc comments (grid.rs, cubic_pieces.rs) are corrected with
    the same line count (geom doesn't grow); a test comment on the xref check says what its bound is.
  • The PDF and SVG bytes don't change. Every existing byte pin still holds.

For reviewers:

  • The app-geometry ledger (Add a shrink-only ledger of geometry computed in the app crates #13957, on main) counts .normalized() calls. Once drawings meets main, it will list
    one line here: crates/io/src/paper/flatten.rs:seg. That call was geom's flattener before this PR moved it into io,
    so the PDF work adds no new site.
  • The PDF writer writes black on no background and takes no paper colour. So drawing.export with format: "pdf"
    (EX3, @DevonHope's) must refuse a blue paper, as PNG refuses paper with a grey or black-and-white colour.

Test change: the flattener's own tests (io/src/paper/flatten.rs, too_many_points_or_no_tolerance_is_refused) name
its cap by its new name, MAX_PATH_POINTS.

Validation (head 76785aef85, the targeted run):

  • Test first: a new io test (the listed grids and their number text) and a new engine test (a hatch dot too small for
    each listed grid is refused, naming that grid) failed to build before the change, and pass after.
  • io paper:: 77 passed, geom paper:: 64 passed, engine dot and hatch tests 45 passed. The PDF and SVG byte pins
    pass unchanged.
  • Planted faults, each caught, then a clean run: PDF decimals 5 -> 4 (5 io tests, the A3 sample's bytes among them);
    the PDF grid left out of the list (both engine dot tests).
  • clippy -D warnings on io, engine and geom; cargo check -p solidcraft-io --target wasm32-unknown-unknown; rustfmt.

@github-actions github-actions Bot added area:io import/export and file formats (STEP, IGES, 3MF, glTF, designs) area:kernel B-rep kernel, booleans, blends, STEP/IGES labels Oct 27, 2026
@selun3

selun3 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@CamWight, thank you for the complete handoff. I have checked out exact 7dc82dc7 with both original commits and the A5/walk stack preserved. I am continuing this existing PR, not opening a competing PDF writer.

The first bounded change repairs and strengthens the two test oracles: cross-reference offsets are byte offsets (including PDFDocEncoding and UTF-16 metadata), while the 10 nm coordinate grid is distinct from the millimetre-to-point transformation. I will keep the nine-decimal scale, assert its physical-size error independently, and apply the five-decimal check to geometry/paint operands rather than weaken the curve tolerance. Arc/parabola acceptance keeps the agreed literal 1e-4 mm bound, independent of the implementation constant.

W38a currently owns the shared native build slot on Pegasus. This PDF continuation remains source-only until that slot is free. No parallel compilation, new test pass, full-CI pass or merge is claimed. Your original runtime and mutation results remain evidence for your exact source; actual final-source checks and any new findings will be recorded here.

selun3 added a commit to CamWight/solidcraft that referenced this pull request Oct 27, 2026
Continue the P1 handoff in tangency-labs#7626 with original commits preserved. Only the existing PDF test module changes. Complete IO library 153/0/2 existing ignored, scoped strict Clippy and wasm pass. Full workspace gate remains unqualified on the limited-memory drawings receiver; see PR evidence.
@selun3

selun3 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@CamWight, continued at 4ae2e1db656c0a39b1897d9ab7ad954857320639 in this same PR, preserving your original commits and stack. Only pdf_tests.rs changed: byte-based xref validation; separate 10 nm geometry/paint versus page-scale checks; Unicode titles and deliberately corrupted-offset/oracle guards; negative-sweep and 5 m arc acceptance. The production writer is byte-identical.

Executed: complete IO library 153 passed / 0 failed / 2 existing ignored, including all nine PDF tests and the PDF mutation case; scoped fmt, strict geom/IO Clippy and wasm pass. Both original failing tests now pass. Your original A3 sample is exactly 1063 bytes with its original SHA-256, repeated byte-for-byte; external strict pypdf read-back and an inspected PDFium render also pass. No physical-printer or Drawing-editor acceptance is inferred.

Full workspace CI remains unqualified on the limited-memory, unbounded-runner receiver; this stays draft. Your earlier 21-mutation campaign is not claimed rerun. P2 fonts/text, P3 layers and scene/export integration remain separate. The body contains final-source evidence and your preserved handoff. A matching backup commit is in our fork, with no second PDF PR.

selun3 added a commit to selun3/solidcraft that referenced this pull request Oct 27, 2026
Continue P1 in tangency-labs#7626. Four regressions reproduce the previous late-check policy using tightened limits; six budget tests pass with all 159 IO library tests, scoped strict Clippy and wasm. Original A3 output bytes unchanged. The limited-memory full-workspace gate remains explicitly unqualified; no CI changes.
@selun3

selun3 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@CamWight, P1 now enforces the existing content-size limit before every append, including within paths/arc subdivision and the final Q, at dc911d80d100028b349b3e1a05c238b11a4acf2e. Checked arithmetic and fallible reservations bound content growth without changing public options, curve rules, number formatting or the original sample bytes. Four small-limit cases first reproduced the original late-check policy; all six new budget cases now pass.

Complete IO library: 159 passed / 0 failed / 2 existing ignored, including all 15 PDF tests and the existing PDF mutation case; scoped fmt/strict Clippy/wasm pass. The original A3 sample is still exactly 1063 bytes with its original SHA-256, reproduced twice. The bound is on uncompressed content, not all export memory. Only pdf.rs and its existing tests changed; original tests, your commits and stack are retained.

This remains draft with full CI/shared-stack integration unqualified; no CI, kernel or other export changes, and no new mutation-campaign claim. Exact commands and limitations are at the top of the PR.

@selun3
selun3 requested a review from bherbruck October 27, 2026 14:16
selun3 added a commit to CamWight/solidcraft that referenced this pull request Oct 28, 2026
Continue the existing tangency-labs#7626 handoff with five ordered default-visible optional-content groups, bounded marked content, paint order and style preservation. Original implementation and earlier tests retained; an original five-kind repeated-group fixture adds independent structure and PDFium visibility acceptance.

Focused validation: complete IO 162 passed, 0 failed, 2 existing ignored; all18 PDF cases, strict IO Clippy and wasm passed. Exact native build artifact reused after a preserved private runner drain failure. Full cargo xtask ci, Drawing UI and print acceptance remain unrun; this is saved draft work, not a ready/merge claim.
selun3 added a commit to CamWight/solidcraft that referenced this pull request Oct 28, 2026
Preserve default layered output and vector paint. Original acceptance covers flat metadata, exact content limits, empty groups and the original 1063-byte A3 pin. Complete IO165/0/2 existing ignored, all21 PDF cases, strict Clippy, wasm and independent five-layer/flat raster checks passed on unchanged final source. An earlier new-test metadata indentation failure is preserved separately and corrected with stricter raw-byte metadata assertions. Full workspace CI and editor/print qualification remain outstanding; saved draft increment in tangency-labs#7626.
@CamWight

Copy link
Copy Markdown
Contributor Author

@0xlillith, thanks for the split on #4890. Here's what we'd like to propose for the many-page and picture follow-up, so we stay out of each other's way in pdf.rs.

Base: #7626 sits on older versions of #7255, #7429 and #7430. Those three are now rebased on drawings (#7255 14f9044, #7429 a05b8b7, #7430 fa8afd094). Would you like to move #7626 onto them yourself, or shall we start the page follow-up on 506d419 as it is and move with you when you do? Pictures need #7590's picture item, so that part would come as a second PR once both are in drawings.

Window: we'd change only paper_pdf's body (it becomes a small page builder, with paper_pdf kept as its one-page call, giving exactly today's bytes), collect_layers (one layer per kind across all pages, tags assigned as pages arrive), and the item loop (a picture arm, in the second PR). date, the number and dash writers, path, arc and cubics_for stay as they are. One page keeps today's object numbers, so your layer and xref tests hold.

P2: fonts would take the next numbers in the same place as layers, whichever lands first, and nothing we change touches how text is written.

Tests: we'd add ours at the end of pdf_tests.rs under their own heading, or in a sibling file if you'd rather keep that file yours.

Your png_tests.rs window: #9512 adds fonts to Scene, so Scene { .. } literals stop compiling once a branch has it. In that file it's one line, in the scene() helper. We won't touch it while your window is open, and we'll change it when #7429 next moves past #9512. Scenes built through scene() need nothing from you. Literals of your own will want Scene::new from #9512. If your increment will be a while, tell us and we'll work out the order, as text in PNG waits on this line.

Does that work for you? Happy to adjust any of it before we start.

@selun3

selun3 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks, that split works for us. Please start the many-page follow-up from the current 506d4190, keeping paper_pdf as the one-page call with the same bytes. Your proposed paper_pdf/collect_layers window is clear; the picture arm can follow #7590 separately. Please append your tests to pdf_tests.rs under their own heading. Our P2 prototypes stay separate and unqualified; we will adapt their font resources to the same global object-number allocation, rather than assume fonts start at a fixed number beside the layers.

You can update the original scene() helper in png_tests.rs for the font table/Scene::new change. Our three-case increment is archived and unapplied, with no active shared-file writer, so that one-line change need not wait for us. We will rebind our appendix, including its own mixed-scale scene literal, to your actual resulting source without changing its expected geometry or pixels.

I also checked #9512/#9513: the intrinsic per-GID hmtx advance and separate placed glyph positions give P2 the contract it was missing. We will use those records directly and preserve your layout and clusters. Compilation, text extraction and the composed PDF gate are still pending.

Source-preservation update: the typed B1 text-plan scaffold and13 original unrun cases are now archived in the canonical repository. This is uncompiled, unregistered WIP around the delivered B1a/B1b records; it preserves your content/common-allocator window and all earlier P2 test suffixes. It still uses the old metric compatibility helper, so it does not supersede the agreed final B1 intrinsic-width authority or resolve DW. We are preparing that width-provider migration separately; no production integration or extraction result is claimed.

Thanks for the many-page follow-up in #9647. We have now pinned its actual ce505658 source over 506d4190; our font-resource adapter will use that delivered Refs allocation seam, keeping your parent/page-builder functions untouched. The single-page old-versus-new byte comparison and the composed PDF extraction gate remain unexecuted on our side.

The additive B1-width and actual #9647 Refs proposal is now preserved as source WIP. It uses the original-GID intrinsic advances, keeps the older SFNT parser only as a test oracle, and stages six references through your delivered Refs. This keeps your page/content/resource builder window intact. The three-file patch has explicit mixed per-file bases; it is not an integrated head or an executed PDF result. Our existing DW question and trusted-font/emission/old-byte acceptance remain pending; we have not invented a GID-0 fallback or another allocator. The 79 source declarations are labelled unrun, and all earlier archives remain available.

F0 explicit-width successor — source only

Following your width clarification, our font-resource helper and exact delta are now preserved here. The helper emits explicit /W for every declared code, omits /DW, and keeps program .notdef separate. The opaque plan, intrinsic advance checks, single source admission and Refs guards are retained. Independent source review is closed; all 49 ordinary cases and four negative compile obligations remain unrun/unregistered. Actual page-emitted CID coverage and the PDF pipeline are still pending.

For the next integration, would you prefer to wire this into your current many-page/Refs parent yourself, or hand us a narrow window in paper/pdf.rs and the relevant end of paper/pdf_tests.rs? We checked #9647 at ce505658; this would only register/connect the owned font-plan/resource pieces and their original acceptance, preserving your page/content/numbering work. We will keep those two owner files untouched until that split is clear and continue independent work meanwhile. This is separate from the existing SVG/PNG/A-series handoff question on #4890.

@CamWight

Copy link
Copy Markdown
Contributor Author

Thanks @0xlillith, the many-page follow-up is up as a draft: #9647, stacked on this PR's 506d4190. Its one commit is ce505658.

  • What it changes: only paper_pdf and collect_layers in pdf.rs. The tests go at the end of pdf_tests.rs under their own heading. paper_pdf is the one-page call of paper_pdf_pages and writes the same bytes; a test checks that, with and without layers, a title and a date.
  • Object numbers: one counter, Refs, hands them out in writing order: catalog, page tree, each page then its content, Info, then layers. One page keeps 1 to 5, with layers from 6. Your fonts can take theirs from the same counter.
  • check_xref: I didn't touch your helper. It allows a one-page object count, so the three-page test checks object numbering in full instead.

The png_tests.rs scene() line goes in with #7429's next push, and nothing else in that file changes.

@selun3

selun3 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Owner decision received — 30 October

Thanks, @CamWight. Following your clarification, we'll emit a complete explicit /W entry for every CID placed by a run, using its Font.glyphs advance, without relying on /DW. We won't request or invent a B1 width for GID 0; retaining .notdef in the embedded font program remains a separate embedding obligation. This settles the width-contract decision. We're updating our font-resource helper and acceptance cases accordingly; the parent integration and actual PDF validation remain pending.

Earlier question, preserved for context

Thanks Cam — we have read ce505658 over 506d4190. Our private P2 adapter can reserve its six font references through your actual Refs counter, keeping your many-page functions untouched; it remains uncompiled and unregistered.

One remaining B1/P2 contract question: B1 correctly carries only the used glyphs and refuses missing characters, so original GID 0 is normally absent from its width records. Would you prefer complete explicit /W coverage for every emitted CID, without relying on a /DW fallback, or should a verified .notdef/default width come separately from font admission? We have not added a B1 field or chosen a fallback. The private width successor currently refuses that unresolved case rather than inserting an unused glyph or parsing hmtx again.

The earlier prepared-text dependency question in #4890 is answered by #9512/#9513; this is its concrete follow-up, not a new B1 claim.

@CamWight

Copy link
Copy Markdown
Contributor Author

@0xlillith, complete explicit /W for every emitted CID, please, without relying on /DW. Every glyph a run places has its advance in Font.glyphs, so the array needs nothing else, and B1 won't add a .notdef width: a character no font has is refused, so GID 0 is never placed. If the font program you embed needs a .notdef glyph at GID 0, that's part of the embedding, not a width it has to report.

@bherbruck

Copy link
Copy Markdown
Collaborator

drawings now includes main as of today; please merge drawings into your branch. Thanks!

@selun3

selun3 commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Thanks, Cam. P2 is rebound to 90fce1b587 / 66adfe5abe, with the producer from #12039 now merged. Its 210 required application cases pass; the full local suite is not green, and standalone kernel/export-reader checks remain pending.

I’m keeping P2 separate from your writer/pages claims. Please flag anything still blocking #7626 and #9647 from leaving draft, so we can land the parents before the consumer. I’ll publish P2 with its actual validation results and dependency links when the remaining checks finish.

CamWight and others added 10 commits November 17, 2026 11:16
…labs#4890 P1)

civil (seconds since 1970 to a UTC year, month, day, hour, minute and second)
moves from engine::crash down to solidcraft_io, unchanged, so sheet PDFs can
write their dates by the same rule. Crash reports call it from there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… P1)

A new writer, io::paper::paper_pdf, beside paper_svg and paper_png, reading
the same walk: one page the sheet's size, its lines, arcs, cubics, parabolas,
fills and dashes. Text follows with P2.

- The file comes from pdf-writer 0.15 (MIT OR Apache-2.0; brings ryu): a
  catalog, one page whose MediaBox is the sheet in points, the content
  deflated with flate2 (already in the tree through zip), and an Info
  dictionary: Producer "SolidCraft <version>", the Title when one is given,
  and CreationDate/ModDate only from PdfOptions::output_time (UTC), never the
  clock, so a scene always gives the same bytes. ISO 32000-1 14.3.3: unknown
  entries are left out, not written empty.
- Numbers: the walk runs on a 10 nm grid (Grid::TEN_NANOMETRES), written as
  millimetres with up to five decimals (Annex C's precision) inside one
  `2.834645669 0 0 2.834645669 0 0 cm`; y is up in both, so nothing flips. The
  SVG writer's number rule moves to io::paper::push_mm, taking the decimals.
- Arcs: each of the walk's quarter-turn pieces is cut into as many 4/3 tan(t/4)
  cubics as keep it within 1e-4 mm, the rounding of control points onto the
  grid included (one cubic a quarter turn would be 2.7e-4 r off). The arc's
  centre comes from Piece::seg, the rule the flattener used, moved onto Piece
  so both read it. Parabolas are raised to cubics.
- Paint: w at the walked width (never 0: 8.4.3.2 says 0 is a device pixel),
  0 J 0 j 4 M as SVG and PNG, d for A5's dashes, each set only when it changes;
  closed outlines `s`, fills even-odd `f*`.
- Refused: a page under 3 pt a side (Annex C), a title over 1,000 characters,
  a date past 9999.
- Dates use io::civil, the crash reports' rule (moved in the commit below).

Tests: the A3 MediaBox; 50 mm on paper is 141.732 pt; the same bytes twice,
dates only from output_time (2000-02-29 and 9999-12-31 23:59:59); every xref
entry at its object; arcs from 0.5 mm to 2 m radius within 1e-4 mm and a
parabola on its cubic, every number at most five decimals; widths, dashes,
closes and fills as the other writers paint them; the refusals. One fuzz scene
now feeds the SVG, PNG and PDF mutation tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Continue the P1 handoff in tangency-labs#7626 with original commits preserved. Only the existing PDF test module changes. Complete IO library 153/0/2 existing ignored, scoped strict Clippy and wasm pass. Full workspace gate remains unqualified on the limited-memory drawings receiver; see PR evidence.
Continue P1 in tangency-labs#7626. Four regressions reproduce the previous late-check policy using tightened limits; six budget tests pass with all 159 IO library tests, scoped strict Clippy and wasm. Original A3 output bytes unchanged. The limited-memory full-workspace gate remains explicitly unqualified; no CI changes.
Continue the existing tangency-labs#7626 handoff with five ordered default-visible optional-content groups, bounded marked content, paint order and style preservation. Original implementation and earlier tests retained; an original five-kind repeated-group fixture adds independent structure and PDFium visibility acceptance.

Focused validation: complete IO 162 passed, 0 failed, 2 existing ignored; all18 PDF cases, strict IO Clippy and wasm passed. Exact native build artifact reused after a preserved private runner drain failure. Full cargo xtask ci, Drawing UI and print acceptance remain unrun; this is saved draft work, not a ready/merge claim.
Preserve default layered output and vector paint. Original acceptance covers flat metadata, exact content limits, empty groups and the original 1063-byte A3 pin. Complete IO165/0/2 existing ignored, all21 PDF cases, strict Clippy, wasm and independent five-layer/flat raster checks passed on unchanged final source. An earlier new-test metadata indentation failure is preserved separately and corrected with stricter raw-byte metadata assertions. Full workspace CI and editor/print qualification remain outstanding; saved draft increment in tangency-labs#7626.
…ene (tangency-labs#4890 P1)

The sheet PDF writer and @0xlillith's layer, budget and flat-output work,
replayed onto drawings 8a0b1fd. What the replayed commits couldn't hold:

- Geometry only, as before: the scene's text runs (B1b, B2a) and pictures
  (tangency-labs#10926) are passed over; text follows with P2. A group with no stroke or
  fill puts no mark on the page, so it invents no layer and doesn't break a
  run of one kind (`painted`, the one test the layers and the content share).
- Seg2 and Vec2 come from solidcore-record and the vector maths from the
  geom prelude (tangency-labs#11496).
- The tests build scenes with Scene::new (scenes now carry fonts and clips).

Line widths need nothing: the walk already gives each stroke its kind's and
line group's width (tangency-labs#12232). The replayed commits keep their resolutions:
the io paper module keeps PaperColour beside push_mm, and the PDF fuzz test
is built like the SVG and PNG ones, on seed 0x5a7 (0x5a5 is the clip test's).

Test change: flat_pdf_reproduces_the_original_p1_a3_sample_bytes pinned the
whole file, and its Info dictionary names the build ("SolidCraft 0.19.0" then,
0.41.0 now). The same file with 0.19.0 put back has the old SHA-256, so the
drawing's bytes are unchanged. The pin is now the 721 bytes before the Info
dictionary, and the Producer is checked against this build's version, so a
release bump no longer moves it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…refused (tangency-labs#4890 P1)

A drilled plate's iso view failed the sheet PDF with "an arc needs too many cubics", while its SVG
and PNG were fine. The walk's arc pieces are about a quarter turn, but can turn a little more: their
ends are rounded onto the 10 nm grid, and a sliver piece merges into the next. cubics_for refused
anything past a quarter turn plus 1e-9.

cubics_for now takes up to a half turn, and starts from enough cubics that each spans at most a
quarter turn. Any arc it wrote before starts at one cubic as before, so it writes the same bytes:
the byte pins pass unchanged. Piece::Arc's doc says what the walk gives (a comment change only in
geom). The scene caps a sweep at a whole turn plus 1e-12, so the walk's four-piece cap adds
nothing past the old slack.

Found by @DevonHope on tangency-labs#9647, with this fix and its unit test
(an_arc_a_little_over_a_quarter_turn_is_written). The second test walks Ø16 circles at nearby
centres until one gives a piece past a quarter turn, then writes each and checks every cubic lies
on the circle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e the PNG and PDF writers that use them (tangency-labs#4890 P1)

geom's paper module only shrinks (CONTRIBUTING). Its flattener had one caller, io's PNG
writer, and the stack had added `Piece::seg`, `GridPoint::vec` and a 10 nm grid constant
to geom for io's PDF writer. They now live in io/src/paper/flatten.rs, with the
flattener's tests unchanged except one call form: `flatten`, `seg` (a piece's curve,
which both writers read) and `vec`. The PDF writer makes its own 10 nm grid with
`Grid::new`. Nothing writes different bytes: the PNG and PDF byte pins pass as they were.

geom's walk test for an ellipse's cubics checked them by flattening them. It now samples
each cubic itself, with the same bound, so geom's test needs no io.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CamWight added a commit to CamWight/solidcraft that referenced this pull request Nov 17, 2026
…ed test (tangency-labs#4890 P1)

Replayed onto the rebased tangency-labs#7626. A page lists the layers of the kinds it
paints, now by the writer's one painted test (a stroke or a fill), so a
page whose group of a kind holds only text or pictures doesn't list that
kind's layer. The pages' tests build scenes with Scene::new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CamWight
CamWight marked this pull request as ready for review November 17, 2026 11:51
@CamWight

Copy link
Copy Markdown
Contributor Author

@0xlillith, thank you for rebinding P2, and sorry the answer on what's left took a while. Here is where #7626 and #9647 stand.

Nothing of yours blocks them. Both are now rebased onto today's drawings (76eb8bfc98). Your five commits are there as you wrote them, with you as their author. We had three things left:

Parents for P2:

Your registration and emission window is where it was, give or take the import lines. The line numbers are at #9647's head:

  • paper_pdf (pdf.rs:90) and paper_pdf_pages (:98)
  • the per-page resources block (:158)
  • Refs (:190)
  • collect_layers (:219) and painted (:233)
  • the GridItem::Text arm (:291)
  • the end of pdf_tests.rs, after the "Many pages" heading (:873)

One thing moved, in case your helper used it. The 10 nm grid is now io's own, grid() (pdf.rs:63, from PER_MM at :60). It used to be geom::paper::Grid::TEN_NANOMETRES.

Tell us if anything doesn't line up when you rebind. And thank you again for the layers and the content budget: they're a big part of why this is ready.

…lue, and io lists the grids (tangency-labs#4890 P1)

A paper writer's precision was two facts that had to agree: PDF kept PER_MM and
DECIMALS, SVG kept the nanometre grid and its six decimals, and PNG named the
nanometre grid too. Now io/src/paper.rs holds one Decimals value for each: whole
nanometres (SVG's numbers, PNG's grid) and 10 nm (PDF's). Each gives the writer
its grid and writes its numbers.

io lists the writers' grids (writer_grids). The engine's hatch-dot check in
drawing_scene/fill.rs, from @0xlillith's saved fills, loops over that list instead
of keeping its own copy of the PDF grid, so a new writer's grid reaches it too.

Docs: the flattener's notes no longer say PDF flattens curves, and its cap is
MAX_PATH_POINTS, apart from the PNG writer's MAX_POINTS. Two geom doc comments
(grid.rs, cubic_pieces.rs) say what the code does, in the same number of lines,
and the xref check's comment says what its bound is. No bytes change: the PDF and
SVG byte pins pass as they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CamWight added a commit to CamWight/solidcraft that referenced this pull request Nov 17, 2026
…ed test (tangency-labs#4890 P1)

Replayed onto the rebased tangency-labs#7626. A page lists the layers of the kinds it
paints, now by the writer's one painted test (a stroke or a fill), so a
page whose group of a kind holds only text or pictures doesn't list that
kind's layer. The pages' tests build scenes with Scene::new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bherbruck bherbruck added the approved-for-ci Reviewed: run the full PR CI (build, tests, goldens, Clippy) label Nov 17, 2026
@bherbruck
bherbruck merged commit 94d2d95 into tangency-labs:drawings Nov 17, 2026
81 of 87 checks passed
bherbruck pushed a commit to CamWight/solidcraft that referenced this pull request Nov 17, 2026
…ed test (tangency-labs#4890 P1)

Replayed onto the rebased tangency-labs#7626. A page lists the layers of the kinds it
paints, now by the writer's one painted test (a stroke or a fill), so a
page whose group of a kind holds only text or pictures doesn't list that
kind's layer. The pages' tests build scenes with Scene::new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bherbruck pushed a commit that referenced this pull request Nov 17, 2026
…9647)

* Paper PDF: sheets as the pages of one document (#4890 P1)

`paper_pdf_pages` writes several prepared scenes as the pages of one PDF, in order, each page its
own sheet's size. `paper_pdf` is now its one-page call and writes the same bytes as before.
- Object numbers come from one counter in the order the objects are written: the catalog, the page
  tree, each page then its content, the Info dictionary, then the layers. One page keeps 1 to 5 and
  layers from 6, as now. P2's fonts can take their numbers from the same counter.
- One layer for each kind across all pages, tagged as it is first painted, so a kind is the same
  layer on every page. Each page lists only the layers it paints.
- The pages share one allowance of content, `MAX_DRAWING_BYTES`. A document has 1 to 1000 pages
  (a drawing's sheets), and every page meets the one-page size check.
Tests, under their own heading in `pdf_tests.rs`: one page is the one-page call byte for byte, with
and without layers, a title and a date; three sheets of different sizes as pages in order, sharing
layers; the page limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Paper PDF: the pages on drawings, each page's layers by the one painted test (#4890 P1)

Replayed onto the rebased #7626. A page lists the layers of the kinds it
paints, now by the writer's one painted test (a stroke or a fill), so a
page whose group of a kind holds only text or pictures doesn't list that
kind's layer. The pages' tests build scenes with Scene::new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Paper PDF: pages are put on the grid one at a time, as they are written (#4890 P1)

paper_pdf_pages put every page on the grid before it wrote the first. Each page's
grid is capped, but up to 1000 pages of them were held at once, only to learn the
page sizes and the layers. The prepared scenes already say both.

Now a first pass reads each page's size and the layers from the scenes, and the
write loop puts one page on the grid just before it writes it, then drops it.
`painted` is asked of the scene's groups: each prepared stroke and fill stays one
on the grid, in order, and the loop refuses a page whose groups don't match. The
object numbers, the write order and the bytes are the same: the byte pins (the A3
sample, one page against pages, pages in order, the later page's 3 pt refusal)
pass as they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@CamWight
CamWight deleted the paper-pdf-4890-p1 branch November 17, 2026 20:59
bherbruck added a commit that referenced this pull request Nov 17, 2026
Brings in sheet PDF export (#7626, #9647).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved-for-ci Reviewed: run the full PR CI (build, tests, goldens, Clippy) area:io import/export and file formats (STEP, IGES, 3MF, glTF, designs) area:kernel B-rep kernel, booleans, blends, STEP/IGES

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants