use crate::model::control::Control;
use crate::model::paragraph::{LineSeg, Paragraph};
pub(crate) fn saved_positive_frame_reset(
previous: Option<(i32, i32)>,
first: &LineSeg,
body_height: i32,
) -> bool {
previous.is_some_and(|(previous_first, previous_end)| {
let next_bottom = first.vertical_pos.saturating_add(first.line_height);
first.vertical_pos > 0
&& first.line_height > 0
&& first.vertical_pos < previous_first
&& next_bottom <= body_height
&& previous_end.saturating_add(next_bottom) > body_height
})
}
pub(crate) fn owns_saved_object_line(para: &Paragraph) -> bool {
let [line] = para.line_segs.as_slice() else {
return false;
};
let mut owners = para
.controls
.iter()
.filter(|control| !crate::renderer::control_is_body_flow_neutral_marker(control));
let Some(control) = owners.next() else {
return false;
};
if owners.next().is_some() {
return false;
}
if para.stored_text_partition_dirty
|| line.tag & LineSeg::TAG_IMPLEMENTATION_PROPERTY != 0
|| para
.text
.chars()
.any(|c| !c.is_whitespace() && c > '\u{001f}' && c != '\u{fffc}')
{
return false;
}
let common = match control {
Control::Shape(shape)
if shape
.drawing()
.is_some_and(|drawing| drawing.caption.is_none()) =>
{
shape.common()
}
Control::Picture(picture) if picture.caption.is_none() => &picture.common,
Control::Table(table)
if table.caption.is_none()
&& table.cells.iter().all(|cell| {
!cell.dirty_flag
&& cell.paragraphs.iter().all(|paragraph| {
!paragraph.stored_text_partition_is_dirty()
&& !paragraph.cell_format_vpos_dirty
&& !crate::renderer::para_has_no_stored_line_segs(paragraph)
})
}) =>
{
&table.common
}
_ => return false,
};
common.treat_as_char
&& common.height > 0
&& i64::from(line.line_height)
== i64::from(common.height)
+ i64::from(common.margin.top)
+ i64::from(common.margin.bottom)
}