Merge pull request #8582

This commit is contained in:
autocraft-bot[bot]
2026-12-03 12:29:58 +00:00
+68
View File
@@ -3754,6 +3754,74 @@ fn turned_text_uses_min_height() {
}
}
/// A minimum height is the turned text's length only while the lines wrapped to it fit across the
/// column. In a narrow cell they would pile up sideways, so the text keeps its unwrapped length
/// instead: it runs on past the minimum and the row grows to hold it, rather than spilling out.
#[test]
fn turned_text_in_a_narrow_cell_keeps_its_unwrapped_length() {
use wordcraft_doc::props::HeightRule;
crate::test_fonts();
for turn in [TextDirection::Up, TextDirection::Down] {
let mut d = Document::from_text("After");
let mut t = Table::new(1, 2, 60.0);
t.props.style = None;
t.rows[0].props.height = Some(80.0);
t.rows[0].props.height_rule = HeightRule::AtLeast;
t.rows[0].cells[1].props.text_direction = turn;
t.rows[0].cells[1].blocks = vec![wordcraft_doc::para_block(Paragraph::with_text(&"word ".repeat(12), Default::default()))];
d.insert_block(StoryRef::Body, &Path::top(0), wordcraft_doc::Block::Table(t)).unwrap();
let l = lay(&d);
let it = l.pages[0].items.iter().find(|it| matches!(it, Placed::Lines { path, .. } if path.0 == [0, 0, 1, 0])).unwrap();
let lines = if let Placed::Lines { l0, l1, .. } = it { l1 - l0 } else { 0 };
assert_eq!(lines, 1, "{turn:?}: the lines at 80pt would not fit across the narrow cell");
let b = it.turned_bounds().unwrap();
assert!(b.w < 20.0, "{turn:?}: one line across the cell, not a stack spilling sideways: {b:?}");
assert!(b.h > 80.0, "{turn:?}: the text keeps its unwrapped length and the row grows: {b:?}");
}
}
/// The probe is skipped inside a text box: the box's own layout decides its size, so turned text
/// there keeps its unwrapped length even when the lines at the minimum height would fit across
/// the cell (which is exactly when a body table would take the minimum as the length).
#[test]
fn a_text_box_skips_the_min_height_probe_for_turned_text() {
use wordcraft_doc::props::HeightRule;
crate::test_fonts();
let mut d = Document::from_text("Before\nafter");
let mut t = Table::new(1, 2, 468.0);
t.props.style = None;
t.rows[0].props.height = Some(80.0);
t.rows[0].props.height_rule = HeightRule::AtLeast;
t.rows[0].cells[1].props.text_direction = TextDirection::Down;
t.rows[0].cells[1].blocks = vec![wordcraft_doc::para_block(Paragraph::with_text(&"word ".repeat(12), Default::default()))];
let id = d.add_part(wordcraft_doc::PartKind::TextBox, vec![wordcraft_doc::Block::Table(t).into()]);
let shape = InlineObject::Shape {
kind: wordcraft_doc::para::ShapeKind::TextBox,
w: 468.0,
h: 400.0,
fill: None,
stroke: None,
stroke_width: 1.0,
float: Default::default(),
story: Some(id),
effects: Default::default(),
freeform: None,
extra: Default::default(),
};
let off = d.para(StoryRef::Body, &Path::top(0)).map_or(0, |p| p.len());
d.insert_object(&Pos::body(0, off), shape, &Default::default()).unwrap();
let l = lay(&d);
let it = l.pages[0]
.items
.iter()
.find(|it| matches!(it, Placed::Lines { story: StoryRef::Part(s), path, .. } if *s == id && path.0 == [0, 0, 1, 0]))
.unwrap();
let lines = if let Placed::Lines { l0, l1, .. } = it { l1 - l0 } else { 0 };
assert_eq!(lines, 1, "the text box skips the probe: the text keeps its unwrapped length");
let b = it.turned_bounds().unwrap();
assert!(b.h > 80.0, "and so it runs on past the minimum height: {b:?}");
}
#[test]
fn turned_text_wraps_to_merged_rows_height() {
use wordcraft_doc::props::{HeightRule, VMerge};