mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-02 22:30:10 +00:00
Merge pull request #8121
This commit is contained in:
@@ -589,7 +589,8 @@ fn table_frame(ctx: &mut Ctx, t: &Table, avail: f32, depth: usize, style: Option
|
||||
indent - first_cell_left_margin_in(t, margins_def)
|
||||
};
|
||||
// The reading view fits the table into what the start offset leaves of the column, mirrored or not (#7988).
|
||||
let room = (avail - start_offset.max(0.0)).max(1.0);
|
||||
// Keep at least half the fitted width so the position clamp can reduce an excessive indent (#8063).
|
||||
let room = (avail - start_offset.max(0.0)).max(acc.min(avail) / 2.0).max(1.0);
|
||||
if ctx.opts.view == ViewMode::Read && acc > room && !matches!(t.props.align, Some(Align::Center | Align::Right)) {
|
||||
let k = room / acc;
|
||||
colx.iter_mut().for_each(|c| *c *= k);
|
||||
|
||||
@@ -685,6 +685,43 @@ fn reading_layout_fits_a_wide_table_to_the_column() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reading_layout_preserves_table_width_with_an_excessive_indent() {
|
||||
crate::test_fonts();
|
||||
for rtl in [false, true] {
|
||||
let frame = |indent, view| {
|
||||
let mut doc = Document::from_text("Before.");
|
||||
doc.settings.compat_mode = 15;
|
||||
let mut table = Table::new(2, 4, 468.0);
|
||||
table.props.fixed = true;
|
||||
table.props.indent = Some(indent);
|
||||
table.props.bidi_visual = rtl;
|
||||
doc.insert_block(StoryRef::Body, &Path::top(1), Block::Table(table)).unwrap();
|
||||
let opts = LayoutOptions { view, web_width: 360.0, read_height: 600.0, ..Default::default() };
|
||||
let layout = layout(&doc, &mut LayoutCache::new(), &opts);
|
||||
let page = &layout.pages[0];
|
||||
let cells: Vec<_> = page.items.iter().filter_map(|item| if let Placed::Cell { rect, .. } = item { Some(*rect) } else { None }).collect();
|
||||
assert_eq!(cells.len(), 8);
|
||||
let (left, right) = cells.iter().fold((f32::INFINITY, f32::NEG_INFINITY), |(l, r), cell| (l.min(cell.x), r.max(cell.x + cell.w)));
|
||||
let start = if rtl { page.body.x + page.body.w - right } else { left - page.body.x };
|
||||
(start, right - left, page.body.w)
|
||||
};
|
||||
let (start, width, column) = frame(0.0, ViewMode::Read);
|
||||
let (indented, _, _) = frame(36.0, ViewMode::Read);
|
||||
assert!((indented - start - 36.0).abs() < 0.5, "ordinary indent is preserved");
|
||||
for indent in [400.0, column - 12.0] {
|
||||
let (start, fitted, _) = frame(indent, ViewMode::Read);
|
||||
assert!(fitted + 0.5 >= width / 2.0, "rtl {rtl}, indent {indent}: table is only {fitted} pt wide vs {width} pt without indent");
|
||||
assert!(start >= -0.5 && start + fitted <= column + 0.5, "table fits within the reading column");
|
||||
assert!(start < indent, "reduce the indent to make space for the table");
|
||||
}
|
||||
let (print_start, print_width, _) = frame(0.0, ViewMode::Print);
|
||||
let (print_indented, print_indented_width, _) = frame(400.0, ViewMode::Print);
|
||||
assert!((print_indented - print_start - 400.0).abs() < 0.5, "print layout keeps the authored indent");
|
||||
assert!((print_indented_width - print_width).abs() < 0.5, "print layout keeps the table width");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hit_and_caret_agree() {
|
||||
crate::test_fonts();
|
||||
|
||||
Reference in New Issue
Block a user