use super::{CellUnit, Control, LayoutEngine, ResolvedStyleSet};
impl LayoutEngine {
pub(in crate::renderer::layout) fn nested_cell_cut_content_height(
&self,
cell: &crate::model::table::Cell,
table: &crate::model::table::Table,
styles: &ResolvedStyleSet,
start: usize,
end: usize,
) -> f64 {
let units = self.cell_units(cell, table, styles);
let lo = start.min(units.len());
let window = &units[lo..end.clamp(lo, units.len())];
if window.iter().any(|unit| {
unit.mixed_nested_fragment
|| unit.nested_row.is_some()
|| unit.nested_table_fragment.is_some()
|| cell.paragraphs.get(unit.para_idx).is_some_and(|paragraph| {
paragraph
.controls
.iter()
.any(|control| matches!(control, Control::Table(_)))
})
}) {
let trailing = self.nested_cut_terminal_line_spacing(table, cell, window);
window.iter().map(|unit| unit.height).sum::<f64>()
+ self.nested_continuation_header_height(cell, &units, lo, styles)
- self.continued_cut_nested_atom_tail(cell, &units, lo, lo + window.len(), styles)
+ self.mixed_nested_flow_extra_from_cut(cell, table, styles, lo, lo + window.len())
- trailing
} else {
0.0
}
}
fn nested_cut_terminal_line_spacing(
&self,
table: &crate::model::table::Table,
cell: &crate::model::table::Cell,
selected: &[CellUnit],
) -> f64 {
use crate::model::paragraph::LineSeg;
let profile = self.profile.get();
if !(profile.hwpx_stored_layout() || profile.hwp5_stored_pagination_layout())
|| profile.session_edited()
|| self
.render_normalization
.borrow()
.table_text_reflowed(table)
|| cell.dirty_flag
{
return 0.0;
}
let Some(last) = selected.last() else {
return 0.0;
};
let paragraph = &cell.paragraphs[last.para_idx];
if last.nested_row.is_some()
|| last.nested_table_fragment.is_some()
|| last.mixed_nested_fragment
|| last.mixed_nested_trailing
|| last.vis_end <= last.vis_start
|| !(last.vis_start + 1..last.vis_end).all(|index| {
crate::renderer::height_measurer::stored_seg_is_row_fragment(paragraph, index)
})
|| !paragraph.controls.is_empty()
|| paragraph.stored_text_partition_is_dirty()
|| paragraph.cell_format_vpos_dirty
{
return 0.0;
}
let Some(line) = paragraph.line_segs.get(last.vis_end - 1) else {
return 0.0;
};
if line.tag & LineSeg::TAG_IMPLEMENTATION_PROPERTY != 0 || line.line_height <= 0 {
return 0.0;
}
let advance = super::hwpunit_to_px(line.line_height, self.dpi)
+ super::hwpunit_to_px(line.line_spacing, self.dpi);
if (last.height - advance).abs() <= super::hwpunit_to_px(2, self.dpi) {
super::hwpunit_to_px(line.line_spacing, self.dpi)
} else {
0.0
}
}
}