use super::{hwpunit_to_px, single_cell_page_fragment_bottom, Table};
pub(crate) struct RowbreakFragmentBounds {
pub(crate) content_bottom: f64,
pub(crate) blank_bottom: f64,
}
pub(crate) fn rowbreak_fragment_bounds(
table: &Table,
body_bottom: f64,
dpi: f64,
body_filling_source_frame: bool,
has_original_page_frames: bool,
) -> RowbreakFragmentBounds {
let outer_bottom = body_bottom - hwpunit_to_px(i32::from(table.outer_margin_bottom), dpi);
let blank_bottom = if body_filling_source_frame {
outer_bottom
} else {
single_cell_page_fragment_bottom(table, body_bottom, dpi)
};
let reparsed_body_owner = table.col_count == 2
&& table.cells.iter().any(|cell| {
cell.col == 1
&& cell.paragraphs.len() == 1
&& cell.paragraphs[0].text.is_empty()
&& cell.paragraphs[0].controls.is_empty()
&& crate::renderer::typeset::is_reparsed_single_column_cell_split_row(
table,
usize::from(cell.row),
)
});
let has_saved_text_coordinates = table.cells.iter().any(|cell| {
cell.paragraphs.iter().any(|paragraph| {
!paragraph.text.trim().is_empty()
&& !crate::renderer::para_has_no_stored_line_segs(paragraph)
})
});
RowbreakFragmentBounds {
content_bottom: if (!has_original_page_frames && has_saved_text_coordinates)
|| (table.row_count == 1 && table.col_count == 1)
|| reparsed_body_owner
{
blank_bottom
} else {
outer_bottom
},
blank_bottom,
}
}
pub(crate) fn rowbreak_fragment_frame_bottom(
table: &Table,
body_bottom: f64,
dpi: f64,
body_filling_source_frame: bool,
) -> f64 {
rowbreak_fragment_bounds(table, body_bottom, dpi, body_filling_source_frame, true)
.content_bottom
}