Skip to content

fix(layout): say when a map frame's tile credits are cut off on export - #3565

Draft
jgregoriorincon wants to merge 5 commits into
opengeos:mainfrom
jgregoriorincon:fix/3474-frame-credit-cut
Draft

jgregoriorincon wants to merge 5 commits into
opengeos:mainfrom
jgregoriorincon:fix/3474-frame-credit-cut

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A layout map frame narrower than its tile layers' credits (several layers, or a small frame) cut the ends of the credit off, and nothing said so. An export now says which frames' credits don't fit, in one notice naming each frame by name and id (the first ten, and how many more): Map frame "Map Frame" (4): its tile credits don't fit in it, so their ends are cut off; make it larger, or show fewer tile layers in it. A report names the layout each frame is in.

A frame is said to cut its credit when no place in it holds all of it: a rectangle narrower than the credit, or a shape (circle, ellipse, polygon, lasso) with no row as wide as it (#3473 centres such a credit on the shape's widest row). It is known as the frame is drawn, so it costs nothing besides the drawing; the list is a per-thread collector opened around the export, the pattern unfitted_legends already uses, with no state kept between exports.

Two drawn changes, both from attribution_center keeping a credit's ends inside the frame when they can be: a credit that fits the frame but not with its 4 pt right margin used to lose its left end by up to 4 pt, and now goes into the margin and is drawn whole; a credit wider than the frame is now centred on it (it sat 4 pt left of the frame's middle), so it runs past both edges alike.

