diff --git a/crates/data/src/loss.rs b/crates/data/src/loss.rs index 2f2add709d..e8a1c6ac1b 100644 --- a/crates/data/src/loss.rs +++ b/crates/data/src/loss.rs @@ -149,6 +149,12 @@ loss_codes! { "RustGIS read only part of the data because it is past a size limit.", "Read less at once, such as by filtering or clipping the source first, or keep fewer fields (columns) in it." ), + DroppedGlyph => ( + "dropped.glyph", + Dropped, + "Text characters were left out of a drawing because the fonts available to RustGIS do not have glyphs for them.", + "Make a font that covers those characters available to RustGIS and draw or export again. For Japanese, Chinese or Korean, try Noto Sans CJK.", + ), ChangedCsvGuard => ( "changed.csv-guard", Changed, diff --git a/crates/engine/src/cmd/block_model.rs b/crates/engine/src/cmd/block_model.rs index 2c77e4703c..c0b803e5ab 100644 --- a/crates/engine/src/cmd/block_model.rs +++ b/crates/engine/src/cmd/block_model.rs @@ -104,6 +104,7 @@ pub(crate) fn export_work(s: &Session, p: &Value) -> Result Result Result, + notes: Vec, + written: Result, + path: String, +) -> Result { + let mut coded = rustgis_data::loss::Notes::new(); + if written.is_ok() { + for note in notes { + if note.loss.is_some() { + coded.push(note); + } else { + diagnostics.push((rustgis_data::diagnostics::Severity::Warning, note.text)); + } + } + } + let mut wrote = drawn(maps, diagnostics, written, path)?; + wrote.notes = coded; + Ok(wrote) +} + /// [`drawn`] for an export drawn on `copy`, a copy of the session: what drawing it said, a loss /// kept with its code and said with the export's notes ([`copy_notices_coded`]). pub(crate) fn drawn_on(copy: &mut Session, written: Result, path: String) -> Result { diff --git a/crates/engine/src/cmd/layout/export.rs b/crates/engine/src/cmd/layout/export.rs index aaab9e8d20..95d4092b62 100644 --- a/crates/engine/src/cmd/layout/export.rs +++ b/crates/engine/src/cmd/layout/export.rs @@ -349,8 +349,8 @@ pub(in crate::cmd::layout) fn layout_bytes_inner( rustgis_render::layout::drawn_charts(|| rustgis_render::layout::unfitted_legends(|| rustgis_render::shadows_said(render_pages))) }); if result.is_ok() { - for w in crate::cmd::share::shadow_warnings("The layout", &said) { - s.warn(w); + for w in crate::cmd::share::shadow_warnings("The layout", said) { + s.say_warning(w); } } // Stepping through the series moved the frame; put the layout back however that went. @@ -612,11 +612,13 @@ fn layout_svg(s: &mut Session, li: usize, dpi: f64, download: Option<(crate::cmd let gaps = rustgis_render::layout::sections_not_drawn(layout, &s.project.maps).into_iter().map(|g| (g, 1)).collect(); let grey = rustgis_render::layout::pictures_not_drawn(layout); let profiles: ProfileNotes = rustgis_render::layout::profiles_not_drawn(layout, &s.project.maps).into_iter().map(|n| (n, 1)).collect(); - let (((drawn, unfitted), charts), credits) = rustgis_render::layout::cut_credits(|| { + let ((((drawn, said), unfitted), charts), credits) = rustgis_render::layout::cut_credits(|| { rustgis_render::layout::drawn_charts(|| { rustgis_render::layout::unfitted_legends(|| { - crate::cmd::exports::held_to(download, |limit| { - rustgis_render::svg::layout_svg_within(layout, &mut s.project.maps, dpi, &info, limit) + rustgis_render::shadows_said(|| { + crate::cmd::exports::held_to(download, |limit| { + rustgis_render::svg::layout_svg_within(layout, &mut s.project.maps, dpi, &info, limit) + }) }) }) }) @@ -625,6 +627,9 @@ fn layout_svg(s: &mut Session, li: usize, dpi: f64, download: Option<(crate::cmd let chart_notes = chart_notice_lines(layout, &charts); // After drawing, as the other exports count. let cut = rustgis_render::layout::tables_cut(layout, &s.project.maps, dpi); + for note in crate::cmd::share::shadow_warnings("The layout", said) { + s.say_warning(note); + } for note in [note, rustgis_render::layout::sections_notice(&gaps, 1)].into_iter().flatten() { s.warn(note); } diff --git a/crates/engine/src/cmd/share.rs b/crates/engine/src/cmd/share.rs index d4c70d1e60..17f9ed4c50 100644 --- a/crates/engine/src/cmd/share.rs +++ b/crates/engine/src/cmd/share.rs @@ -9,6 +9,7 @@ use std::path::Path; use rustgis_data::capped::Limit; use rustgis_data::io::{DeclarationChanges, GpkgMode, GpkgTable, GpkgWritten, PathWritten}; +use rustgis_data::loss::Note; use rustgis_data::raster::Crs; use rustgis_render::View; use serde_json::{Value, json}; @@ -325,8 +326,8 @@ pub(super) fn map_png_unsaid(s: &mut Session, width: Option, height: Option pub(crate) fn saying_shadows(s: &mut Session, what: &str, draw: impl FnOnce(&mut Session) -> Result) -> Result { let (drawn, said) = rustgis_render::shadows_said(|| draw(s)); if drawn.is_ok() { - for w in shadow_warnings(what, &said) { - s.warn(w); + for w in shadow_warnings(what, said) { + s.say_warning(w); } } drawn @@ -336,12 +337,12 @@ pub(crate) fn saying_shadows(s: &mut Session, what: &str, draw: impl FnOnce(& /// and, drawn on the interface's thread (which doesn't wait for them: an image, a print, or a /// file exported there, by a script or while a style's view loads), that some were still being /// worked out. What was drawn is written all the same. -pub(crate) fn shadow_warnings(what: &str, said: &rustgis_render::ShadowsSaid) -> Vec { - let mut out: Vec = said.notices.iter().map(|e| format!("{what}: {e}")).collect(); +pub(crate) fn shadow_warnings(what: &str, said: rustgis_render::ShadowsSaid) -> Vec { + let mut out: Vec<_> = said.notices.into_iter().map(|note| note.prefixed(what)).collect(); if said.to_come { out.push(format!( "{what}: made without the cast shadows or sky visibility still being worked out, as the window doesn't wait for them: once the map shows them, draw or export it again" - )); + ).into()); } out } @@ -564,7 +565,7 @@ pub(crate) fn map_work(s: &Session, p: &Value) -> Result { }) }); let png = png?; - shadows = shadow_warnings(&path, &said); + shadows = shadow_warnings(&path, said); rustgis_data::progress::check().map_err(|e| e.to_string())?; let bytes = png.len(); held = super::exports::place(download.is_some(), &path, png)?; @@ -572,13 +573,9 @@ pub(crate) fn map_work(s: &Session, p: &Value) -> Result { })(); // What the size limit did, and layers drawn without their cast shadows, are said of a // file written. - let sized = if written.is_ok() { - let warn = rustgis_data::diagnostics::Severity::Warning; - sized.into_iter().chain(shadows.into_iter().map(|e| (warn, e))).collect() - } else { - Vec::new() - }; - super::exports::drawn(std::slice::from_ref(&map), sized, written, path).map(|wrote| Wrote { download: held, ..wrote }) + let sized = if written.is_ok() { sized } else { Vec::new() }; + super::exports::drawn_with_notes(std::slice::from_ref(&map), sized, shadows, written, path) + .map(|wrote| Wrote { download: held, ..wrote }) })) } @@ -629,14 +626,13 @@ fn geotiff_work( let download = s.download_room()?; Ok(Box::new(move || { let mut notices = notices; + let mut gaps = Vec::new(); let mut held = None; let mut copyright_loss = None; let written = (|| { let placed = rustgis_render::render_placed(&mut map, &view)?; rustgis_data::progress::check().map_err(|e| e.to_string())?; - for gap in &placed.gaps { - notices.push((rustgis_data::diagnostics::Severity::Warning, format!("{path}: {gap}"))); - } + gaps = placed.gaps.into_iter().map(|note| note.prefixed(&path)).collect(); let credits = placed.credits; // The drawn picture is dropped once its bands are made, before the raster's // statistics and the file's encoding. @@ -683,7 +679,7 @@ fn geotiff_work( if written.is_ok() { notices.splice(0..0, sized); } - super::exports::drawn(std::slice::from_ref(&map), notices, written, path).map(|mut wrote| { + super::exports::drawn_with_notes(std::slice::from_ref(&map), notices, gaps, written, path).map(|mut wrote| { if let Some(note) = copyright_loss { wrote.notes.insert(0, note); } diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index 785ca73e4f..b2d3719bf3 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -280,13 +280,11 @@ pub(crate) fn orbit_work(s: &Session, p: &Value) -> Result = notes.iter().filter(|n| n.loss() == Some(LossCode::DroppedGlyph)).collect(); + if losses.len() != count + || losses + .iter() + .any(|n| !n.text.contains(subject) || !n.text.contains("2 distinct characters") || !n.text.contains("Noto Sans CJK")) + { + failures.push(format!("{file} / {text}, expected {count} glyph loss(es) for {subject}: {notes:?}")); + } + } + } + assert!(failures.is_empty(), "{}", failures.join("\n")); +} diff --git a/crates/render/src/approximations.rs b/crates/render/src/approximations.rs index caa14df40f..715a5e9103 100644 --- a/crates/render/src/approximations.rs +++ b/crates/render/src/approximations.rs @@ -13,13 +13,69 @@ //! map view's [`Relay`] for the map view to take with its own. use std::cell::{Cell, RefCell}; +use std::collections::BTreeSet; -/// The most notices a thread (or the relay) keeps unread: a thread whose frames nobody reads (a -/// pass drawn and thrown away) never holds more. +use rustgis_data::loss::{LossCode, Note}; + +/// The most individual notices a thread (or the relay) keeps unread. Glyph losses from further +/// subjects share one extra notice so a full store still reports their loss code. const KEPT: usize = 64; +const EXTRA_GLYPHS: &str = "\0more-missing-glyphs"; /// One thing approximated: its kind (the layer and what), and what to say of it. -type Entry = (String, String); +type Entry = (String, Detail); + +#[derive(Debug)] +pub(crate) enum Detail { + Text(String), + Glyphs { subject: String, missing: MissingGlyphs }, +} + +impl Detail { + fn into_note(self) -> Note { + match self { + Self::Text(text) => Note::plain(text), + Self::Glyphs { subject, missing } => { + let sample = missing.chars.iter().take(8).map(|c| format!("U+{:04X}", u32::from(*c))).collect::>().join(", "); + let count = if missing.more { format!("at least {}", missing.chars.len()) } else { missing.chars.len().to_string() }; + let skipped = if missing.label_left_out { "Label text was left out. " } else { "" }; + Note::loss( + LossCode::DroppedGlyph, + format!( + "{subject}: {skipped}{count} distinct characters couldn't be drawn because their glyphs aren't available in the current fonts ({sample}). {}", + LossCode::DroppedGlyph.spec().action, + ), + ) + } + } + } +} + +/// Distinct omitted characters, bounded even when a layer contains many scripts. +#[derive(Debug, Default)] +pub(crate) struct MissingGlyphs { + chars: BTreeSet, + more: bool, + label_left_out: bool, +} + +impl MissingGlyphs { + fn add(&mut self, chars: impl IntoIterator) { + for c in chars { + if self.chars.len() < 256 { + self.chars.insert(c); + } else if !self.chars.contains(&c) { + self.more = true; + } + } + } + + fn merge(&mut self, other: Self) { + self.add(other.chars); + self.more |= other.more; + self.label_left_out |= other.label_left_out; + } +} thread_local! { /// What frames drawn on this thread approximated, each kind once, since [`take`]. @@ -28,13 +84,15 @@ thread_local! { static LAYER: RefCell> = const { RefCell::new(None) }; /// How many dashed lines of [`LAYER`] were drawn solid ([`dashes_drawn_solid`]). static SOLID_DASHES: Cell = const { Cell::new(0) }; - /// Distinct glyphs actually omitted while drawing, not characters merely measured. - static MISSING_GLYPHS: RefCell> = const { RefCell::new(std::collections::BTreeSet::new()) }; + /// Distinct glyphs omitted while drawing. `None` while a layout probe draws. + static MISSING_GLYPHS: RefCell> = const { RefCell::new(Some(MissingGlyphs { + chars: BTreeSet::new(), more: false, label_left_out: false, + })) }; + /// The layout element responsible for text drawn outside a map layer. + static ELEMENT: RefCell> = const { RefCell::new(None) }; /// How many points of each layer (by name) a frame left out of the obstacles for labels, since /// they were last said ([`obstacles_left_out`]). static OBSTACLES_LEFT: RefCell> = const { RefCell::new(std::collections::BTreeMap::new()) }; - static MORE_GLYPHS: Cell = const { Cell::new(false) }; - static MISSING_LABEL_TEXT: Cell = const { Cell::new(false) }; /// Whether a selected feature's highlight is being drawn ([`Highlighting`]): its redraws of a /// line already drawn aren't counted again. static HIGHLIGHTING: Cell = const { Cell::new(false) }; @@ -74,28 +132,41 @@ impl Relay { } } -/// Adds `entry` to `to`, unless its kind is there already; `false` when `to` holds [`KEPT`] and -/// the kind is turned away. +/// Adds or merges an entry. Past [`KEPT`] subjects, glyph losses share a coded summary at the +/// end of `to`; other entries are turned away (returns `false`). fn add(to: &mut Vec, entry: Entry) -> bool { - if to.iter().any(|(k, _)| *k == entry.0) { + if let Some((_, detail)) = to.iter_mut().find(|(k, _)| *k == entry.0) { + if let (Detail::Glyphs { missing, .. }, Detail::Glyphs { missing: other, .. }) = (detail, entry.1) { + missing.merge(other); + } + return true; + } + let has_summary = to.last().is_some_and(|(key, _)| key == EXTRA_GLYPHS); + let kept = to.len() - usize::from(has_summary); + if kept < KEPT && entry.0 != EXTRA_GLYPHS { + to.insert(kept, entry); return true; } - if to.len() >= KEPT { + let Detail::Glyphs { missing, .. } = entry.1 else { return false; + }; + if let Some((_, Detail::Glyphs { missing: total, .. })) = to.last_mut().filter(|(key, _)| key == EXTRA_GLYPHS) { + total.merge(missing); + } else { + to.push((EXTRA_GLYPHS.to_string(), Detail::Glyphs { subject: "Additional drawing text".to_string(), missing })); } - to.push(entry); true } /// What to say of `n` kinds turned away, as one more entry of its own. fn turned_away(n: usize) -> Entry { - ("\0more".to_string(), format!("{n} more kind(s) of approximation in the map's frames weren't kept to be said")) + ("\0more".to_string(), Detail::Text(format!("{n} more kind(s) of approximation in the map's frames weren't kept to be said"))) } /// Keeps `text` under kind `key`, unless this thread keeps that kind already; past [`KEPT`] kinds, /// it is counted as turned away instead, and the count said when they are taken. pub(crate) fn note(key: String, text: String) { - if !SAID.with(|s| add(&mut s.borrow_mut(), (key, text))) { + if !SAID.with(|s| add(&mut s.borrow_mut(), (key, Detail::Text(text)))) { turn_away(1); } } @@ -107,9 +178,9 @@ fn turn_away(n: usize) { /// What frames drawn on this thread approximated since the last call, each kind once (and how /// many kinds were turned away, as one more notice), and forgets it. -pub(crate) fn take() -> Vec { +pub(crate) fn take() -> Vec { let (entries, n) = keep(); - entries.into_iter().chain((n > 0).then(|| turned_away(n))).map(|(_, t)| t).collect() + entries.into_iter().chain((n > 0).then(|| turned_away(n))).map(|(_, detail)| detail.into_note()).collect() } /// What frames drawn on this thread approximated so far, with their kinds, and how many kinds were @@ -126,7 +197,7 @@ pub(crate) fn keep() -> (Vec, usize) { /// [`take`] with each notice's kind, and what workers handed over to `relays` ([`Relay`]), the /// kinds turned away by all said in one more notice: for the map view, which says each kind once /// a project. -pub(crate) fn take_keyed(relays: &[&Relay]) -> Vec { +pub(crate) fn take_keyed(relays: &[&Relay]) -> Vec<(String, Note)> { let (mut out, mut n) = keep(); for relay in relays { let (entries, m) = relay.take(); @@ -140,7 +211,7 @@ pub(crate) fn take_keyed(relays: &[&Relay]) -> Vec { if n > 0 { out.push(turned_away(n)); } - out + out.into_iter().map(|(key, detail)| (key, detail.into_note())).collect() } /// Puts what [`keep`] took back in front of what frames said since: what a caller took to read on @@ -221,14 +292,9 @@ fn flush_stray_dashes() { /// Counts distinct unavailable glyphs actually omitted from text or replaced by a marker's /// fallback shape. Deduplication also prevents halos and repeated painting from inflating counts. pub(crate) fn missing_glyphs(chars: impl IntoIterator) { - MISSING_GLYPHS.with(|missing| { - let mut missing = missing.borrow_mut(); - for c in chars { - if missing.len() < 256 { - missing.insert(c); - } else if !missing.contains(&c) { - MORE_GLYPHS.with(|more| more.set(true)); - } + MISSING_GLYPHS.with(|pending| { + if let Some(missing) = pending.borrow_mut().as_mut() { + missing.add(chars); } }); } @@ -236,35 +302,76 @@ pub(crate) fn missing_glyphs(chars: impl IntoIterator) { /// Records that unsupported text was filtered before tile placement, without counting duplicate /// copies of the same label from adjacent tiles. pub(crate) fn missing_label_line() { - MISSING_LABEL_TEXT.with(|c| c.set(true)); + MISSING_GLYPHS.with(|pending| { + if let Some(missing) = pending.borrow_mut().as_mut() { + missing.label_left_out = true; + } + }); +} + +/// Suspends glyph collection for trial drawings, saving the caller's pending characters. +pub(crate) struct IgnoreMissingGlyphs(Option); + +impl IgnoreMissingGlyphs { + pub(crate) fn start() -> Self { + Self(MISSING_GLYPHS.with(|pending| pending.replace(None))) + } +} + +impl Drop for IgnoreMissingGlyphs { + fn drop(&mut self) { + MISSING_GLYPHS.with(|pending| pending.replace(self.0.take())); + } +} + +/// Attributes text outside nested map layers to the layout element actually drawn. +pub(crate) struct GlyphElement(Option); + +impl GlyphElement { + pub(crate) fn new(layout: &rustgis_map::layout::Layout, element: &rustgis_map::layout::Element) -> Self { + flush_missing_glyphs(); + let name = if element.name.trim().is_empty() { element.kind.code() } else { &element.name }; + let subject = format!("Layout {:?}, {name} ({})", layout.name, element.id); + Self(ELEMENT.with(|e| e.replace(Some(subject)))) + } } -/// Carries actual missing-glyph notices through the existing frame/export relay, once per layer. +impl Drop for GlyphElement { + fn drop(&mut self) { + flush_missing_glyphs(); + ELEMENT.with(|e| e.replace(self.0.take())); + } +} + +/// Records characters under the layer or element that drew them. Later runs of the same layer's +/// labels, or later pages with the same element, add distinct characters to the same notice. fn flush_missing_glyphs() { - let missing = MISSING_GLYPHS.with(|c| std::mem::take(&mut *c.borrow_mut())); - let more = MORE_GLYPHS.with(|c| c.replace(false)); - let lines = MISSING_LABEL_TEXT.with(|c| c.replace(false)); - if missing.is_empty() { + let Some(missing) = MISSING_GLYPHS.with(|pending| pending.borrow_mut().as_mut().map(std::mem::take)) else { + return; + }; + if missing.chars.is_empty() { return; } - let name = LAYER.with(|l| l.borrow().clone()).unwrap_or_else(|| "Text outside any layer".into()); - let sample = missing.iter().take(8).map(|c| format!("U+{:04X}", u32::from(*c))).collect::>().join(", "); - let count = if more { format!("at least {}", missing.len()) } else { missing.len().to_string() }; - let skipped = if lines { "Label text was left out; " } else { "" }; - note( - format!("{name}\0missing-glyphs"), - format!( - "{name}: {skipped}{count} distinct characters couldn't be drawn because their glyphs aren't available in the current fonts ({sample})." - ), - ); + let layer = LAYER.with(|l| l.borrow().clone()); + let element = ELEMENT.with(|e| e.borrow().clone()); + let (key, subject) = match (layer, element) { + (Some(name), _) => (format!("\0layer\0{name}\0missing-glyphs"), name), + (None, Some(element)) => (format!("\0element\0{element}\0missing-glyphs"), element), + (None, None) => ("\0missing-glyphs".to_string(), "Text outside any layer".to_string()), + }; + if !SAID.with(|s| add(&mut s.borrow_mut(), (key, Detail::Glyphs { subject, missing }))) { + turn_away(1); + } } /// Forgets the layer being drawn and what it approximated so far, unsaid: a frame stopped /// part-way (an error, a cancel) leaves it for no one ([`LayerScope`]). fn discard() { - MISSING_GLYPHS.with(|c| c.borrow_mut().clear()); - MORE_GLYPHS.with(|c| c.set(false)); - MISSING_LABEL_TEXT.with(|c| c.set(false)); + MISSING_GLYPHS.with(|pending| { + if let Some(missing) = pending.borrow_mut().as_mut() { + *missing = MissingGlyphs::default(); + } + }); SOLID_DASHES.with(|c| c.set(0)); LAYER.with(|l| *l.borrow_mut() = None); } @@ -555,7 +662,7 @@ mod tests { ground_without_height(ground_without_height_text(0.004)); let kept = keep(); walls_left_plain("Geology", 3); - restore(kept.clone()); + restore(kept); let said = take(); assert_eq!(said.len(), 2); assert!(said.first().is_some_and(|s| s.contains("under 1%")), "{said:?}"); @@ -615,6 +722,26 @@ mod tests { mod missing_font_tests { use super::*; + #[test] + fn glyph_loss_survives_a_store_full_of_wall_notices() { + let (_, said) = crate::shadows_said(|| { + for i in 0..KEPT { + walls_left_plain(&format!("Layer {i}"), 1); + } + layer(Some("First labels")); + missing_glyphs(['\u{10fffd}', '\u{10fffd}']); + layer(Some("Second labels")); + missing_glyphs(['\u{10fffd}', '\u{10fffe}']); + layer(None); + }); + let losses: Vec<_> = said.notices.iter().filter(|n| n.loss == Some(LossCode::DroppedGlyph)).collect(); + assert_eq!(losses.len(), 1, "{:?}", said.notices); + assert!(losses[0].contains("2 distinct characters"), "{losses:?}"); + assert!(losses[0].contains("U+10FFFD") && losses[0].contains("U+10FFFE"), "{losses:?}"); + assert!(losses[0].contains(LossCode::DroppedGlyph.spec().action), "{losses:?}"); + assert_eq!(said.notices.len(), KEPT + 1, "{:?}", said.notices); + } + #[test] fn missing_glyph_notices_count_distinct_characters_in_their_layer() { let _ = take(); @@ -624,7 +751,8 @@ mod missing_font_tests { layer(None); let notes = take(); assert_eq!(notes.len(), 1, "{notes:?}"); - assert!(notes[0].contains("Places: Label text was left out; 2 distinct characters"), "{notes:?}"); + assert!(notes[0].contains("Places: Label text was left out. 2 distinct characters"), "{notes:?}"); + assert_eq!(notes[0].loss, Some(LossCode::DroppedGlyph)); assert!(notes[0].contains("U+0985") && notes[0].contains("U+0E81"), "{notes:?}"); assert!(take().is_empty()); layer(Some("Clean")); diff --git a/crates/render/src/block.rs b/crates/render/src/block.rs index 98c5d47575..09f957afba 100644 --- a/crates/render/src/block.rs +++ b/crates/render/src/block.rs @@ -2243,7 +2243,7 @@ pub struct FlatWalls { /// How many stretches of the walls run through water (#2317): the pictures leave its section out. pub water: usize, /// What the drawing approximated, as the map view says it (gradient fills left plain). - pub gaps: Vec, + pub gaps: Vec, } /// The walls of box `b` on `map` as `draw_walls` colours them, unlit and unfogged (a 3D viewer @@ -2271,7 +2271,7 @@ pub fn flat_walls(map: &Map, ground: &Ground, b: &Block, res: f64, per_unit: f64 // The walls' top band (#2607) is the map view's only. let top = map.view.terrain.as_ref().and_then(|t| t.block.as_ref()).and_then(|t| t.walls_top.as_ref()); if let Some(top) = top.filter(|t| crate::terrain::walls_layer(map, &t.layer).is_some()) { - gaps.push(format!("the walls' top band from '{}' is drawn on the map view only, not on the model's walls", top.layer)); + gaps.push(format!("the walls' top band from '{}' is drawn on the map view only, not on the model's walls", top.layer).into()); } let water = water_runs(map, b, ground, res, scale, &env).iter().map(Vec::len).sum(); let mut out = FlatWalls { pictures: None, squeeze: 1.0, water, gaps }; @@ -2298,7 +2298,7 @@ pub fn flat_walls(map: &Map, ground: &Ground, b: &Block, res: f64, per_unit: f64 // Both sides are 1 to `MAX_SIDE` pixels, which a pixmap and a mask take, unless the // box's geometry is broken (NaN): then the walls stay plain, said. let (Some(mut pm), Some(mut mask)) = (Pixmap::new(w as u32, h as u32), Mask::new(w as u32, h as u32)) else { - out.gaps.push(format!("the walls' {w} by {h} pixel pictures can't be drawn, so they are their plain colour")); + out.gaps.push(format!("the walls' {w} by {h} pixel pictures can't be drawn, so they are their plain colour").into()); return out; }; // Across as the view lays a pattern out: Web Mercator along the side over `res`, left to diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 8bf27efb29..0f4eccf422 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -446,6 +446,7 @@ fn draw_page( } } for e in layout.elements.iter().filter(visible) { + let _glyph_element = crate::approximations::GlyphElement::new(layout, e); // Each element is a layer of the recording, named after it (#1815) and identified by its // id: the same layer on every page of a series, whatever other elements draw there. pm.layer_with_id(if e.name.trim().is_empty() { e.kind.code() } else { &e.name }, u64::from(e.id)); diff --git a/crates/render/src/layout/coverage.rs b/crates/render/src/layout/coverage.rs index d39a8aca75..8121d998fb 100644 --- a/crates/render/src/layout/coverage.rs +++ b/crates/render/src/layout/coverage.rs @@ -141,6 +141,7 @@ pub fn frame_coverage_judged_on( anchors: std::mem::take(&mut map.label_lock_line_anchors), map, }; + let _ignore_glyphs = crate::approximations::IgnoreMissingGlyphs::start(); let pm = crate::render(&mut *aside.map, &view)?.pixmap; drop(aside); let (gw, gh) = (pm.width(), pm.height()); @@ -189,6 +190,7 @@ pub fn frame_plain_under( } } let lock = Lock { lock: map.label_lock.take(), anchors: std::mem::take(&mut map.label_lock_line_anchors), map }; + let _ignore_glyphs = crate::approximations::IgnoreMissingGlyphs::start(); let Some(img) = crate::render(&mut *lock.map, &view) else { return false }; drop(lock); // A streamed layer still reading, or a raster read in place whose tiles are on their way or @@ -199,7 +201,7 @@ pub fn frame_plain_under( // The labels are drawn apart from the features, as the frame draws them over its map. let crate::Rendered { pixmap, labels, unplaced, label_layers, .. } = img; let mut canvas = Canvas::from_pixmap(pixmap); - crate::draw_labels(&mut canvas, (&unplaced, &labels, &label_layers), ppp as f32); + crate::draw_labels(&mut canvas, (&unplaced, &labels, &label_layers), map, ppp as f32); let pm = canvas.into_pixmap(); let (gw, gh) = (pm.width() as usize, pm.height() as usize); // Every cell the rectangle touches, partly too. diff --git a/crates/render/src/layout/frame.rs b/crates/render/src/layout/frame.rs index 0bd4b10b00..022569e14b 100644 --- a/crates/render/src/layout/frame.rs +++ b/crates/render/src/layout/frame.rs @@ -47,7 +47,7 @@ pub(super) fn frame_canvas( let img = img?; *pending |= img.tiles_pending || img.data_pending || shadows; let grid = over.grid.map(|(g, comma)| (&*map, view, g, comma)); - let (canvas, cut_here) = finish_frame(img, view.pixels_per_point, grid, over.sections, over.shape); + let (canvas, cut_here) = finish_frame(img, map, view.pixels_per_point, grid, over.sections, over.shape); *cut |= cut_here; Some(canvas) } @@ -62,7 +62,7 @@ pub fn frame_map_preview(map: &mut Map, camera: rustgis_map::Camera, w: f64, h: /// Map preview during a layout pan, using the same expression context as its page. pub fn frame_map_preview_with(map: &mut Map, camera: rustgis_map::Camera, w: f64, h: f64, ppp: f64, env: &Env) -> Option { let view = View { width: w, height: h, pixels_per_point: ppp, camera, sky: false }; - crate::render_cpu(map, &view, false, false, &mut None, env).map(|img| finish_frame(img, ppp, None, &[], None).0.into_pixmap()) + crate::render_cpu(map, &view, false, false, &mut None, env).map(|img| finish_frame(img, map, ppp, None, &[], None).0.into_pixmap()) } /// A rendered frame map with its labels, its `grid` (drawn on `map` in `view`, with a decimal @@ -71,6 +71,7 @@ pub fn frame_map_preview_with(map: &mut Map, camera: rustgis_map::Camera, w: f64 /// names. Also whether the attribution doesn't fit in the frame, so that its ends are cut off. pub(super) fn finish_frame( img: crate::Rendered, + map: &Map, ppp: f64, grid: Option<(&Map, &View, &Grid, bool)>, sections: &[(&Section, SectionEnds)], @@ -78,7 +79,7 @@ pub(super) fn finish_frame( ) -> (Canvas, bool) { let crate::Rendered { pixmap, recorded, labels, unplaced, label_layers, attribution, .. } = img; let mut pm = recorded.unwrap_or_else(|| Canvas::from_pixmap(pixmap)); - crate::draw_labels(&mut pm, (&unplaced, &labels, &label_layers), ppp as f32); + crate::draw_labels(&mut pm, (&unplaced, &labels, &label_layers), map, ppp as f32); // The grid is a layer of its own (#1815). pm.layer(grid.is_some().then_some("Grid")); let mut kept_clear = grid.map(|(map, view, g, comma)| draw_grid(&mut pm, map, view, g, comma)).unwrap_or_default(); diff --git a/crates/render/src/layout/tests.rs b/crates/render/src/layout/tests.rs index 0d57cde8d5..7c526c8482 100644 --- a/crates/render/src/layout/tests.rs +++ b/crates/render/src/layout/tests.rs @@ -1741,6 +1741,45 @@ fn frame_plain_under_counts_everything_drawn_but_the_background() { assert!(!plain(&mut map, (2.0, 86.0, 12.0, 12.0)), "web tiles aren't fetched for it, so nothing is plain"); } +#[test] +fn legend_probe_preserves_pending_glyphs_and_leaves_its_own_for_the_layout_draw() { + use crate::approximations; + use rustgis_data::loss::LossCode; + use rustgis_data::{Dataset, Field, FieldType, Geometry, Value}; + + let mut map = Map::new("Places map"); + (map.basemap, map.graticule) = (rustgis_map::Basemap::Blank, false); + let center = Coord::new(0.0, 0.0); + let mut places = Dataset::new("Places", GeometryType::Point, vec![Field::new("name", FieldType::Text)]); + places.push(Some(Geometry::Point(center)), vec![Value::Text("A\u{10fffd}".into())]); + let id = map.add_dataset(places); + let labels = &mut map.layer_mut(id).unwrap().labels; + labels.enabled = true; + labels.default.field = "name".into(); + + let mut layout = Layout::new("Page", 100.0, 100.0); + let frame = layout.add( + "Map", + (0.0, 0.0, 100.0, 100.0), + serde_json::from_value(serde_json::json!({"MapFrame":{"map":map.name,"center":center,"scale":1_000_000.0}})).unwrap(), + ); + let legend_rect = (2.0, 70.0, 25.0, 25.0); + layout.add("Legend", legend_rect, serde_json::from_value(serde_json::json!({"Legend":{"frame":frame,"title":"Places"}})).unwrap()); + + let (page, said) = crate::shadows_said(|| { + approximations::missing_glyphs(['\u{10fffe}']); + assert!(frame_plain_under(&mut map, center, 1_000_000.0, (100.0, 100.0), legend_rect, 128)); + render(&layout, std::slice::from_mut(&mut map), 96.0, &PageInfo::default()).unwrap() + }); + let losses: Vec<_> = said.notices.iter().filter(|n| n.loss == Some(LossCode::DroppedGlyph)).collect(); + assert_eq!(losses.len(), 2, "{losses:?}"); + assert!(losses.iter().any(|n| n.starts_with("Text outside any layer: 1 distinct characters") && n.contains("U+10FFFE")), "{losses:?}"); + assert!(losses.iter().any(|n| n.starts_with("Places: 1 distinct characters") && n.contains("U+10FFFD")), "{losses:?}"); + + let (without_probe, _) = crate::shadows_said(|| render(&layout, &mut [map], 96.0, &PageInfo::default()).unwrap()); + assert!(page.data() == without_probe.data(), "the probe changed the layout pixels"); +} + #[test] fn plain_dark_basemaps_keep_the_legend_paper_while_light_ones_clear_it() { for body in ["earth", "mars"] { @@ -6290,9 +6329,9 @@ fn a_frames_attribution_keeps_clear_of_its_grid_labels() { partial: Vec::new(), pending_in_place: Vec::new(), recorded: None, - label_layers: Vec::new(), + label_layers: Default::default(), }; - let framed = finish_frame(img, ppp, Some((&map, &view, &all, false)), &[], None).0; + let framed = finish_frame(img, &map, ppp, Some((&map, &view, &all, false)), &[], None).0; let (a, b) = (labels_pm.pixmap(), framed.pixmap()); assert_ne!(a.data(), b.data(), "the credit is drawn"); for (_, [x0, y0, x1, y1]) in &labels { @@ -6321,9 +6360,9 @@ fn credit_pixels((w, h): (f32, f32), credit: &str, shape: &FrameShape) -> Vec<(u partial: Vec::new(), pending_in_place: Vec::new(), recorded: None, - label_layers: Vec::new(), + label_layers: Default::default(), }; - let framed = finish_frame(img, f64::from(ppp), None, &[], Some(shape)).0; + let framed = finish_frame(img, &Map::new("Map"), f64::from(ppp), None, &[], Some(shape)).0; let pm = framed.pixmap(); let mut mask = Mask::new(pm.width(), pm.height()).unwrap(); let path = shape_path(shape, Rect::from_xywh(0.0, 0.0, w * ppp, h * ppp).unwrap()).unwrap(); @@ -6448,9 +6487,9 @@ fn credit_is_cut((w, h): (f32, f32), credit: &[String], shape: Option<&FrameShap partial: Vec::new(), pending_in_place: Vec::new(), recorded: None, - label_layers: Vec::new(), + label_layers: Default::default(), }; - finish_frame(img, f64::from(ppp), None, &[], shape).1 + finish_frame(img, &Map::new("Map"), f64::from(ppp), None, &[], shape).1 } /// A frame says its credit is cut off exactly when no place in it holds all of it (#3474): a diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index c405463070..bd58489fa0 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -597,9 +597,28 @@ pub struct Rendered { pub pending_in_place: Vec, /// The frame kept as vectors, when it was recorded ([`render_complete_recorded`]). pub(crate) recorded: Option, - /// When recorded, each of `labels`' map layer, by id and name (`u32::MAX` and no name for - /// a label of no layer's), for [`draw_labels`]; else empty. - pub(crate) label_layers: Vec<(u32, String)>, + /// For exports, the layer that supplied each label, for [`draw_labels`]. + pub(crate) label_layers: LabelLayers, +} + +#[derive(Default)] +pub(crate) struct LabelLayers { + /// `u32::MAX` marks graphics text and graticule labels, which have no label layer. + placed: Vec, + unplaced: Vec, +} + +impl LabelLayers { + fn of(placement: &Placement, keep: bool) -> Self { + if !keep { + return Self::default(); + } + let fixed = placement.labels.len().saturating_sub(placement.keys.len()); + Self { + placed: std::iter::repeat_n(u32::MAX, fixed).chain(placement.keys.iter().map(|(key, _)| key.0)).collect(), + unplaced: placement.unplaced_layers.clone(), + } + } } /// Which rasteriser [`render_backend`] targets: the tiny-skia CPU pixmap (the default, and the @@ -3102,6 +3121,7 @@ fn render_tilted( draw_icon(&mut pm, icon, view.pixels_per_point as f32); } } + let label_layers = LabelLayers::of(&placed, full_res_rasters); let unplaced = if map.label_display.show_unplaced { placed.unplaced } else { Vec::new() }; let absent = absences.finish(); tile_errors.extend(absent.iter().cloned()); @@ -3117,7 +3137,7 @@ fn render_tilted( partial, pending_in_place, recorded: None, - label_layers: Vec::new(), + label_layers, }) } @@ -7766,16 +7786,8 @@ fn render_frame( lock.is_some(), display.show_unplaced, ); - // Each placed label's map layer, for a recording to keep each layer's labels together: the - // fixed labels (graphics text) come first, then one for each key. - let label_layers: Vec<(u32, String)> = if pm.is_recording() { - let fixed = placed.labels.len().saturating_sub(placed.keys.len()); - let names: std::collections::HashMap = map.layers.iter().map(|l| (l.id, layer_name(l))).collect(); - let name = |id: u32| names.get(&id).cloned().unwrap_or_default(); - std::iter::repeat_n((u32::MAX, String::new()), fixed).chain(placed.keys.iter().map(|((id, ..), _)| (*id, name(*id)))).collect() - } else { - Vec::new() - }; + let keep_label_layers = full_res_rasters || pm.is_recording(); + let mut label_layers = LabelLayers::of(&placed, keep_label_layers); // (The lock is never taken from a tilted view: its labels' places out of sight are dropped, // so the numbers of the places they take aren't those of their class's.) if display.locked && map.label_lock.is_none() && !matches!(labels_to, Labels::Tilted(..)) { @@ -7805,7 +7817,6 @@ fn render_frame( post::apply(pm.pixels(), &map.view.effects, vision, &lonlat); } let mut labels = placed.labels; - let mut label_layers = label_layers; // The MGRS graticule's names (#1042), over the placed labels and apart from their collisions, // with no layer of their own in a recording, in the graticule's color made opaque. A tilted // view's bands draw none: their places would repeat from band to band. Paused labels pause @@ -7848,8 +7859,8 @@ fn render_frame( glyphs: Vec::new(), background: None, }); - if pm.is_recording() { - label_layers.push((u32::MAX, String::new())); + if keep_label_layers { + label_layers.placed.push(u32::MAX); } } } @@ -8986,6 +8997,7 @@ fn halo_for(text: Rgba) -> Rgba { struct Placement { labels: Vec, unplaced: Vec, + unplaced_layers: Vec, /// The key of each placed label, and the place it took. keys: Vec<(rustgis_map::LabelKey, rustgis_map::LockedPlace)>, line_anchors: Vec<(rustgis_map::LabelKey, Coord)>, @@ -9134,7 +9146,8 @@ fn place_labels_with_previews( let (text, icon) = label_boxes(l); text.iter().chain(&icon).for_each(|b| grid.insert(*b)); } - let mut out = Placement { labels: fixed, unplaced: Vec::new(), keys: Vec::new(), line_anchors: Vec::new() }; + let mut out = + Placement { labels: fixed, unplaced: Vec::new(), unplaced_layers: Vec::new(), keys: Vec::new(), line_anchors: Vec::new() }; let outside = |b: &[f32; 4]| b[2] < 0.0 || b[3] < 0.0 || b[0] > w || b[1] > h; let (mut searches, mut spots) = (MAX_CALLOUT_SEARCHES, MAX_CALLOUT_SPOTS); // Same work bound as 20,000 heads with eight positions, shared across all bands. @@ -9288,8 +9301,7 @@ fn place_labels_with_previews( } if !show_text && !show_icon { if show_unplaced && has_text && unplaced.len() < 2000 && pending.is_none() { - pending = - Some((grouped.then_some(key), PlacedLabel { color: UNPLACED, halo: Some(halo_for(UNPLACED)), icon: None, ..l })); + pending = Some((key, grouped, PlacedLabel { color: UNPLACED, halo: Some(halo_for(UNPLACED)), icon: None, ..l })); } continue; } @@ -9322,10 +9334,11 @@ fn place_labels_with_previews( out.labels.push(l); out.keys.push((key, rustgis_map::LockedPlace { place: u8::try_from(i).unwrap_or(u8::MAX), callout: moved_by })); } - if let Some((key, preview)) = pending - && key.is_none_or(|k| !placed_groups.contains(&k)) + if let Some((key, grouped, preview)) = pending + && (!grouped || !placed_groups.contains(&key)) { unplaced.push(preview); + out.unplaced_layers.push(key.0); } } out.unplaced = unplaced; @@ -9718,7 +9731,7 @@ pub struct ShadowsSaid { /// Why layers were drawn without them, each once, named by the layer ("Relief: its cast /// shadows aren't drawn: …"); then what else the frames drew otherwise than their layers /// ask, each once ("Roads: dashed lines are drawn solid …", see `approximations`). - pub notices: Vec, + pub notices: Vec, /// What each of [`Self::notices`] is, in the same order, for whoever says them once each: /// a cast-shadow notice by its text, an approximation by its kind /// (`approximated\0{kind}`, as the map view keys them), whose text carries a count that @@ -9742,8 +9755,8 @@ pub fn shadows_said(f: impl FnOnce() -> T) -> (T, ShadowsSaid) { /// What frames drawn on this thread since the last call said of their cast shadows, and what /// else they approximated ([`approximations::take`]). fn take_said() -> ShadowsSaid { - let mut notices = take_shadow_notices(); - let mut keys = notices.clone(); + let mut keys = take_shadow_notices(); + let mut notices: Vec<_> = keys.iter().map(rustgis_data::loss::Note::from).collect(); for (kind, e) in approximations::take_keyed(&[]) { let key = notice_key(&kind); if !keys.contains(&key) { @@ -9767,7 +9780,7 @@ pub fn notice_key(kind: &str) -> String { /// drawn on worker threads handed over to `relays` ([`ApproximationRelay::hand_over`]), each kind /// once, as (kind, notice): what the map view says after each frame it shows, each kind once a /// project (see `approximations`). Exports and pages read it through [`shadows_said`] instead. -pub fn take_approximations(relays: &[&ApproximationRelay]) -> Vec<(String, String)> { +pub fn take_approximations(relays: &[&ApproximationRelay]) -> Vec<(String, rustgis_data::loss::Note)> { approximations::take_keyed(relays) } @@ -9954,7 +9967,7 @@ fn render_drawing_inner(map: &mut Map, view: &View, failed_source: &mut Option String { /// as a layer of their own, "Labels: " (#1815): drawn in the placement's order, as the /// pixels draw them (labels can overlap: pinned ones, a class that shows all), each run of one /// layer's labels is marked as that layer, so one layer can be several runs. -pub(crate) fn draw_labels(pm: &mut Canvas, (unplaced, labels, layers): (&[PlacedLabel], &[PlacedLabel], &[(u32, String)]), ppp: f32) { - for l in unplaced { - text::draw(pm, l, ppp); - } - // Recorded, there is a layer for each label (see `render_frame`); without, no layers. - if !pm.is_recording() || layers.len() != labels.len() { - for l in labels { - text::draw(pm, l, ppp); - } - return; - } - let mut shown = None; - for (l, (id, name)) in labels.iter().zip(layers) { - if shown != Some(*id) { - if *id == u32::MAX { - pm.layer(None); - } else { - pm.layer_with_id(&format!("Labels: {name}"), u64::from(*id)); +pub(crate) fn draw_labels( + pm: &mut Canvas, + (unplaced, labels, layers): (&[PlacedLabel], &[PlacedLabel], &LabelLayers), + map: &Map, + ppp: f32, +) { + let names: std::collections::HashMap<_, _> = if layers.placed.is_empty() && layers.unplaced.is_empty() { + Default::default() + } else { + map.layers.iter().map(|layer| (layer.id, layer_name(layer))).collect() + }; + for (labels, ids, record) in [(unplaced, &layers.unplaced, false), (labels, &layers.placed, pm.is_recording())] { + let mut layer = None; + let mut shown = None; + for (at, label) in labels.iter().enumerate() { + let id = ids.get(at).copied().filter(|id| *id != u32::MAX); + if shown != id { + // Flush the previous layer before entering this one. The label order is the + // placement's order, so a layer can occur in several separate runs. + drop(layer.take()); + let name = id.and_then(|id| names.get(&id)); + layer = name.map(|name| approximations::NamedLayer::new(name)); + if record { + if let (Some(id), Some(name)) = (id, name) { + pm.layer_with_id(&format!("Labels: {name}"), u64::from(id)); + } else { + pm.layer(None); + } + } + shown = id; } - shown = Some(*id); + text::draw(pm, label, ppp); } - text::draw(pm, l, ppp); } pm.layer(None); } @@ -10022,9 +10046,7 @@ pub fn render_pixmap(map: &mut Map, view: &View) -> Result { fn exported_pixmap(map: &mut Map, view: &View) -> Result { let r = render_exported(map, view)?; let mut pm = Canvas::from_pixmap(r.pixmap); - for l in r.unplaced.iter().chain(&r.labels) { - text::draw(&mut pm, l, view.pixels_per_point as f32); - } + draw_labels(&mut pm, (&r.unplaced, &r.labels, &r.label_layers), map, view.pixels_per_point as f32); text::scale_bar(&mut pm, view, map.ground_res_at(&view.camera)); draw_export_attribution(&mut pm, &r.attribution, view.pixels_per_point as f32); Ok(pm.into_pixmap()) @@ -10040,7 +10062,7 @@ pub struct Placed { /// ran out, tile layers that couldn't be drawn. In a picture placed on the ground a gap looks /// like data, so an export says these. And what it drew otherwise than its layers ask (a /// dashed line drawn solid, see `approximations`), which it says too. - pub gaps: Vec, + pub gaps: Vec, } /// A map drawn as data, for an image placed on the ground (a GeoTIFF of the view): its layers @@ -10057,9 +10079,7 @@ pub fn render_placed(map: &mut Map, view: &View) -> Result { let r = render_exported(map, view).map(|mut r| { // Label drawing can report omissions too; keep them inside this export's notice scope. let mut pm = Canvas::from_pixmap(r.pixmap); - for l in r.unplaced.iter().chain(&r.labels) { - text::draw(&mut pm, l, view.pixels_per_point as f32); - } + draw_labels(&mut pm, (&r.unplaced, &r.labels, &r.label_layers), map, view.pixels_per_point as f32); r.pixmap = pm.into_pixmap(); r }); @@ -10069,21 +10089,20 @@ pub fn render_placed(map: &mut Map, view: &View) -> Result { approximations::restore(approximated_before); let r = r?; // Tile layers that couldn't be drawn are among what it approximated (see `complete`). - let mut gaps = shadows; + let mut gaps: Vec<_> = shadows.into_iter().map(rustgis_data::loss::Note::from).collect(); gaps.extend(approximated); if to_come { gaps.push( "made without the cast shadows or sky visibility still being worked out, as the window doesn't wait for them: once the map shows them, draw or export it again" - .to_string(), + .into(), ); } if r.tiles_pending { - gaps.push("some tiles were still on their way when the export stopped waiting, so parts of tile layers are empty: export again once the map has drawn them".to_string()); + gaps.push("some tiles were still on their way when the export stopped waiting, so parts of tile layers are empty: export again once the map has drawn them".into()); } if r.data_pending { gaps.push( - "streamed layers were still reading the view, so some features are missing: export again once the map has drawn them" - .to_string(), + "streamed layers were still reading the view, so some features are missing: export again once the map has drawn them".into(), ); } revisions.finish(map, None, Some(Placed { pixmap: r.pixmap, credits: r.attribution, gaps }), "could not draw the map") @@ -10230,10 +10249,13 @@ mod tests { fn overlapping_labels_of_two_layers_keep_their_order() { use crate::vector::Item; let labels = [label("Aa", 10.0, None, 0.0), label("Bb", 12.0, None, 0.0), label("Cc", 14.0, None, 0.0)]; - let layers = [(1, "Rios".to_string()), (2, "Cidades".to_string()), (1, "Rios".to_string())]; + let mut map = Map::new("Map"); + let rivers = map.add_dataset(Dataset::new("Rios", GeometryType::Polyline, Vec::new())); + let cities = map.add_dataset(Dataset::new("Cidades", GeometryType::Point, Vec::new())); + let layers = LabelLayers { placed: vec![rivers, cities, rivers], ..Default::default() }; let record = || { let mut pm = Canvas::recording(120, 40).unwrap(); - draw_labels(&mut pm, (&[], &labels, &layers), 1.0); + draw_labels(&mut pm, (&[], &labels, &layers), &map, 1.0); pm.into_drawing().unwrap() }; let (_, _, items) = record().finish(); diff --git a/crates/render/src/tiles.rs b/crates/render/src/tiles.rs index c7935e06fc..49fd47551e 100644 --- a/crates/render/src/tiles.rs +++ b/crates/render/src/tiles.rs @@ -1907,7 +1907,7 @@ pub(crate) mod tests { } /// What a PNG export of `tiles` (name, address) says. - fn export_says(tiles: &[(&str, &str)]) -> Vec { + fn export_says(tiles: &[(&str, &str)]) -> Vec { serve(); let camera = Camera { center: lonlat_to_merc(Coord::new(11.25, 50.0)), res: 2000.0, bearing: 0.0, pitch: 0.0 }; let view = View { width: 200.0, height: 100.0, pixels_per_point: 1.0, camera, sky: false }; diff --git a/crates/ui-egui/src/layoutview.rs b/crates/ui-egui/src/layoutview.rs index 1bdbc6d0f2..47a69d3e7b 100644 --- a/crates/ui-egui/src/layoutview.rs +++ b/crates/ui-egui/src/layoutview.rs @@ -58,9 +58,9 @@ pub(crate) fn say_frame_shadows(app: &mut RustGisApp, said: &rustgis_engine::ren // carries a count that changes as the page is drawn again, and the map view and a page say // each kind once between them. for (i, e) in said.notices.iter().enumerate() { - let key = said.keys.get(i).cloned().unwrap_or_else(|| e.clone()); + let key = said.keys.get(i).cloned().unwrap_or_else(|| e.text.clone()); if app.map.tile_errors.insert(key) { - app.session.warn(e.clone()); + app.session.say_warning(e.clone()); } } } diff --git a/crates/ui-egui/src/layoutview/tests.rs b/crates/ui-egui/src/layoutview/tests.rs index e0a0df0d4e..ca0e02a219 100644 --- a/crates/ui-egui/src/layoutview/tests.rs +++ b/crates/ui-egui/src/layoutview/tests.rs @@ -16,7 +16,7 @@ fn frame_approximations_are_said_once_a_kind() { let mut app = RustGisApp::with_sample(); let mark = app.session.notice_mark(); let said = |n: u32| rustgis_engine::render::ShadowsSaid { - notices: vec![format!("Roads: {n} dashed line(s) drawn solid")], + notices: vec![format!("Roads: {n} dashed line(s) drawn solid").into()], keys: vec!["approximated\0Roads\0dashes".to_string()], to_come: false, }; diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index ac97524393..ac5c3438d5 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -2017,7 +2017,7 @@ fn say_approximations(app: &mut RustGisApp) { let relays = [&app.map.tilt_settle.relay, &app.map.motion_frame.relay, &app.map.tilt_drape.relay]; for (kind, e) in rustgis_engine::render::take_approximations(&relays) { if app.map.tile_errors.insert(rustgis_engine::render::notice_key(&kind)) { - app.session.warn(e); + app.session.say_warning(e); } } } diff --git a/crates/ui-egui/src/tilt_settle.rs b/crates/ui-egui/src/tilt_settle.rs index 1974712955..c0c684b62f 100644 --- a/crates/ui-egui/src/tilt_settle.rs +++ b/crates/ui-egui/src/tilt_settle.rs @@ -281,7 +281,7 @@ mod tests { #[cfg(not(target_arch = "wasm32"))] #[test] fn a_workers_approximations_reach_the_map_view_of_the_project_it_was_started_for() { - use rustgis_engine::data::{Dataset, Geometry, GeometryType}; + use rustgis_engine::data::{Dataset, Geometry, GeometryType, loss::Note}; use rustgis_engine::geom::Coord; use rustgis_engine::map::{Basemap, LineStroke, symbology::Dash}; let ctx = egui::Context::default(); @@ -295,7 +295,7 @@ mod tests { } let camera = Camera { center: rustgis_engine::geom::lonlat_to_merc(Coord::new(0.0, 0.0)), res: 1500.0, bearing: 0.0, pitch: 0.0 }; let view = View { width: 64.0, height: 48.0, pixels_per_point: 1.0, camera, sky: false }; - let ours = |said: Vec<(String, String)>| said.into_iter().filter(|(_, e)| e.starts_with("settled road: ")).count(); + let ours = |said: Vec<(String, Note)>| said.into_iter().filter(|(_, e)| e.starts_with("settled road: ")).count(); let settle = |forget: bool| { let mut s = TiltSettle::default(); let started_with = s.relay.clone(); diff --git a/docs/user-guide/loss-codes.md b/docs/user-guide/loss-codes.md index d586525032..de2e963562 100644 --- a/docs/user-guide/loss-codes.md +++ b/docs/user-guide/loss-codes.md @@ -136,6 +136,16 @@ RustGIS read only part of the data because it is past a size limit. **What to do:** Read less at once, such as by filtering or clipping the source first, or keep fewer fields (columns) in it. +### `dropped.glyph` { #dropped.glyph } + +Text characters were left out of a drawing because the fonts available to RustGIS do not have glyphs for them. + +**Where you see it:** drawing maps, layouts and reports on screen or exporting them. A whole label +may be left out, or a fallback shape may be used for a character marker. + +**What to do:** Make a font that covers those characters available to RustGIS and draw or export again. +For Japanese, Chinese or Korean, try Noto Sans CJK. + ## Changed Changed means data is still there but was altered, such as cut short or rounded.