Skip to content

Paper text: retain each label's logical source and run ranges (#12035) - #12039

Merged
selun3 merged 1 commit into
tangency-labs:drawingsfrom
selun3:codex/drawings-paper-text-source-20261104
Nov 15, 2026
Merged

selun3 merged 1 commit into
tangency-labs:drawingsfrom
selun3:codex/drawings-paper-text-source-20261104

Conversation

@selun3

@selun3 selun3 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Change

Paper text producers retain a label’s original UTF-8 source alongside the exact shaped records a consumer receives. Fixes #12035.

The additive PaperSourceFlow API records wrapped runs as source spans, preserving line breaks and omitted whitespace. Validation rejects changed glyphs, clusters, font identity, placement, text or run order. Existing PaperTextFlow, run_ranges, measurement and font-loading contracts remain intact. The PDF consumer and checked-font snapshots remain separate P2 work; B1/F4 design review remains pending.

Current Drawings integration also removes the unused private left_inset helper after the shared Browser panel removed its last caller. One test compares its single expected range through std::slice::from_ref, preserving the same range and satisfying strict Clippy.

Changes a default: no

Validation

On exact tree 7cb7877895114e77219cccfd7fca4a4d7a728cbb, the actual freshly compiled Sketch executable passed all 61 paper-text tests, including all 11 owned cases. Its actual test inventory, source/index and executable hashes were checked. No test was ignored or omitted from this focused selection.

Full cargo xtask ci completed on that exact tree: 17,190 passed, 31 failed, 75 skipped. All 61 paper-text tests, including all 11 owned cases, passed in this full run as well. Strict workspace Clippy, shared-crate checks, WebAssembly checks (29 crates), and documentation tests passed. The repository policy check reports 17 known failures and 14 unlisted failures and exits nonzero. No full-gate pass or baseline qualification for every unlisted failure is claimed; web checks were not reached after native failure. Actual source/index and executable guards remained unchanged.

The preceding 6b74a604 full gate failed strict Clippy on the single-range array assertion. That failed gate and its separate 61-test focused pass remain archived. The correction changes only the assertion’s equivalent slice expression; all production bytes and other test assertions are unchanged. The earlier copied-cache run lacked the 11 owned cases and is not qualification for this unit.

This unit adds source-association metadata, with no application or IO consumer and no new rendered output. The tests compare flowed and ordinary paint records/fonts exactly, retain original whitespace and UTF-8 spans, and reject altered records. No old image is presented as new evidence. PDF visual and extraction evidence belongs to the separate consumer.

Native run: 4d417901-7c51-49d1-af07-9a9e85aef248. The terminal raw gate, JUnit, policy output, actual Sketch inventory/executable and source snapshot are preserved locally. Publication retains the exact tested tree; it is not a separate test run on the resulting commit.

Integration status

Integrated on drawings@8a0b1fdfe164cba6dc654880b7495a7b81d15c9b. Current paper-line/font APIs and upstream exports are retained. This update resolves the old branch conflicts while retaining upstream APIs. The full gate is non-green as disclosed above; maintainer review and approved remote CI remain necessary.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor
Pre-merge checks: Passed 1

Check name Status Explanation
Existing Defaults Unchanged Passed The PR commit e187967 ("fix(paper): retain source spans on current drawings (#12035)") changes four files. None of the changes alters a user-facing default. - crates/sketch/src/lib.rs: adds re-export…
Full details: Existing Defaults Unchanged

Explanation

