Skip to content
Merged
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
6 changes: 6 additions & 0 deletions crates/data/src/loss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions crates/engine/src/cmd/block_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub(crate) fn export_work(s: &Session, p: &Value) -> Result<super::exports::Work
let exaggeration = t.exaggeration;
Ok(Box::new(move || {
let mut notes = Vec::new();
let mut draw_notes = Vec::new();
let written = (|| {
rustgis_data::progress::check().map_err(|e| e.to_string())?;
if round {
Expand Down Expand Up @@ -157,11 +158,15 @@ pub(crate) fn export_work(s: &Session, p: &Value) -> Result<super::exports::Work
rustgis_data::progress::check().map_err(|e| e.to_string())?;
rustgis_data::io::write_atomic(std::path::Path::new(&path), &bytes).map_err(|e| format!("{path}: {e}"))?;
let warn = rustgis_data::diagnostics::Severity::Warning;
for gap in &placed.gaps {
notes.push((warn, format!("{path}: the texture: {gap}")));
}
for gap in &flat.gaps {
notes.push((warn, format!("{path}: the walls' texture: {gap}")));
for (part, gaps) in [("the texture", placed.gaps), ("the walls' texture", flat.gaps)] {
let target = format!("{path}: {part}");
for note in gaps.into_iter().map(|note| note.prefixed(&target)) {
if note.loss.is_some() {
draw_notes.push(note);
} else {
notes.push((warn, note.text));
}
}
}
if flat.squeeze < 1.0 {
notes.push((
Expand Down Expand Up @@ -201,7 +206,7 @@ pub(crate) fn export_work(s: &Session, p: &Value) -> Result<super::exports::Work
if written.is_err() {
notes.clear();
}
super::exports::drawn(std::slice::from_ref(&map), notes, written, path)
super::exports::drawn_with_notes(std::slice::from_ref(&map), notes, draw_notes, written, path)
}))
}

Expand Down
23 changes: 23 additions & 0 deletions crates/engine/src/cmd/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,29 @@ pub(crate) fn drawn(
})
}

/// [`drawn`] with the renderer's warnings and coded losses, reported only for a completed output.
pub(crate) fn drawn_with_notes(
maps: &[rustgis_map::Map],
mut diagnostics: Vec<(rustgis_data::diagnostics::Severity, String)>,
notes: Vec<rustgis_data::loss::Note>,
written: Result<Value, String>,
path: String,
) -> Result<Wrote, String> {
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<Value, String>, path: String) -> Result<Wrote, String> {
Expand Down
15 changes: 10 additions & 5 deletions crates/engine/src/cmd/layout/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
})
})
})
})
Expand All @@ -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);
}
Expand Down
30 changes: 13 additions & 17 deletions crates/engine/src/cmd/share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -325,8 +326,8 @@ pub(super) fn map_png_unsaid(s: &mut Session, width: Option<f64>, height: Option
pub(crate) fn saying_shadows<T>(s: &mut Session, what: &str, draw: impl FnOnce(&mut Session) -> Result<T, String>) -> Result<T, String> {
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
Expand All @@ -336,12 +337,12 @@ pub(crate) fn saying_shadows<T>(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<String> {
let mut out: Vec<String> = said.notices.iter().map(|e| format!("{what}: {e}")).collect();
pub(crate) fn shadow_warnings(what: &str, said: rustgis_render::ShadowsSaid) -> Vec<Note> {
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
}
Expand Down Expand Up @@ -564,21 +565,17 @@ pub(crate) fn map_work(s: &Session, p: &Value) -> Result<Work, String> {
})
});
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)?;
Ok(json!({"path": path, "bytes": bytes}))
})();
// 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 })
}))
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions crates/engine/src/cmd/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,11 @@ pub(crate) fn orbit_work(s: &Session, p: &Value) -> Result<super::exports::Work,
});
let bytes = made?;
// What the frames said of their cast shadows, once for the export.
shadows = super::share::shadow_warnings("The orbit", &said);
shadows = super::share::shadow_warnings("The orbit", said);
rustgis_data::io::write_atomic(std::path::Path::new(&path), &bytes).map_err(|e| format!("{path}: {e}"))?;
Ok(json!({"path": path, "frames": n, "turn": turn, "bytes": bytes.len()}))
})();
let warn = rustgis_data::diagnostics::Severity::Warning;
let notes = if written.is_ok() { shadows.into_iter().map(|e| (warn, e)).collect() } else { Vec::new() };
super::exports::drawn(std::slice::from_ref(&map), notes, written, path)
super::exports::drawn_with_notes(std::slice::from_ref(&map), Vec::new(), shadows, written, path)
}))
}

Expand Down
59 changes: 59 additions & 0 deletions crates/engine/src/tests/write_notices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,3 +1149,62 @@ fn export_declarations_count_all_changed_columns_of_a_wide_table() {
let notice = s.notices_since(mark).iter().find(|n| n.text == expected).unwrap();
assert_eq!(notice.translated(|key, _| key.to_owned()), Some("{target}: changed {count} column declarations ({columns})".into()));
}

#[test]
fn exports_report_missing_glyphs_for_named_text() {
if std::env::var_os("RUSTGIS_TEST_EXPORT_GLYPHS").is_none() {
let test = std::process::Command::new(std::env::current_exe().unwrap())
.args(["--exact", "tests::write_notices::exports_report_missing_glyphs_for_named_text", "--nocapture"])
.env("RUSTGIS_TEST_EXPORT_GLYPHS", "1")
.env("RUSTGIS_BUILTIN_FONTS", "1")
.output()
.unwrap();
let stdout = String::from_utf8_lossy(&test.stdout);
let stderr = String::from_utf8_lossy(&test.stderr);
assert!(test.status.success() && stdout.contains("1 passed"), "{stdout}\n{stderr}");
return;
}

use rustgis_data::loss::LossCode;

let files = Files::new();
let mut failures = Vec::new();
for (text, count) in [("Tokyo", 0), ("東京", 1)] {
let mut s = Session::new(Project::default());
let mut places = Dataset::new("Places", GeometryType::Point, vec![Field::new("name", FieldType::Text)]);
places.crs = rustgis_data::raster::Crs::from_epsg(4326);
places.push(Some(Geometry::Point(rustgis_data::Coord::new(0.0, 0.0))), vec![Cell::Text(text.into())]);
s.map_mut().add_dataset(places);
s.run("labels.enable", &json!({"layer":"Places", "on":true})).unwrap();
s.run("layout.new", &json!({"template":"blank", "width":100, "height":80})).unwrap();
s.run("layout.addElement", &json!({"kind":"text", "text":text, "x":10, "y":10, "w":60, "h":20})).unwrap();
s.run("layout.update", &json!({"element":1, "name":"Heading"})).unwrap();

for (command, file, subject, count) in [
("share.exportMap", "map.png", "Places", count),
("share.exportMap", "map.tif", "Places", count),
("layout.export", "sheet.png", "Heading (1)", count),
("layout.export", "sheet.pdf", "Heading (1)", count),
("layout.export", "sheet.svg", "Heading (1)", 0),
] {
let path = files.path().join(file);
let mark = s.notice_mark();
s.run(command, &json!({"path":path, "width":320, "height":240, "dpi":72})).unwrap();
assert!(path.is_file(), "{file}");
if file.ends_with(".svg") {
// The SVG viewer supplies fonts for editable text.
assert!(std::fs::read_to_string(&path).unwrap().contains(text));
}
let notes = s.notices_since(mark);
let losses: Vec<_> = 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"));
}
Loading
Loading