use crate::model::control::Control;
use crate::model::paragraph::{LineSeg, Paragraph};
use crate::model::shape::ShapeObject;
pub(super) fn source_physical_lines<'a>(
paragraph: &'a Paragraph,
unit: &super::CellUnit,
) -> Option<&'a [LineSeg]> {
if unit.nested_row.is_some() || unit.non_inline_control_range.is_some() {
return None;
}
if unit.vis_start < unit.vis_end {
return paragraph.line_segs.get(unit.vis_start..unit.vis_end);
}
(unit.vis_start == 0
&& unit.vis_end == 0
&& unit.empty_spacer
&& unit.height == 0.0
&& !unit.reflowed_line_slot
&& paragraph.controls.is_empty()
&& paragraph.text.trim().is_empty()
&& paragraph.line_segs.len() == 1)
.then_some(paragraph.line_segs.as_slice())
}
pub(super) fn source_line_controls_fit(paragraph: &Paragraph) -> bool {
paragraph
.controls
.iter()
.enumerate()
.all(|(index, control)| {
let picture = match control {
Control::Footnote(_) | Control::Endnote(_) => return true,
Control::Picture(picture) => picture.as_ref(),
Control::Shape(shape) => match shape.as_ref() {
ShapeObject::Picture(picture) => picture,
_ => return false,
},
_ => return false,
};
let common = &picture.common;
if !common.treat_as_char || common.height == 0 || picture.caption.is_some() {
return false;
}
let Some(owner) = super::super::control_line_seg_index(paragraph, index) else {
return false;
};
let Some(line) = paragraph.line_segs.get(owner) else {
return false;
};
let Some(height) = crate::renderer::tac_object_flow_height_hu(control) else {
return false;
};
let occupied =
i64::from(height) + i64::from(common.margin.top) + i64::from(common.margin.bottom);
line.tag & LineSeg::TAG_IMPLEMENTATION_PROPERTY == 0
&& height > 0
&& line.line_height > 0
&& occupied <= i64::from(line.line_height)
})
}