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
17 changes: 17 additions & 0 deletions crates/engine/src/cmd/layout/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,22 @@ pub(in crate::cmd::layout) fn held_rows(p: &Value) -> Option<String> {
(n != kept).then(|| format!("rows {n} held to {kept} ({least} to {most})"))
}

/// Says the rows and columns the box of the table `id` of layout `li` leaves out (#3416),
/// measured as [`super::text::text_fit_loss`] measures a text; nothing of another element.
pub(in crate::cmd::layout) fn say_table_cut(s: &mut Session, li: usize, id: u32) {
let Some(l) = s.project.layouts.get(li) else { return };
// The counts don't depend on the resolution: the box, its columns and its rows scale with it.
// Nothing is drawn here, so a layer read in place counts the rows it holds now.
let mut cut = rustgis_render::layout::tables_cut(l, &s.project.maps, 300.0);
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
cut.retain(|t| t.id == id);
if let Some(note) = rustgis_render::layout::table_cut_notice(&cut) {
s.warn(note);
}
}

/// What a table is given that changes what its box holds, or shows it.
pub(in crate::cmd::layout) const TABLE_FIT_KEYS: [&str; 8] = ["w", "h", "rows", "fields", "textSize", "header", "layer", "visible"];

/// Says what [`held_to_limits`] found, in one notice for the command `title`.
pub(in crate::cmd::layout) fn say_held(s: &mut Session, title: &str, held: Vec<String>) {
if !held.is_empty() {
Expand Down Expand Up @@ -779,6 +795,7 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu
if kind == "chart" {
say_chart_losses(s, i, id);
}
say_table_cut(s, i, id);
say_text_fit(s, i, id, true);
say_text_statistics(s, i, id);
if let Some(said) = empty_colorbar {
Expand Down
22 changes: 22 additions & 0 deletions crates/engine/src/cmd/layout/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,20 @@ pub fn layout_png(s: &mut Session, li: usize, dpi: f64, region: Option<[f64; 4]>
})
});
let img = img?;
// After drawing: a layer read in place holds the rows its frame just read.
let mut cut = rustgis_render::layout::tables_cut(&layout, &s.project.maps, dpi);
if let Some(r) = region {
cut.retain(|t| layout.element(t.id).is_some_and(|e| rustgis_render::layout::meets(e, r, 0.0)));
unfitted.retain(|l| layout.element(l.id).is_some_and(|e| rustgis_render::layout::meets(e, r, 0.0)));
charts.retain(|(id, _)| layout.element(*id).is_some_and(|e| rustgis_render::layout::meets(e, r, 0.0)));
}
if let Some(note) = rustgis_render::layout::clipped_text_notice(&layout, &clipped) {
s.warn(note);
}
say_unfitted_legends(s, &unfitted);
if let Some(note) = rustgis_render::layout::table_cut_notice(&cut) {
s.warn(note);
}
for note in chart_notice_lines(&layout, &charts) {
s.warn(note);
}
Expand Down Expand Up @@ -228,6 +234,8 @@ pub(in crate::cmd::layout) fn layout_bytes_inner(
let mut clipped = BTreeMap::new();
let mut gaps = SectionGaps::new();
let mut profiles = ProfileNotes::new();
// Each table cut on a page, as its first such page cut it.
let mut cut = BTreeMap::new();
let render_pages = || -> Result<(Vec<rustgis_render::pdf::Page>, Option<Vec<u8>>), String> {
let mut out = Vec::new();
let mut png = None;
Expand Down Expand Up @@ -295,6 +303,12 @@ pub(in crate::cmd::layout) fn layout_bytes_inner(
let img = rustgis_render::layout::render(layout, &mut s.project.maps, dpi, &info)?;
png = Some(crate::cmd::exports::held_to(download, |limit| rustgis_render::png::within(&img, limit))?);
}
// Counted once the page is drawn: a layer read in place holds that page's rows.
if let Some(layout) = s.project.layouts.get(li) {
for table in rustgis_render::layout::tables_cut(layout, &s.project.maps, dpi) {
cut.entry(table.id).or_insert(table);
}
}
// A cancelled export stops here, its layout put back below.
rustgis_data::progress::step(1).map_err(|e| e.to_string())?;
}
Expand Down Expand Up @@ -329,6 +343,9 @@ pub(in crate::cmd::layout) fn layout_bytes_inner(
s.warn(note);
}
say_unfitted_legends(s, &unfitted);
if let Some(note) = rustgis_render::layout::table_cut_notice(&cut.into_values().collect::<Vec<_>>()) {
s.warn(note);
}
for note in chart_notice_lines(&saved, &charts) {
s.warn(note);
}
Expand Down Expand Up @@ -573,6 +590,8 @@ fn layout_svg(s: &mut Session, li: usize, dpi: f64, download: Option<(crate::cmd
});
let (text, pictured) = drawn?;
let chart_notes = chart_notice_lines(layout, &charts);
// After drawing, as the other exports count.
let cut = rustgis_render::layout::table_cut_notice(&rustgis_render::layout::tables_cut(layout, &s.project.maps, dpi));
for note in [note, rustgis_render::layout::sections_notice(&gaps, 1)].into_iter().flatten() {
s.warn(note);
}
Expand All @@ -581,6 +600,9 @@ fn layout_svg(s: &mut Session, li: usize, dpi: f64, download: Option<(crate::cmd
s.warn(note);
}
say_unfitted_legends(s, &unfitted);
if let Some(note) = cut {
s.warn(note);
}
for note in chart_notes {
s.warn(note);
}
Expand Down
5 changes: 5 additions & 0 deletions crates/engine/src/cmd/layout/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
let excluding =
matches!(&e.kind, ElementKind::Legend { .. }) && (p.get("exclude").is_some_and(|v| !v.is_null()) || b(p, "allClasses").is_some());
let fit = tells_legend_fit(&e.kind, p);
// `null` included: it gives a text size or the header back.
let tells_table_fit = TABLE_FIT_KEYS.iter().any(|k| p.get(*k).is_some());
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
if unremembered {
s.notify(picture_unremembered(), false);
}
Expand All @@ -859,6 +861,9 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult {
if excluding {
say_raster_keys(s, li, id);
}
if tells_table_fit {
say_table_cut(s, li, id);
}
// A chart told what to draw, or coloured by classes, says what it leaves out of it.
// Given a maximum, it says the bars past it.
if !chart_said.is_empty()
Expand Down
27 changes: 27 additions & 0 deletions crates/engine/src/cmd/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,8 @@ fn report_pages_bytes(
let (mut unfitted, mut charts) = (Vec::new(), Vec::new());
// The texts cut off on its layouts' pages, by layout and element.
let mut clipped = ClippedTexts::new();
// The tables its layouts' pages cut, by layout.
let mut tables = Vec::new();
// Counted, and stopped on Cancel, a page at a time.
rustgis_data::progress::begin(n);
for k in 0..n {
Expand All @@ -1214,11 +1216,13 @@ fn report_pages_bytes(
let (drawn, listed, shown) =
listing(|| rustgis_render::report::draw_page(doc, pages, k, dpi, &s.project.layouts, &mut s.project.maps));
let (img, ..) = drawn?;
keep_tables(s, &mut tables, page_layout, dpi);
keep_drawn(&mut unfitted, page_layout, listed);
keep_drawn(&mut charts, page_layout, shown);
say_report_unfitted(s, &unfitted);
say_report_charts(s, &charts);
say_report_clipped(s, &clipped);
say_report_tables(s, tables);
say_sections_not_drawn(s, pages, 1);
say_report_pictures(s, pages, 1);
let png = super::exports::held_to(download, |limit| rustgis_render::png::within(&img, limit))?;
Expand All @@ -1227,6 +1231,7 @@ fn report_pages_bytes(
let (drawn, listed, shown) =
listing(|| rustgis_render::report::pdf_page(doc, pages, k, dpi, &s.project.layouts, &mut s.project.maps));
let (page, pictured) = drawn?;
keep_tables(s, &mut tables, page_layout, dpi);
keep_drawn(&mut unfitted, page_layout, listed);
keep_drawn(&mut charts, page_layout, shown);
if page.overflowed() {
Expand Down Expand Up @@ -1257,12 +1262,34 @@ fn report_pages_bytes(
say_report_charts(s, &charts);
say_report_clipped(s, &clipped);
super::layout::pictured_notices(s, &frames_pictured, &pages_pictured);
say_report_tables(s, tables);
say_sections_not_drawn(s, pages, n);
say_report_pictures(s, pages, n);
let pdf = super::exports::held_to(download, |limit| rustgis_render::pdf::write_within(&out, &doc.title, limit))?;
Ok((pdf, pages.len()))
}

/// Keeps the tables the layout just drawn, `layout` by its index, cuts at `dpi` (#3416), each
/// with its layout's name: counted after the page is drawn, as a layer read in place then holds
/// that page's rows. A table a layout cut on an earlier page is kept as it was.
fn keep_tables(s: &Session, kept: &mut Vec<(usize, rustgis_render::layout::TableCut)>, layout: Option<usize>, dpi: f64) {
let Some((li, layout)) = layout.and_then(|li| Some((li, s.project.layouts.get(li)?))) else { return };
for mut table in rustgis_render::layout::tables_cut(layout, &s.project.maps, dpi) {
if !kept.iter().any(|(at, t)| *at == li && t.id == table.id) {
table.layout = Some(layout.name.clone());
kept.push((li, table));
}
}
}

/// Says the tables [`keep_tables`] kept in one notice however many layouts cut one.
fn say_report_tables(s: &mut Session, kept: Vec<(usize, rustgis_render::layout::TableCut)>) {
let cut: Vec<_> = kept.into_iter().map(|(_, table)| table).collect();
if let Some(note) = rustgis_render::layout::table_cut_notice(&cut) {
s.warn(format!("The report: {note}"));
}
}

/// Says the section lines (#2863) the layouts of the first `n` of `pages` don't draw, as the
/// layout's own export says them: in one notice however many layouts leave one out, each line named
/// with its layout, and a layout on several pages counted once.
Expand Down
Loading
Loading