The same attribution_center draws the credit of the plain map export (share.exportMap, the map's PDF and SVG), so a credit that fits there also goes whole into the margin; that export's own silent cut of a credit wider than the view is not in this PR.

Not changed: where a credit that fits goes; the layout view on screen (as for legends that don't fit, the notice is the export's); the credit is not split over lines (a word wider than the frame would still be cut, so the notice would still be needed).

presentation.export says the notice too (a slide's size is a project field, so a long credit or a narrow slide cuts it), with the same collector; a PNG is the first page only.

Surfaces: the notice goes through Session::warn, so the desktop app, the browser, the command line and Python (take_notices) all get it, from the publication preview (its warnings), from layout.export (PNG, JPG, PDF, SVG, a page of a series, a region), from report.export and from presentation.export. No command, parameter, project format or UI text changes.

Testing

  • New tests in crates/render/src/layout/tests.rs: a frame says its credit is cut exactly when no place holds it (rectangle, circle, ellipse, triangle, two credits, none); a credit within the margin of the frame's width is drawn whole; a shape's verdict is the drawn credit's box against the shape (a fraction of a point wider isn't a cut, narrower is; a trapezoid swept against its edges; labels over the rows); the collector lists each frame once and nests; the notice's wording for one, two and twelve frames; a label over the rows that hold a shape's credit isn't a cut.

  • New crates/engine/src/tests/layout_credits.rs: with an MBTiles layer crediting a long text, a wide frame says nothing, a narrow one says so on PNG, SVG and PDF exports, two narrow frames are one notice, a frame with no tile layer says nothing, a report names the layout, and a presentation slide narrower than its credit says so.

  • deliver.sh: fmt, clippy (-D warnings, also with the schema feature), doctests, layers and schema pass. The workspace run is 11946 of 11954; the 8 failures (seven rustgis-geolibre tests and line_strokes_editor_edits_one_class) also fail on this machine without this change. A ui_shot export isn't attached because nothing in the interface changes; the notice is text.

UI evidence

No visible UI change: the only drawn difference is at most 4 pt in where a credit starts.

Related issue

Closes #3474

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Comment thread crates/render/src/layout/frame.rs Resolved
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code review

Reviewed the full diff (9 files) against pr-context/AGENTS.md. I could not build or run the tests (no shell here), so the compile and test results are unverified. I checked by reading that the helpers and imports the new code uses exist, and that the engine crate declares rusqlite and tiny-skia.

Bugs

  • Shape credit can be cut without a notice (crates/render/src/layout/frame.rs:221, confidence about 50%). cut is judged against the longest run anywhere in the shape, labels or not. But the credit is placed on the widest clear-of-labels segment, which can be shorter than the credit. Its ends then overhang the shape and get clipped, and nothing is reported. Suggested fix and a regression test are in the inline comment.

Security

  • None found.

Performance

  • None significant. The extra longest tracking is a constant-cost max inside a loop that already runs. The keep_drawn dedup is linear, but that is the existing pattern.

Quality

  • frame_canvas now takes a tuple parameter (pending, cut): (&mut bool, &mut bool). It works, but a small struct or a return value would read more clearly. Left for the release quality pass.
  • The "a label over the rows that hold a credit isn't a cut" test pins the verdict, not the placement, which is why the finding above got through. It may be worth a companion test.

AGENTS.md

  • No new break found. Checked: no project save or command surface change (no schema or command-surface.txt update needed); no std::time, threads, or unwrap in non-test code; test timer and assert_eq rules satisfied; the thread-local collector is only written on the calling thread, since frame drawing does not spawn workers.
  • Twins checked: the four export paths that collect drawn_charts/unfitted_legends (layout page, layout bytes for PNG/PDF, layout SVG, report pages) all now wrap cut_credits and call credit_notice. No wasm/desktop cfg branch changed.
  • Scope note, not introduced here: presentation.export still cuts credits silently on a slide narrower than the credit. The PR body discloses this as out of scope. Under "Never silent" it is a known gap for a follow-up.

Earlier concerns left alone: 0 (no prior review threads on this PR).

Change size

Compared with the base branch: the whole PR against main (merge base eaf74c0 to PR head 6fdd13a).

Files changed Added Modified Removed Renamed Size before Size after Total change
9 2 7 0 0 5.46 MB 5.48 MB +17.3 KB
Path Size before Size after Change
crates/render/src/layout/tests.rs 491.5 KB 497.5 KB +6.1 KB
crates/engine/src/tests/layout_credits.rs 0 B 4.9 KB +4.9 KB
crates/render/src/layout/credit.rs 0 B 3.2 KB +3.2 KB
crates/engine/src/cmd/report.rs 90.0 KB 91.2 KB +1.2 KB
crates/render/src/layout/frame.rs 37.4 KB 38.3 KB +0.8 KB
crates/engine/src/cmd/layout/export.rs 30.5 KB 31.1 KB +0.6 KB
crates/render/src/layout.rs 64.9 KB 65.2 KB +0.3 KB
crates/render/src/lib.rs 942.9 KB 943.0 KB +112 B
crates/engine/src/tests.rs 3.84 MB 3.84 MB +57 B

Comment thread crates/render/src/layout/credit.rs Resolved
Comment thread crates/render/src/layout/frame.rs Resolved
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code review

I read the full diff, the base-branch AGENTS.md, and the surrounding code, then checked the twin paths. I could not build or run the tests here, so every finding below comes from reading the code.

Bugs

  • Presentation export is not covered, so its cut credits are silent. presentation.export draws through layout::render and render_drawing with no cut_credits wrapper. The PR marks this as out of scope, but AGENTS.md says existing silent losses are bugs. Posted inline on credit.rs:37. Confidence about 50%, since it needs a slide narrower than its credit.
  • The shape cut verdict can flag a credit that fits, on huge shapes. room_there is counted in whole mask cells, and a cell counts only when fully inside the shape. At a scale below one, that can be off by a cell per side, so the notice can be wrong. Posted inline on frame.rs:219. Confidence about 30%.

The earlier thread (verdict versus placement disagreeing on a shape) is fixed in cb07128. The verdict now reads the placement, so I did not re-raise it.

Security

  • None found. The new code takes no external input beyond what the layout already holds, and the notice text is built from names that are already cut to a fixed length.

Performance

  • None new. The mask and attribution_in_shape existed before. The collector adds small linear scans over the list of cut frames.

Quality

  • frame_canvas now takes a (pending, cut) tuple of &mut bool. A small struct would make the call sites in draw_page easier to read. Nit, left for the release quality pass.
  • say_report_credits drops the layout name silently when the layout index is out of range, so the notice then has no "in layout" part. Minor.

AGENTS.md

  • No unwrap, expect or unsafe in the new non-test code. The notices go through Session::warn, one per kind with a count, and the tests cover lossy and clean input. The presentation gap above is the one rule break.

Twins checked

  • Layout exports: layout_page (PNG and JPG), layout_bytes_inner (PDF and PNG series) and layout_svg all wrap cut_credits and say the notice. Confirmed by grep.
  • Report paths: the PNG, PDF and overflow-picture branches all keep the credits and say them once.
  • Presentation: not covered (see above).
  • Preview paths (frame_map, frame_map_preview_with) discard the flag by design, since they are not exports.
  • No #[cfg(target_arch = "wasm32")] branch is changed in this diff. I did not run the wasm build.

I left one earlier concern alone, the verdict/placement disagreement, because it is already fixed in the head.

Change size

Compared: the whole PR against main (merge base eaf74c0 to PR head cb07128).

Measure Value
Files changed 9 (2 added, 7 modified, 0 removed, 0 renamed)
Size before 5.46 MB
Size after 5.48 MB
Total size change +18.1 KB
File Before After Change
crates/render/src/layout/tests.rs 491.4 KB 498.4 KB +6.9 KB
crates/engine/src/tests/layout_credits.rs 0 B 4.9 KB +4.9 KB
crates/render/src/layout/credit.rs 0 B 3.2 KB +3.2 KB
crates/engine/src/cmd/report.rs 90.0 KB 91.2 KB +1.2 KB
crates/render/src/layout/frame.rs 37.4 KB 38.2 KB +0.7 KB
crates/engine/src/cmd/layout/export.rs 30.5 KB 31.1 KB +0.6 KB
crates/render/src/layout.rs 64.9 KB 65.2 KB +0.3 KB
crates/render/src/lib.rs 942.9 KB 943.0 KB +112 B
crates/engine/src/tests.rs 3936.7 KB 3936.8 KB +57 B

Comment thread crates/render/src/layout/frame.rs Resolved
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code review

I read the full diff, the base-branch AGENTS.md, and the source around the changed code. I could not run the tests (no shell here), so everything below rests on reading the code.

Bugs

  • Two-cell slack hides real cuts (crates/render/src/layout/frame.rs:222, inline comment posted). The slack fixes the earlier false positive but creates a false negative: a credit cut by up to about two cells (about 2 pt on an ordinary frame, about 2.8 pt on A0) goes unreported. Nothing in the tests covers a shortfall of 0–2 pt. Confidence about 40%. This is a new point; the earlier thread asked for the opposite fix.

Security

  • None found.

Performance

  • None found. The collector is a per-thread Vec that holds one entry per cut frame, and credit_cut runs on the thread that draws the page. The thread::scope spawns in render run inside the frame, after which the caller records the cut, so they don't affect the collector.

Quality

  • frame_canvas now takes (pending, cut): (&mut bool, &mut bool). A returned struct or a tuple result would read more clearly than a tuple of out-parameters (frame.rs, frame_canvas signature).
  • frame_map (public, frame.rs:8) passes &mut false and drops the cut silently. The repo has no production caller, but as public API it is a silent-loss path. Confidence high it's harmless today, low that it stays that way.
  • The publication preview (crates/engine/src/cmd/layout/preview.rs:90–98) calls layout_page, so it now carries the credit notice in its warnings. That is consistent with the other layout notices, but the PR's "Reach every surface" list doesn't mention it. Ask the author to name it in the PR.

AGENTS.md

  • None found. The notices go through s.warn, the new code has no unwrap/expect, no new command or saved field is added (so no schema or snapshot change), and the tests cover both clean and lossy inputs.

Prior threads (left alone: 2)

  • The presentation-export silent-loss thread is answered, and the fix is in presentation.rs:534. Left alone.
  • The shape-verdict-vs-placement thread is answered, and cut now comes from the placement at frame.rs:222. Left alone.
  • The coarse-scale false-positive thread is answered; I raised its new side (the false negative) in the inline comment above.

Twins checked

  • Layout export: layout_page, layout_bytes_inner (PDF) and layout_svg all wrap the collector. Series and region paths reach them through these.
  • Report: listing wraps draw_page and pdf_page, and the overflowed re-draw is covered.
  • Presentation: export_within covers PNG, PDF and HTML, per the tests.
  • No #[cfg(target_arch = "wasm32")] branch is changed.

Change size

Compared with the base branch (merge base eaf74c0 to head 3dae5a5).

Files changed Added Modified Removed Renamed Size before Size after Total change
10 2 8 0 0 5.50 MB 5.52 MB +20.5 KB
Path Size before Size after Change
crates/render/src/layout/tests.rs 491.4 KB 499.1 KB +7.7 KB
crates/engine/src/tests/layout_credits.rs 0 B 6.1 KB +6.1 KB
crates/render/src/layout/credit.rs 0 B 3.2 KB +3.2 KB
crates/engine/src/cmd/report.rs 90.0 KB 91.2 KB +1.2 KB
crates/render/src/layout/frame.rs 37.4 KB 38.4 KB +1.0 KB
crates/engine/src/cmd/layout/export.rs 30.5 KB 31.1 KB +0.6 KB
crates/render/src/layout.rs 64.9 KB 65.2 KB +0.3 KB
crates/engine/src/cmd/presentation.rs 41.0 KB 41.3 KB +0.3 KB
crates/render/src/lib.rs 942.9 KB 943.0 KB +112 B
crates/engine/src/tests.rs 3.84 MB 3.84 MB +57 B

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3565/
Web app https://preview.rustgis.app/pr-3565/app/
Commit 3dae5a5

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

// The box [`attribution_inset`] keeps clear of the labels: the credit's width, its height with
// its halo.
let (x0, y0) = (crate::attribution_center(w, tw, right) - tw / 2.0, h - bottom - size * 0.9 - size * 0.8);
let (cols, rows) = ((tw * ppp).floor().max(1.0) as u32, (size * 1.6 * ppp).floor().max(1.0) as u32);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The verdict can miss a credit that overhangs the shape by less than one pixel. floor(tw * ppp) leaves out the credit's last partial pixel column, so the mask's right edge stops up to 1/ppp points short of the credit's right end. Whenever the shape's edge falls in that gap, contains(&0) never sees the overhang and the credit goes unsaid. That is the silent loss the earlier thread on this line asked to close. The loss is up to 0.5 pt at ppp 2, and up to 2 pt on a 36 dpi export (ppp 0.5, which the engine tests use). The non-anti-aliased fill tests pixel centres, so the box should count the pixel centres that lie below tw. That is ceil(tw * ppp - 0.5). The rows have the same truncation.

Suggested fix: count pixel centres inside the credit's box, and add a case to a_credit_is_said_cut_when_its_box_leaves_the_shape at ppp 0.5 with a fractional tw. The current cases pass only at the widths they use. I have not run the tests (no shell here), so the reasoning is from reading the code.

Category: bug

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code review

The PR adds a notice when a map frame's tile credit is wider than the frame, or than every row of its shape, so the credit's ends get cut off on export. I read the diff, the surrounding layout and export code, and the earlier review threads. I could not build or run the tests here (no shell), so everything below comes from reading the code.

Bugs

  • crates/render/src/layout/frame.rs:115: a cut credit can go unreported (confidence ~70%, inline comment posted). floor(tw * ppp) drops the credit's last partial pixel column, so a shape edge that falls in that gap is never tested. The loss is up to 0.5 pt at ppp 2 and up to 2 pt on a 36 dpi export. The same truncation applies to the rows.
  • Known gap, deferred by the PR (confidence high that it is real). share.exportMap draws the same credit, now into the margin, and still gives no notice. The PR body defers this. AGENTS.md says existing silent losses are bugs, so it should be tracked.
  • Low confidence (~10%). The let else { return false } in credit_leaves_frame reports "fits" silently if the mask or the shape path can't be built. I think this is unreachable in practice, because the frame's own draw uses the same shape path.

Security

  • None found.

Performance

  • None significant. The verdict builds one credit-sized mask per finished frame, including preview frames, which is negligible.

Quality

  • frame.rs:39: (pending, cut): (&mut bool, &mut bool) is an awkward tuple parameter for frame_canvas, which has three call sites. A small struct or a returned flag would read better.
  • export.rs (layout_page, layout_bytes_inner, layout_svg) and report.rs (listing) destructure nested tuples such as (((img, mut unfitted), mut charts), mut credits). This is readable but dense.
  • The test a_frame_says_when_its_attribution_is_cut_off says "attribution" where the notice says "credit".

AGENTS.md

  • No breaks found. The notice goes through Session::warn once per export, with a count. There are tests for both the lossy and the clean case. No command, parameter or saved format changes, so the schema and command-surface files need no update. The collector is per-thread and opened inside the existing export paths. By reading, the thread_local is fine for wasm, but I did not build it.

Earlier review threads

  • Four threads are already on the PR: presentation export (credit.rs:37) and three on the cut verdict (frame.rs:219, :221, :222). All four are resolved. I checked the fixes by reading (the presentation hook in presentation.rs:534, and the box-based verdict in frame.rs), and I left all four alone. The bug above is new, though it sits in the verdict those threads asked to close.

Surfaces checked (twins)

  • Layout export (PNG, PDF, SVG, region, series): wrapped by the collector.
  • Report (PNG, PDF, overflowed page): wrapped.
  • Presentation export: wrapped.
  • Publication preview: reaches the notice through layout_page.
  • UI preview paths (reportpane.rs, render_preview): no notice, by design.
  • share.exportMap: not wrapped, as the PR says.
  • Frame-map helpers: none has an export caller.

Change size

Compared with the base branch (merge base eaf74c0 to PR head fd0a020). The stats are not truncated.

Measure Value
Files changed 10 (2 added, 8 modified, 0 removed, 0 renamed)
Size before 5.50 MB
Size after 5.52 MB
Total size change +23.1 KB
Path Before After Change
crates/render/src/layout/tests.rs 491.4 KB 500.7 KB +9.3 KB
crates/engine/src/tests/layout_credits.rs 0 B 6.1 KB +6.1 KB
crates/render/src/layout/credit.rs 0 B 3.2 KB +3.2 KB
crates/render/src/layout/frame.rs 37.4 KB 39.4 KB +2.0 KB
crates/engine/src/cmd/report.rs 90.0 KB 91.2 KB +1.2 KB
crates/engine/src/cmd/layout/export.rs 30.5 KB 31.1 KB +651 B
crates/render/src/layout.rs 64.9 KB 65.2 KB +313 B
crates/engine/src/cmd/presentation.rs 41.0 KB 41.3 KB +264 B
crates/render/src/lib.rs 942.9 KB 943.0 KB +112 B
crates/engine/src/tests.rs 3.84 MB 3.84 MB +57 B

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A layout map frame narrower than its tile credits cuts them off without saying so

1 participant