use super::{hwpunit_to_px, Cell, CommonObjAttr, LayoutEngine, Table, DEFAULT_DPI};
#[test]
fn row_width_outlier_preserves_the_nonminimum_authored_column_grid() {
let nominal_hu = 1_000;
let cells = (0..3)
.flat_map(|row| {
(0..2).map(move |col| Cell {
row,
col,
row_span: 1,
col_span: 1,
width: nominal_hu,
..Default::default()
})
})
.collect();
let regular = Table {
row_count: 3,
col_count: 2,
cells,
common: CommonObjAttr {
width: nominal_hu * 2,
..Default::default()
},
..Default::default()
};
let mut with_outlier = regular.clone();
with_outlier.cells[0].width = nominal_hu * 3 / 2;
let source_widths: Vec<_> = with_outlier.cells.iter().map(|cell| cell.width).collect();
let engine = LayoutEngine::with_default_dpi();
let regular_widths = engine.resolve_column_widths(®ular, 2);
let resolved = engine.resolve_column_widths(&with_outlier, 2);
assert_eq!(
resolved, regular_widths,
"한 이상 행이 지배적인 두 행의 열 경계를 확대하지 않음"
);
assert_eq!(resolved[0], resolved[1], "같은 원본 폭인 두 열의 관계 유지");
let authored_total = hwpunit_to_px(regular.common.width as i32, DEFAULT_DPI);
assert!(
(resolved.iter().sum::<f64>() - authored_total).abs() < 1e-6,
"실제 열 합계는 원본의 지배적인 행 합계와 같음"
);
assert_eq!(
with_outlier
.cells
.iter()
.map(|cell| cell.width)
.collect::<Vec<_>>(),
source_widths,
"격자 계산이 저장 원시 폭을 변경하지 않음"
);
}