Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions crates/render/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2531,10 +2531,16 @@ pub fn frame_coverage_judged_on(
Some((gw, gh, drawn))
}

/// The least lightness (0-255, weighted 3:6:1 as the renderer's greys are) of a background a
/// publication's dark legend text reads on without its box: Paper, Ocean and Atlas are lighter,
/// Midnight darker (#1379).
const LIGHT_BACKGROUND: u32 = 160;

/// Whether a frame showing `map` at 1:`scale` around `center`, `size` (mm) wide and tall, shows
/// one plain colour under `under` (mm from the frame's top left), the basemap's water or land
/// colour, and nothing else: no layer, label or context layer, no outline of the basemap's. Drawn as the map is, on a
/// grid of about `cells` cells across the frame's longer side, its label lock set aside (and put
/// colour and a light one ([`LIGHT_BACKGROUND`]), and nothing else: no layer, label or context
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
/// layer, no outline of the basemap's. Drawn as the map is, on a grid of about `cells` cells
/// across the frame's longer side, its label lock set aside (and put
/// back) as [`frame_coverage`] does. Web tiles aren't fetched for it, so a map with any is not
/// plain anywhere; nor is a frame that can't be drawn. For a publication's legend, which needs no
/// box there (#1379).
Expand Down Expand Up @@ -2586,10 +2592,12 @@ pub fn frame_plain_under(
let px = pm.pixels();
let mut seen = (r0..r1).flat_map(|r| (c0..c1).map(move |c| r * gw + c)).map(|i| px[i]);
// One colour, and that the basemap's water or land: a polygon filling the whole rectangle in
// one colour, data or context, isn't the background.
// one colour, data or context, isn't the background. And a light one: the legend's text is
// dark, so over a dark background (Midnight's) it keeps its box.
let rgba = |p: tiny_skia::PremultipliedColorU8| (p.red(), p.green(), p.blue(), p.alpha());
let Some(first) = seen.next().map(rgba) else { return false };
let background = [water, land].iter().any(|c| (c.0[0], c.0[1], c.0[2], 255) == first);
let light = |c: &Rgba| (3 * u32::from(c.0[0]) + 6 * u32::from(c.0[1]) + u32::from(c.0[2])) / 10 >= LIGHT_BACKGROUND;
Comment thread
elpidioassinaturas marked this conversation as resolved.
Resolved
let background = [water, land].iter().any(|c| (c.0[0], c.0[1], c.0[2], 255) == first && light(c));
background && seen.all(|p| rgba(p) == first)
}

Expand Down Expand Up @@ -3432,7 +3440,12 @@ mod tests {
// Earth basemap's water: that grey is the background there.
(map.body, map.basemap) = ("mars".into(), rustgis_map::Basemap::Paper);
assert!(plain(&mut map, (2.0, 86.0, 12.0, 12.0)), "Mars's plain grey is its background");
(map.body, map.basemap) = ("earth".into(), rustgis_map::Basemap::Blank);
// A dark background (Midnight's water) isn't plain for a legend: its dark text needs the box.
(map.body, map.basemap) = ("earth".into(), rustgis_map::Basemap::Midnight);
assert!(!plain(&mut map, (2.0, 86.0, 12.0, 12.0)), "Midnight's dark water keeps the box");
map.basemap = rustgis_map::Basemap::Ocean;
assert!(plain(&mut map, (2.0, 86.0, 12.0, 12.0)), "Ocean's light water is plain");
map.basemap = rustgis_map::Basemap::Blank;
map.tiles.push(rustgis_map::TileLayer::new("tiles", rustgis_map::TileKind::Raster, "https://example.invalid/{z}/{x}/{y}.png"));
assert!(!plain(&mut map, (2.0, 86.0, 12.0, 12.0)), "web tiles aren't fetched for it, so nothing is plain");
}
Expand Down
7 changes: 4 additions & 3 deletions docs/user-guide/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu
`"none"` leaves it out at any span.
- **Legend box**: over the map, the legend's box is left clear where the map shows nothing under
it but its plain paper or water: no layer, label, context layer, basemap shape or graticule
line, no web tiles, and no veil. Its text then sits on the page as on open sea. The answer's
`legendBox` says whether it has one; the clear box is still an element, to fill by hand, and
`"legendBox": "always"` keeps it white. A legend in a side column or on a card keeps its box
line, no web tiles, and no veil, on a light background (a dark one, such as the Midnight
basemap's, keeps the box under the legend's dark text). Its text then sits on the page as on
open sea. The answer's `legendBox` says whether it has one; the clear box is still an
element, to fill by hand, and `"legendBox": "always"` keeps it white. A legend in a side column or on a card keeps its box
(`legendBox` is `true`).
- **Decimal comma**: `"decimal": ","` prints the graticule, scale bar and colorbar numbers and
`{scale}` with a decimal comma and points between thousands (`0,05`, `1:6.300.000`).
Expand Down
Loading