The PR commit e187967 ("fix(paper): retain source spans on current drawings (#12035)") changes four files. None of the changes alters a user-facing default. - crates/sketch/src/lib.rs: adds re-exports for new items (FlowedPaperText, PaperSourceFlow, PaperTextFlow, paper_text_with_flow*). This is additive API surface. - crates/sketch/src/paper_text.rs: adds PaperTextFlow, PaperSourceFlow, FlowedPaperText and paper_text_with_flow* functions. It also adds source, source_spans and wrapped fields to PaperLines. The wrap logic in measure() keeps the same wrap decisions and the same painted text. The change tracks original byte offsets alongside it. The existing paper_text/paper_lines entry points keep their behaviour. - crates/ui-egui/src/drawing_workspace.rs: removes the unused pub(crate) left_inset helper. The removed code had no caller after the Browser panel change, so no UI layout or behaviour changes. - crates/sketch/src/paper_text_tests.rs: adds tests only. No preference value, default setting, command default, UI default layout, or shortcut is changed. The description's "Changes a default: no" line is consistent with the code. The check only applies to UX defaults, so kernel or geometry results (solidcore) are out of scope and were not changed anyway.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@CamWight

CamWight commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Thanks @0xlillith, this is a clean, careful slice, and it's what we hoped for when we asked for it on #4890. I read the diff in full against set_text, run_records and the layout code under them, and against where the runs go next in the drawing scene.

What's good

  • Nothing about today's text changes. set_text hands None to the new set_text_records, and the only new work in the old path is one offset sum per line (paper_text.rs:400). The Scene and TextRun shapes are untouched, so SVG, PNG, DXF, the saved format and wasm see nothing new. sha2 is already a dependency, so there's no new crate either.
  • The ranges come from the right place. Each range is the laid-out run's own run.text plus the line's offset (paper_text.rs:382-392), and run_records cuts TextRun::text out of the line with the same range. So the "range equals the run's text" check holds by construction and can never drift from what the shaper did. Paint order is kept because ranges and runs are pushed in the same loop.
  • The coverage rule is exactly right. Every non-LF byte belongs to exactly one run, and the gaps are only line breaks (paper_text.rs:158-178). I checked the producer can't break it in normal use: laid_out makes one run over the whole line, mixed_line's pieces are never empty, and only an empty line loses its run. If that ever changed, issue would refuse instead of binding the wrong text, which is the safe way round.
  • The tests are thorough. Mixed direction with marks, LF and empty lines, all-LF input, a real fallback font, each of the 15 fields a writer could change, reordered and doubled runs, two equal strings on different baselines, and the bounds. Like for like against the old API in each case is a good habit.

