use crate::model::control::Control;
use crate::model::paragraph::LineSeg;
use crate::model::table::{Cell, Table, VerticalAlign};
use crate::renderer::px_to_hwpunit;
use super::{ComposedParagraph, LayoutEngine};
impl LayoutEngine {
#[allow(clippy::too_many_arguments)]
pub(super) fn stored_overlay_text_cell_origin(
&self,
table: &Table,
cell: &Cell,
composed: &[ComposedParagraph],
para_index: usize,
cell_height: f64,
inner_height: f64,
content_origin: f64,
) -> Option<f64> {
let profile = self.profile.get();
if !(profile.hwp5_stored_pagination_layout() || profile.hwpx_stored_layout())
|| profile.session_edited()
|| cell.dirty_flag
|| cell.text_direction != 0
|| self
.render_normalization
.borrow()
.table_text_reflowed(table)
|| i64::from(px_to_hwpunit(cell_height, self.dpi)) != i64::from(cell.height)
|| composed.len() != cell.paragraphs.len()
{
return None;
}
if cell.vertical_align != VerticalAlign::Top
&& cell.paragraphs.first()?.line_segs.first()?.vertical_pos == 0
{
return None;
}
let host = cell.paragraphs.get(para_index)?;
if host.controls.is_empty()
|| !host.controls.iter().all(|control| {
matches!(control, Control::Table(nested) if self.nested_table_is_overlay(nested))
})
{
return None;
}
let bottom = i64::from(px_to_hwpunit(inner_height, self.dpi));
let mut previous_end = 0_i64;
for (para, current) in cell.paragraphs.iter().zip(composed) {
if para.stored_text_partition_is_dirty()
|| para.cell_format_vpos_dirty
|| para.line_segs.is_empty()
|| para.line_segs.len() != current.lines.len()
|| current.frame_geometry.is_some()
{
return None;
}
for line in ¶.line_segs {
let start = i64::from(line.vertical_pos);
let end = start + i64::from(line.line_height);
if line.tag & LineSeg::TAG_IMPLEMENTATION_PROPERTY != 0
|| line.line_height <= 0
|| line.text_height <= 0
|| line.text_height > line.line_height
|| line.baseline_distance < 0
|| line.baseline_distance > line.line_height
|| line.segment_width <= 0
|| start < previous_end
|| end > bottom
{
return None;
}
previous_end = end;
}
}
Some(content_origin)
}
}