A few things worth a look

  1. Placement is in the fingerprint, and the scene moves runs after they're made. flow_fingerprint hashes origin, scale and angle (paper_text.rs:240). In the drawing scene, Assembly::add moves each group to its place with moved(), which rewrites every text run's origin (crates/engine/src/drawing_scene.rs:313 and :446 on today's drawings). So any text in a group placed that way would fail check_runs on its way into the PDF, even though nothing changed but where it sits. This doesn't need a change here. It's something P2 has to settle: issue the flow after placement, check before the move, or carry the move. Worth a line in the PR text so whoever wires the scene knows.
  2. Which scene runs belong to which label is still open. This matches Paper text: retain a label’s logical source beside its paint-order runs #12035's choice to keep the Scene shapes. But once the runs are Item::Text items in a group, nothing ties them back to their FlowedPaperText, so check_runs has to be handed exactly one label's runs. That's the grouping question from our earlier reply, now on P2's side. Again, just worth saying in the text.
  3. The whole label is bounded by the per-run byte cap (paper_text.rs:152, text.len() > MAX_RUN_TEXT_BYTES). Today that's harmless, because 1,000 characters of at most 4 bytes is exactly 4,000. But it ties two unrelated limits together: if MAX_TEXT_CHARS ever grows, the flow API would refuse labels the old API accepts. A bound in terms of MAX_TEXT_CHARS (4 bytes a character), or a comment saying why the two agree, would keep them from drifting.
  4. issue hashes every run twice. It builds the fingerprints (:183), then calls check_runs, which hashes them again and compares them with what it just made (:189). The cost is small (SHA-256 over at most a label's glyphs), but the second pass can't fail, since it re-checks the same runs, ranges and text the loop above already checked. Dropping it would also leave check_runs with a single job: the writer's check.
  5. Small tidy-ups, take or leave:
    • paper_text_with_flow has seven arguments, so it doesn't need #[allow(clippy::too_many_arguments)] (:263). paper_text beside it has none.
    • The use lines inside issue and flow_fingerprint (:150, :226-227) could join the file's import block from the same module (:44).
    • The run-count bound is checked both in the loop (:383) and in issue (:153). One place would do, since each run holds at least one character.
    • The new public accessors (text, run_ranges, runs, fonts, flow, into_parts) have no doc lines, while every other public item in the file has one.

Looking ahead, not for this PR. With both sets in, paper_text* and paper_text_with_flow* are six public entry points into one producer, with an out-parameter (Option<&mut Vec<_>>) threaded through it. Once P2 is reading the flow, one of the two sets can probably go, so writers have one way in.

Checks on my side, on the PR head: the 49 paper-text tests pass (cargo test -p solidcraft-sketch --lib -- paper_text), and solidcraft-sketch checks for wasm32-unknown-unknown.

Nice work. Points 1 and 2 are the ones I'd want written down before P2 starts, and the rest are small.

@CamWight

CamWight commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Hi @0xlillith, a heads-up so our two pieces join cleanly. #12349 (merged into drawings today) changes the same line loop in paper_text.rs as this PR. It splits setting text into measuring the lines first (paper_lines) and then placing them (PaperLines::set), so a title block cell can break a long value between words to fit its box. paper_text becomes those two steps, with the same results.

When the two meet, the run ranges would be recorded in PaperLines::set, where the loop now lives. Since ours landed first, we're happy to help carry it across if that's useful.

One point to settle, nothing urgent: a wrapped line is the value's words put back one space apart. So between two wrapped lines, the original text has a space (or several), not a line break, and issue's rule that only LF may sit between runs would refuse a wrapped value. We'd suggest taking a wrapped value's ranges from its words, so the gaps are the spaces the wrap removed and the rule allows those. That keeps every title block value searchable and copyable in the PDF's text layer, including the tolerances note every new part drawing starts with, which already wraps to two lines. The other way, issuing a flow only for text that isn't wrapped, would leave those values out of it. Nothing wraps on a sheet until #12357, so there's time.

@CamWight

CamWight commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Hi @0xlillith, a small offer for this PR now that #12846 is on drawings.

#12846 added PaperFonts in crates/sketch/src/paper_text.rs. It holds a drawing's font family, language and font folders once, plus whether to wait for a fallback font or ask the search thread. lines and text are its two methods, and the title block and the dimensions now set their text through it. The point was one rule for how sheet text waits for fonts.

paper_text_with_flow, _with_flow_in and _with_flow_now carry those same choices as arguments: folders, family, language, and wait or now. One PaperFonts::text_with_flow method beside text could replace all three. Then flowed text would wait for fonts exactly as the rest of the sheet does, and a later change to that rule would reach it too.

Entirely your call. If it helps, we can also make that change as a small follow-up once this lands.

@selun3

selun3 commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for both integration notes. The current source port records the mapping in PaperLines::set_with_flow and adds PaperFonts::text_with_flow through the sheet’s existing measurement/font-waiting path.

Wrapped runs carry source word spans, preserving the removed whitespace as explicit gaps. The original contiguous run_ranges contract remains available for unwrapped text; wrapped source uses a separate run_spans API. The existing tests are retained, with additional wrapping and PaperFonts coverage.

This is source-prepared and independently reviewed, not yet runtime-qualified. P2’s final-placement binding remains separate consumer work; this update does not claim that placement issue is solved.

@bherbruck

Copy link
Copy Markdown
Collaborator

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

@selun3

selun3 commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

The paper-text source-flow change is now ported to Drawings 8a0b1fdfe164cba6dc654880b7495a7b81d15c9b. The two implementation/test files are unchanged from the prepared version; the library exports retain the new upstream additions.

The source-flow API still preserves wrapped UTF-8 spans alongside the existing measurement and font path. Existing compatibility wrappers remain. Current-base compilation and tests are pending before the branch update is pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sketch sketcher and constraint solver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants