mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-19 08:55:26 +00:00
Tables: percentage cell widths size their columns whichever rows give them
Percentage cell widths size their columns from whichever rows give them, taking the largest when rows disagree, sharing a merged cell's percentage, and keeping a grid that already matches. Originally authored by @pakiat in #5074.
This commit is contained in:
1 parent
32b4ab5724
commit
5bf3ffb920
5 files changed
+362
-4
No files matched your search
@@ -304,6 +304,7 @@ Ranked, to beta (detail and remaining milestones in [docs/roadmap.md](docs/roadm
|
||||
- 2026-11-01: Tab leaders are drawn as Word draws them: the dots are spaced by their advance in whole 600-dpi pixels (2.64 pt for TH SarabunPSK at 16 pt, not 2.59), from the first place on that grid after the text before the tab to the last one that ends before the text after it.
|
||||
- 2026-10-31: List numbers count as Word counts them when a deeper item comes first: a list that opens with 10.1–10.4 goes on with 11, not a second 10, and 1.1, 1.2 are followed by 2. A level above that hasn't counted yet takes its first number at the first deeper item.
|
||||
- 2026-11-01: Paragraph side borders lie outside the text, so a thick border no longer covers the first letter (#5036).
|
||||
- 2026-10-31: Percentage cell widths size table columns as in Word, whichever rows give them: where rows disagree a column takes the largest, a merged cell's percentage is shared by the columns under it, a header row of percentages over rows without cell widths now sets the columns, in autofit and fixed tables, scaled to the table's width or, without one, the text width (a fixed table's grid width); past 100% the columns take their shares left to right until the width runs out, and the ones after it get their longest words, or 2 pt each with their text clipped in a fixed table. Conflicting percentages, unsized columns, spans and absolute widths keep the grid.
|
||||
- 2026-10-31: DOCX: a paragraph naming a style the file doesn't define is formatted as Normal, as in Word, not with the document defaults alone, so a Pandoc footer naming an undefined `Footer` style is as tall as Word's and no longer pushes the last paragraph to the next page (#5077). Readiness unchanged.
|
||||
- 2026-10-31: Table of contents: with Word's table over entries in columns, where the title sits in a one-column section above a continuous break, Insert Table of Contents with new settings keeps the title above the break and the entries in their columns (the new title went under the break, into the columns), and Remove Table of Contents takes the title, the blank paragraph and its break with the entries, as Word does (observed in Word for Mac); a paragraph of another style above the break stays (#4041).
|
||||
- 2026-10-31: A table of contents writes its page numbers as `PAGEREF` fields to the headings' bookmarks, as Word does, so updating the fields in Word moves the numbers with the headings; they were plain text (#5097).
|
||||
@@ -1028,6 +1029,7 @@ MATH glyphs that reference the same construction now share its immutable variant
|
||||
| 2026-11-01 | trivial | Progress log: proofing moved to craft-proof (craft-libs) and its data to craft-i18n `language-data/` (CP1) |
|
||||
| 2026-11-01 | trivial | #3915: preserve guarded whole-line ordinary-tab alignment with current main. Existing controls retained; source checks only, primary qualification pending. |
|
||||
| 2026-11-01 | trivial | #2437: Preserve finite paragraph-border flow extents and terminal-break keep preflight with current-main changes. Recursive terminal-successor lookahead remains outside scope. Source checks only; primary qualification pending. |
|
||||
| 2026-10-31 | trivial | Progress log: percentage cell widths size table columns whichever rows give them |
|
||||
| 2026-10-31 | trivial | Progress log: a paragraph naming an undefined DOCX style is formatted as Normal (#5077) |
|
||||
| 2026-10-31 | minor | #3398: persistent screen-only green, cream and gray paper presets, with document backgrounds and export colors retained. Read Mode None follows the screen preset; Sepia/Inverse retain priority. |
|
||||
| 2026-10-31 | trivial | Progress log: TOC page numbers are PAGEREF fields (#5097) |
|
||||
|
||||
+143
-2
@@ -378,7 +378,9 @@ struct TableFrame {
|
||||
x: f32,
|
||||
}
|
||||
|
||||
// Nested measurement needs the same preferred weights as layout before sharing span minima.
|
||||
/// The table's column widths before autofit: its grid, or equal shares of `avail` without one,
|
||||
/// then the cells' absolute and percentage widths. Nested measurement needs the same preferred
|
||||
/// weights as layout before sharing span minima.
|
||||
fn preferred_grid(t: &Table, avail: f32) -> Vec<f32> {
|
||||
let ncols = grid_cols(t).max(1);
|
||||
let mut grid: Vec<f32> = if t.grid.len() == ncols {
|
||||
@@ -395,6 +397,7 @@ fn preferred_grid(t: &Table, avail: f32) -> Vec<f32> {
|
||||
vec![avail / ncols as f32; ncols]
|
||||
};
|
||||
apply_cell_widths(t, &mut grid);
|
||||
apply_pct_widths(t, &mut grid, avail);
|
||||
grid
|
||||
}
|
||||
|
||||
@@ -723,6 +726,9 @@ struct TableRows<'a> {
|
||||
total: f32,
|
||||
}
|
||||
|
||||
/// Place the laid-out cells of every row: vertical alignment, turned text, borders and the cell
|
||||
/// rectangles, clipped where the row's exact height or a fixed table's column is too small for
|
||||
/// the cell's text.
|
||||
fn finish_table_rows(ctx: &mut Ctx, input: TableRows<'_>) -> TableLayout {
|
||||
let TableRows { story, table: t, path, depth, cell_text, rows, heights, bottoms, edges, x, total } = input;
|
||||
// Grid columns holding a vertical-merge continuation, per row.
|
||||
@@ -858,7 +864,9 @@ fn finish_table_rows(ctx: &mut Ctx, input: TableRows<'_>) -> TableLayout {
|
||||
row: ri,
|
||||
cell: ci,
|
||||
story,
|
||||
clip: exact && c.h > span_h + 0.01,
|
||||
// A fixed table's cell too narrow for any text (its lines are laid out 4 pt wide)
|
||||
// clips them, as Word does, rather than letting them run past its edges.
|
||||
clip: (exact && c.h > span_h + 0.01) || (t.props.fixed && c.w - c.margins[1] - c.margins[3] < 4.0),
|
||||
});
|
||||
let top = c.margins[0] + c.borders.top.filter(Border::is_visible).map_or(0.0, |b| b.width.clamp(0.0, 12.0));
|
||||
parts.push(CellPart { top, items: first..items.len(), end, align });
|
||||
@@ -1535,6 +1543,121 @@ fn apply_cell_widths(t: &Table, grid: &mut [f32]) {
|
||||
grid.copy_from_slice(&widths);
|
||||
}
|
||||
|
||||
/// Word sizes each column by the percentage its cells ask for, whichever rows ask: cells without a
|
||||
/// preferred width take no part, so a header row of percentages sizes the automatic rows below it.
|
||||
/// The percentages are shares of the table's width, scaled up when they come short of 100%; past
|
||||
/// 100% the columns take their shares left to right until the width runs out
|
||||
/// (`overfull_shares`). A table without a
|
||||
/// width of its own takes `avail` when autofit and its grid's width when fixed. Where rows ask
|
||||
/// different percentages of a column it takes the largest. A merged cell's percentage is shared
|
||||
/// by the columns under it that ask none of their own, in their grid proportions (Word shares it
|
||||
/// by their content), and makes no column narrower than it asks. Measured in Word. Columns no cell
|
||||
/// sizes and absolute widths keep the grid.
|
||||
fn apply_pct_widths(t: &Table, grid: &mut [f32], avail: f32) {
|
||||
let mut pcts: Vec<Option<f32>> = vec![None; grid.len()];
|
||||
let mut merged: Vec<(usize, usize, f32)> = Vec::new();
|
||||
for row in &t.rows {
|
||||
let mut g = row.first_grid();
|
||||
for cell in &row.cells {
|
||||
if cell.props.width.is_some() {
|
||||
return;
|
||||
}
|
||||
if let Some(p) = cell.props.width_pct {
|
||||
if !p.is_finite() || p <= 0.0 {
|
||||
return;
|
||||
}
|
||||
if cell.span() == 1 {
|
||||
let Some(slot) = pcts.get_mut(g) else { return };
|
||||
*slot = Some(slot.map_or(p, |q| q.max(p)));
|
||||
} else {
|
||||
merged.push((g, cell.span(), p));
|
||||
}
|
||||
}
|
||||
g = g.saturating_add(cell.span());
|
||||
}
|
||||
}
|
||||
for (g, span, p) in merged {
|
||||
let Some(cols) = pcts.get_mut(g..g.saturating_add(span)) else { return };
|
||||
let Some(weights) = grid.get(g..g.saturating_add(span)) else { return };
|
||||
let own: f32 = cols.iter().flatten().sum();
|
||||
let free: f32 = cols.iter().zip(weights).filter(|(c, _)| c.is_none()).map(|(_, w)| *w).sum();
|
||||
let rest = (p - own).max(0.0);
|
||||
if free > 0.0 {
|
||||
for (c, w) in cols.iter_mut().zip(weights) {
|
||||
if c.is_none() {
|
||||
*c = Some(rest * w / free);
|
||||
}
|
||||
}
|
||||
} else if own > 0.0 && rest > 0.0 {
|
||||
// Every column asks its own, short of the merged cell's: they grow to it together.
|
||||
cols.iter_mut().flatten().for_each(|c| *c *= p / own);
|
||||
}
|
||||
}
|
||||
let Some(pcts) = pcts.into_iter().collect::<Option<Vec<f32>>>() else { return };
|
||||
if pcts.iter().any(|p| *p <= 0.0) {
|
||||
return;
|
||||
}
|
||||
let sum: f32 = pcts.iter().sum();
|
||||
let own_width = t.props.width_pct.is_some_and(|p| p > 0.0) || t.props.width.is_some_and(|w| w > 0.0);
|
||||
// A table with its own width is scaled to it afterwards; any positive total will do. A fixed
|
||||
// table without one keeps its grid's width.
|
||||
let total = if own_width || t.props.fixed { grid.iter().sum() } else { avail };
|
||||
if !sum.is_finite() || sum <= 0.0 || !total.is_finite() || total <= 0.0 {
|
||||
return;
|
||||
}
|
||||
if sum <= 100.0 {
|
||||
let shares: Vec<f32> = pcts.iter().map(|p| total * (p / sum)).collect();
|
||||
// A grid Word wrote from these same percentages is within its rounding of them (whole
|
||||
// twips, and percentages in fiftieths): it is kept exactly. Rebuilt, a column could come
|
||||
// out a few hundredths of a point narrower and wrap its text differently (#6575).
|
||||
let rounding = 0.05 + total * 0.0002;
|
||||
if grid.iter().zip(&shares).all(|(g, s)| (g - s).abs() <= rounding) {
|
||||
return;
|
||||
}
|
||||
grid.copy_from_slice(&shares);
|
||||
return;
|
||||
}
|
||||
// A grid too narrow for the floor in every column shares its width out instead, so the table
|
||||
// keeps it.
|
||||
let floor = if t.props.fixed { FIXED_PCT_MIN_COLUMN.min(total / pcts.len() as f32) } else { 0.0 };
|
||||
grid.copy_from_slice(&overfull_shares(&pcts, total, floor));
|
||||
}
|
||||
|
||||
/// Over 100%, as Word lays it out: the columns take their shares left to right until the table's
|
||||
/// width runs out; the column it runs out in takes what is left, and those after it nothing. In an
|
||||
/// autofit table autofit then widens them to their longest words at the others' expense. In a
|
||||
/// fixed table they keep `floor` each, their text clipped, and the shares are of what is left
|
||||
/// once those are set aside.
|
||||
fn overfull_shares(pcts: &[f32], total: f32, floor: f32) -> Vec<f32> {
|
||||
let mut starved = 0;
|
||||
loop {
|
||||
let room = (total - floor * starved as f32).max(0.0);
|
||||
let mut used = 0.0;
|
||||
let mut short = 0;
|
||||
let widths: Vec<f32> = pcts
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let w = (room * p / 100.0).min(room - used);
|
||||
if w < floor || w <= 0.0 {
|
||||
short += 1;
|
||||
return floor;
|
||||
}
|
||||
used += w;
|
||||
w
|
||||
})
|
||||
.collect();
|
||||
// More columns starved than were set aside for: set aside for them and share again.
|
||||
if short <= starved || starved >= pcts.len() {
|
||||
return widths;
|
||||
}
|
||||
starved = short;
|
||||
}
|
||||
}
|
||||
|
||||
/// The narrowest a fixed table's columns get when the percentages before them fill the table
|
||||
/// (measured in Word: 2 pt, with or without a table width).
|
||||
const FIXED_PCT_MIN_COLUMN: f32 = 2.0;
|
||||
|
||||
/// Word's autofit for a table whose widths may follow its content (`tblLayout` not fixed).
|
||||
/// - With no preferred width anywhere (the table's and every cell's automatic) the columns come
|
||||
/// from their content alone: each its widest line if they all fit in `avail`, else shared out
|
||||
@@ -1594,6 +1717,24 @@ mod width_tests {
|
||||
assert_eq!(grid, [28.0, 111.0, 40.0, 81.0]);
|
||||
}
|
||||
|
||||
/// #5074 review (and #6575): a grid Word wrote from the cells' percentages is kept exactly,
|
||||
/// while one that is off by more than Word's rounding is rebuilt from them.
|
||||
#[test]
|
||||
fn a_grid_matching_its_percentages_is_kept() {
|
||||
let mut t = Table::new(1, 3, 300.0);
|
||||
t.props.width = Some(300.0);
|
||||
for (cell, p) in t.rows[0].cells.iter_mut().zip([33.32, 33.34, 33.34]) {
|
||||
cell.props.width = None;
|
||||
cell.props.width_pct = Some(p);
|
||||
}
|
||||
let mut grid = [99.95, 100.05, 100.0];
|
||||
apply_pct_widths(&t, &mut grid, 468.0);
|
||||
assert_eq!(grid, [99.95, 100.05, 100.0], "kept");
|
||||
let mut stale = [90.0, 110.0, 100.0];
|
||||
apply_pct_widths(&t, &mut stale, 468.0);
|
||||
assert!(stale.iter().zip([99.96, 100.02, 100.02]).all(|(g, w)| (g - w).abs() < 0.01), "rebuilt: {stale:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn autofit_exhausts_donors() {
|
||||
crate::test_fonts();
|
||||
|
||||
@@ -12444,6 +12444,219 @@ fn cell_widths_override_grid() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn percentage_cell_widths_that_disagree_or_span_columns() {
|
||||
// Measured in Word (A4, 451.3 pt between the margins; 468 pt here), autofit tables 100% wide:
|
||||
// rows asking 30/10/10/30 and 10/30/10/30, in either order, give 30/30/10/30 (each column its
|
||||
// largest); a merged cell asking 50% over the first two columns, beside 10% and 40%, gives
|
||||
// those two 50% between them; a merged 20% over columns asking 40% and 10% changes nothing;
|
||||
// and a nested table's percentages are of its own width.
|
||||
let cell_text = |s: &str| vec![wordcraft_doc::para_block(Paragraph::with_text(s, Default::default()))];
|
||||
let table = |rows: &[&[(Option<f32>, u32)]]| {
|
||||
let mut t = Table::new(rows.len(), 4, 460.3);
|
||||
t.grid = vec![107.3, 37.2, 31.95, 283.85];
|
||||
t.props.width_pct = Some(100.0);
|
||||
for (row, spec) in t.rows.iter_mut().zip(rows) {
|
||||
row.cells.truncate(spec.len());
|
||||
for (cell, (pct, span)) in row.cells.iter_mut().zip(spec.iter()) {
|
||||
cell.props.width = None;
|
||||
cell.props.width_pct = *pct;
|
||||
cell.props.span = *span;
|
||||
cell.blocks = cell_text("A");
|
||||
}
|
||||
}
|
||||
t
|
||||
};
|
||||
let starts_at = |t: Table, prefix: &[u32], row: u32| {
|
||||
let mut d = Document::from_text("After");
|
||||
d.insert_block(StoryRef::Body, &Path::top(0), wordcraft_doc::Block::Table(t)).unwrap();
|
||||
let l = lay(&d);
|
||||
let x: Vec<f32> = (0..4)
|
||||
.map(|c| {
|
||||
let path: Vec<u32> = prefix.iter().copied().chain([row, c, 0]).collect();
|
||||
let [(x, _, _)] = para_at(&l, &path)[..] else { panic!("cell {c} missing") };
|
||||
x
|
||||
})
|
||||
.collect();
|
||||
x.iter().map(|v| v - x[0]).collect::<Vec<_>>()
|
||||
};
|
||||
let near = |got: Vec<f32>, want: [f32; 4], what: &str| {
|
||||
assert!(got.iter().zip(want).all(|(g, w)| (g - w).abs() < 0.01), "{what}: columns start at {got:?}, not {want:?}");
|
||||
};
|
||||
let at = |shares: [f32; 3]| [0.0, shares[0] * 468.0, shares[1] * 468.0, shares[2] * 468.0];
|
||||
let p = |v: f32| (Some(v), 1);
|
||||
let auto = (None, 1);
|
||||
let open = [auto, auto, auto, auto];
|
||||
near(
|
||||
starts_at(table(&[&[p(30.0), p(10.0), p(10.0), p(30.0)], &[p(10.0), p(30.0), p(10.0), p(30.0)], &open]), &[0], 2),
|
||||
at([0.3, 0.6, 0.7]),
|
||||
"rows disagree",
|
||||
);
|
||||
near(
|
||||
starts_at(table(&[&[p(10.0), p(30.0), p(10.0), p(30.0)], &[p(30.0), p(10.0), p(10.0), p(30.0)], &open]), &[0], 2),
|
||||
at([0.3, 0.6, 0.7]),
|
||||
"the other order",
|
||||
);
|
||||
let merged = starts_at(table(&[&[(Some(50.0), 2), p(10.0), p(40.0)], &open]), &[0], 1);
|
||||
near(vec![merged[0], merged[2], merged[3]].into_iter().chain([0.0]).collect(), [0.0, 0.5 * 468.0, 0.6 * 468.0, 0.0], "merged 50%");
|
||||
near(
|
||||
starts_at(table(&[&[p(40.0), p(10.0), p(10.0), p(40.0)], &[(Some(20.0), 2), auto, auto], &open]), &[0], 2),
|
||||
at([0.4, 0.5, 0.6]),
|
||||
"a smaller merged cell",
|
||||
);
|
||||
// The nested table fills the outer table's only cell, less the cell's margins.
|
||||
let inner = table(&[&[p(40.0), p(10.0), p(10.0), p(40.0)], &open]);
|
||||
let mut outer = Table::new(1, 1, 468.0);
|
||||
outer.props.width_pct = Some(100.0);
|
||||
outer.rows[0].cells[0].props.width_pct = Some(100.0);
|
||||
outer.rows[0].cells[0].blocks = vec![std::sync::Arc::new(wordcraft_doc::Block::Table(inner)), wordcraft_doc::para_block(Paragraph::new())];
|
||||
let nested = starts_at(outer, &[0, 0, 0, 0], 1);
|
||||
let w = nested[3] / 0.6;
|
||||
near(nested, [0.0, 0.4 * w, 0.5 * w, 0.6 * w], "nested");
|
||||
assert!(w > 400.0 && w <= 468.0, "the nested table is {w} wide");
|
||||
}
|
||||
#[test]
|
||||
fn percentage_cell_widths_size_the_columns_whichever_rows_ask() {
|
||||
// Measured in Word (A4, 451.3 pt between the margins; 468 pt here): a 40/10/10/40 header row
|
||||
// over rows without cell widths lays out 40/10/10/40 of the table, from the grid
|
||||
// 107.3/37.2/32/283.9 pt a document saved. The same with the row in the middle, in a fixed
|
||||
// table, with the table 100% wide or without a width; 144 pt for 40% of a 360 pt table; and
|
||||
// 20/5/5/20 scaled up to fill the table.
|
||||
let starts = |t: Table| {
|
||||
let mut d = Document::from_text("After");
|
||||
d.insert_block(StoryRef::Body, &Path::top(0), wordcraft_doc::Block::Table(t)).unwrap();
|
||||
let l = lay(&d);
|
||||
let x: Vec<f32> = (0..4)
|
||||
.map(|c| {
|
||||
let [(x, _, _)] = para_at(&l, &[0, 2, c, 0])[..] else { panic!("cell {c} missing") };
|
||||
x
|
||||
})
|
||||
.collect();
|
||||
x.iter().map(|v| v - x[0]).collect::<Vec<_>>()
|
||||
};
|
||||
let table = |pct_row: usize, pcts: [f32; 4]| {
|
||||
let mut t = Table::new(4, 4, 460.3);
|
||||
t.grid = vec![107.3, 37.2, 31.95, 283.85];
|
||||
for (r, row) in t.rows.iter_mut().enumerate() {
|
||||
for (cell, p) in row.cells.iter_mut().zip(pcts) {
|
||||
cell.props.width = None;
|
||||
cell.props.width_pct = (r == pct_row).then_some(p);
|
||||
cell.blocks = vec![wordcraft_doc::para_block(Paragraph::with_text("A", Default::default()))];
|
||||
}
|
||||
}
|
||||
t
|
||||
};
|
||||
let near = |got: Vec<f32>, want: [f32; 4]| {
|
||||
assert!(got.iter().zip(want).all(|(g, w)| (g - w).abs() < 0.01), "columns start at {got:?}, not {want:?}");
|
||||
};
|
||||
let of = |w: f32| [0.0, w * 0.4, w * 0.5, w * 0.6];
|
||||
near(starts(table(0, [40.0, 10.0, 10.0, 40.0])), of(468.0));
|
||||
near(starts(table(1, [40.0, 10.0, 10.0, 40.0])), of(468.0));
|
||||
near(starts(table(0, [20.0, 5.0, 5.0, 20.0])), of(468.0));
|
||||
// A fixed table without a width of its own keeps its grid's 460.3 pt; 100% wide, it takes
|
||||
// the text width.
|
||||
let mut fixed = table(0, [40.0, 10.0, 10.0, 40.0]);
|
||||
fixed.props.fixed = true;
|
||||
near(starts(fixed.clone()), of(460.3));
|
||||
fixed.props.width_pct = Some(100.0);
|
||||
near(starts(fixed), of(468.0));
|
||||
let mut full = table(0, [40.0, 10.0, 10.0, 40.0]);
|
||||
full.props.width_pct = Some(100.0);
|
||||
near(starts(full), of(468.0));
|
||||
let mut narrow = table(0, [20.0, 5.0, 5.0, 20.0]);
|
||||
narrow.props.width = Some(360.0);
|
||||
near(starts(narrow), of(360.0));
|
||||
// A row that starts one column in gives its percentages to the columns it covers: 10/10/40
|
||||
// there agree with the header row's 10/10/40 over the last three columns.
|
||||
let mut shifted = table(0, [40.0, 10.0, 10.0, 40.0]);
|
||||
shifted.rows[1].props.grid_before = 1;
|
||||
shifted.rows[1].cells.remove(0);
|
||||
for (cell, p) in shifted.rows[1].cells.iter_mut().zip([10.0, 10.0, 40.0]) {
|
||||
cell.props.width_pct = Some(p);
|
||||
}
|
||||
near(starts(shifted), of(468.0));
|
||||
// Past 100% Word gives every column but the last its share of the table and the last what
|
||||
// is left: 44/11/11/44 starts the columns at 44%, 55% and 66%. At 60/20/20/60 nothing is left,
|
||||
// so the last column takes its longest word and the other three give up the same width.
|
||||
near(starts(table(0, [44.0, 11.0, 11.0, 44.0])), [0.0, 0.44, 0.55, 0.66].map(|f| f * 468.0));
|
||||
let over = starts(table(0, [60.0, 20.0, 20.0, 60.0]));
|
||||
let lost = [0.6 * 468.0 - over[1], 0.2 * 468.0 - (over[2] - over[1]), 0.2 * 468.0 - (over[3] - over[2])];
|
||||
assert!(lost[0] > 1.0 && lost.iter().all(|l| (l - lost[0]).abs() < 0.01), "columns start at {over:?}");
|
||||
// A fixed table gives the last column 2 pt and clips its text to the cell instead; the
|
||||
// others share the rest of its 460.3 pt (Word: 275.5, 91.5, 91 and 2 pt).
|
||||
let mut fixed_over = table(0, [60.0, 20.0, 20.0, 60.0]);
|
||||
fixed_over.props.fixed = true;
|
||||
for row in &mut fixed_over.rows {
|
||||
row.cells[3].blocks = vec![wordcraft_doc::para_block(Paragraph::with_text("Lorem ipsum", Default::default()))];
|
||||
}
|
||||
near(starts(fixed_over.clone()), [0.0, 0.6, 0.8, 1.0].map(|f| f * (460.3 - 2.0)));
|
||||
let mut d = Document::from_text("After");
|
||||
d.insert_block(StoryRef::Body, &Path::top(0), wordcraft_doc::Block::Table(fixed_over)).unwrap();
|
||||
let l = lay(&d);
|
||||
let cells: Vec<(usize, f32, bool)> = l.pages[0]
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|i| if let Placed::Cell { cell, rect, clip, row: 0, .. } = i { Some((*cell, rect.w, *clip)) } else { None })
|
||||
.collect();
|
||||
assert!(cells.iter().any(|&(c, w, clip)| c == 3 && (w - 2.0).abs() < 0.01 && clip), "the last cell is 2 pt and clipped: {cells:?}");
|
||||
assert!(cells.iter().all(|&(c, _, clip)| c == 3 || !clip), "only the last cell is clipped: {cells:?}");
|
||||
// When the columns before the last already pass 100% (80/40/40/20), Word gives them their
|
||||
// shares left to right until the width runs out, and the table keeps its width: in a fixed
|
||||
// table the third and fourth columns get 2 pt, the shares being of 460.3 - 4 pt; in an
|
||||
// autofit table they get their longest words, the first two giving up the same width.
|
||||
let widths = |t: Table| {
|
||||
let mut d = Document::from_text("After");
|
||||
d.insert_block(StoryRef::Body, &Path::top(0), wordcraft_doc::Block::Table(t)).unwrap();
|
||||
let l = lay(&d);
|
||||
let mut w: Vec<(usize, f32)> = l.pages[0]
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|i| if let Placed::Cell { cell, rect, row: 0, .. } = i { Some((*cell, rect.w)) } else { None })
|
||||
.collect();
|
||||
w.sort_by_key(|c| c.0);
|
||||
w.into_iter().map(|c| c.1).collect::<Vec<f32>>()
|
||||
};
|
||||
let mut fixed_far = table(0, [80.0, 40.0, 40.0, 20.0]);
|
||||
fixed_far.props.fixed = true;
|
||||
let got = widths(fixed_far);
|
||||
let room = 460.3 - 4.0;
|
||||
let want = [0.8 * room, 0.2 * room, 2.0, 2.0];
|
||||
assert!(got.iter().zip(want).all(|(g, w)| (g - w).abs() < 0.01), "fixed 80/40/40/20: {got:?}, not {want:?}");
|
||||
assert!((got.iter().sum::<f32>() - 460.3).abs() < 0.01, "fixed 80/40/40/20 is {} wide", got.iter().sum::<f32>());
|
||||
// A fixed grid narrower than 2 pt a column keeps its width: the columns share it.
|
||||
let mut fixed_narrow = table(0, [80.0, 40.0, 40.0, 20.0]);
|
||||
fixed_narrow.props.fixed = true;
|
||||
fixed_narrow.grid = vec![1.5; 4];
|
||||
let got = widths(fixed_narrow);
|
||||
assert!(got.iter().all(|w| (w - 1.5).abs() < 0.01), "a fixed 6 pt grid of 80/40/40/20: {got:?}");
|
||||
let got = widths(table(0, [80.0, 40.0, 40.0, 20.0]));
|
||||
assert!((got.iter().sum::<f32>() - 468.0).abs() < 0.01, "autofit 80/40/40/20 is {} wide: {got:?}", got.iter().sum::<f32>());
|
||||
let lost = [0.8 * 468.0 - got[0], 0.2 * 468.0 - got[1]];
|
||||
assert!(lost[0] > 1.0 && (lost[0] - lost[1]).abs() < 0.01 && got[2] > 1.0 && got[3] > 1.0, "autofit 80/40/40/20: {got:?}");
|
||||
// A smaller percentage in another row of a column changes nothing: the column takes its
|
||||
// largest. A merged cell's 20% goes to the two columns under it, which ask none.
|
||||
let mut disagreeing = table(0, [40.0, 10.0, 10.0, 40.0]);
|
||||
disagreeing.rows[1].cells[0].props.width_pct = Some(10.0);
|
||||
near(starts(disagreeing), of(468.0));
|
||||
let mut spanned = table(0, [40.0, 10.0, 10.0, 40.0]);
|
||||
spanned.rows[0].cells.remove(2);
|
||||
spanned.rows[0].cells[1].props.span = 2;
|
||||
spanned.rows[0].cells[1].props.width_pct = Some(20.0);
|
||||
let got = starts(spanned);
|
||||
assert!((got[1] - 0.4 * 468.0).abs() < 0.01 && (got[3] - 0.6 * 468.0).abs() < 0.01, "merged 20%: columns start at {got:?}");
|
||||
// A column no cell sizes and an absolute width alongside keep the grid.
|
||||
let grid = [0.0, 107.3, 144.5, 176.45];
|
||||
let mut unsized_column = table(0, [40.0, 10.0, 10.0, 40.0]);
|
||||
unsized_column.rows[0].cells[3].props.width_pct = None;
|
||||
let mut absolute = table(0, [40.0, 10.0, 10.0, 40.0]);
|
||||
absolute.rows[1].cells[0].props.width = Some(100.0);
|
||||
for t in [unsized_column, absolute] {
|
||||
let got = starts(t);
|
||||
let k = got[3] / grid[3];
|
||||
near(got, grid.map(|g| g * k));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ambiguous_widths_keep_grid() {
|
||||
crate::test_fonts();
|
||||
|
||||
+2
-1
@@ -35,7 +35,7 @@ Floating tables count exact contact with a line's bottom edge (#3977); shapes ke
|
||||
|
||||
An otherwise empty section at page start retains its line before continuous content. Shared-section page totals and wrapping earlier text around later floating tables remain open.
|
||||
|
||||
Consistent cell widths override stale table grid proportions when their totals agree. Conflicting widths, spans and percentages still need the shared-grid algorithm.
|
||||
Consistent cell widths override stale table grid proportions when their totals agree. Percentage cell widths size their columns whichever rows give them, as in Word: rows that disagree give each column its largest, and a merged cell's percentage is shared by the columns under it (in grid proportions, where Word shares it by their content). Mixed absolute and percentage widths still need the shared-grid algorithm.
|
||||
|
||||
Protected typing boundary discovery (#3614) counts earlier objects once and uses an editable-ID set when moving through consecutive permission markers. Permission matching, protection enforcement and saved formats are unchanged. This narrows gap #3; broader stability and mutation costs remain.
|
||||
|
||||
@@ -270,6 +270,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
|
||||
| 2026-10-31 | trivial | Preserve recipient columns after an unquoted whitespace-only prefix in a headered CSV (#4249); keep quoted headers, headerless whitespace records and shared CSV parsing. |
|
||||
| 2026-10-31 | trivial | Integrate complete-record recipient CSV delimiter detection (#4249) with current main; preserve leading blank-line detection (#5042), original regressions and readiness estimates. |
|
||||
| 2026-11-01 | trivial | #2437: Preserve finite paragraph-border flow extents and terminal-break keep preflight with current-main changes. Recursive terminal-successor lookahead remains outside scope. Source checks only; primary qualification pending. |
|
||||
| 2026-10-31 | trivial | Percentage cell widths size their columns whichever rows give them, as measured in Word, rows that disagree giving each column its largest and merged cells sharing theirs; mixed absolute and percentage widths still need the shared-grid algorithm; no ranked gap changed; readiness estimates unchanged |
|
||||
| 2026-10-30 | trivial | Only the PDF sent to the printer omits link annotations; File › Print › Save these pages as PDF (`file.printPdf`) keeps them, like Export (#4734); no ranked gap changed; readiness estimates unchanged |
|
||||
| 2026-10-29 | trivial | The print job's PDF omits link annotations, which the spooler refused to fit to the paper, so documents with links reach the printer (#4734); physical printer output remains to be validated; no ranked gap changed; readiness estimates unchanged |
|
||||
| 2026-10-31 | trivial | Synchronize the existing Proofing pane with main `eecbb8f`; preserve explicit-position lookup, implicit selection, navigation, undo and per-window state; fresh exact-SHA hosted validation pending, readiness unchanged |
|
||||
|
||||
@@ -70,7 +70,7 @@ Exact line spacing keeps the run font baseline around tall equations; automatic
|
||||
| Tables: row border exceptions (`w:tblPrEx/w:tblBorders`) | ✅ | `row_borders_stay_on_row`, `row_nil_overrides_style`: explicit cell borders win; row exceptions precede table styles and table borders | — |
|
||||
| Footnotes at the page bottom, endnotes at the end, note numbering | 🟡 | A long note continues onto the next page at a line boundary (its first line stays with the reference), first in that page's note area under a full-width continuation separator (#352); the document's own separator, continuation separator and continuation notice are drawn (the notice under a note that continues); on a page with footnotes a paragraph ending there keeps its space after above the separator, or its last lines go to the next page with the note (#1116); a long endnote continues on the next column or page at a line boundary (#456), and the caret finds note text on its continuation page (#457); each section's note options: footnotes below the text, endnotes at the end of each section, start at, numbering restarted each section or each page (counted from where the notes land, at most three passes) (#385) | 1–2 |
|
||||
| Tables: row heights (at least/exact), rows split across pages, header rows repeat, Can't Split | ✅ | 2026-10-06, #138; omitted cell-margin edges inherit current table defaults; every cell in a row gets the row's largest top and bottom margin; an exact height covers the top border, top margin and text, the bottom margin comes on top, and an exact row never splits; a row split across pages keeps its cells' bottom margin, border and last space after on the first page, widow/orphan control applies in its cells, each cell continues at the top of the next page and an at-least row keeps its minimum; an at-least row with less room than its minimum on a page that already holds something starts the next page whole (Allow row to break on or off, vAlign centre too), as observed in Word for Mac 2026-10-15 (a row of about 2.6 cm), #1742; that repeated header rows go with it and that a row taller than a page splits from the top of the next page come from the issue and synthetic tests, not a Word check (`…_an_at_least_row_with_no_room_starts_the_next_page_whole_either_way_breaking_is_set`, `…_an_at_least_row_taller_than_a_page_splits_from_the_top_of_the_next_page`, `layout::tests::a_row_shares_its_largest_top_and_bottom_margins`, `…_a_split_row_keeps_its_bottom_margin_and_widow_control`, `…_split_row_cells_each_continue_at_the_top`); a row's `gridAfter` is bounded to 63 columns in native documents too, and repeated header rows stop after 500 000 copied items across a table (hostile documents, #3692); a cell aligned to the middle or bottom of a split row is aligned within the part left on the page when all its text fits there (as tall as the other cells' text there), and runs from the top of the cell otherwise, as measured in Word (`layout::tests::a_middle_or_bottom_cell_of_a_split_row_lines_up_on_the_first_page`); a row whose first part on a page that already holds something would leave a cell empty there, because that cell's first line or inline picture (one line, never split) runs past the room, moves on whole instead of leaving the other cells' text beside the empty cell, so an at-least row grown taller than its minimum by a picture no longer splits off its picture (#4272; inferred from the reporter's Word result and the earlier observation that Word doesn't leave a cell empty for widow control, not yet checked in Word for rows without a minimum; at the top of a page such a row still splits; `layout::tests::an_at_least_row_grown_by_its_picture_moves_on_whole_rather_than_leave_the_picture_behind`, `…_a_picture_row_that_fits_stays_and_text_rows_beside_a_short_picture_still_split`, `…_a_picture_row_too_tall_for_any_page_splits_from_the_top_of_the_next_one`); a row of a nested table marked Can't Split isn't split with its outer row: the outer row moves on whole when that row comes first in it (docxide-pdf `nested-first-row-*-cant1`) and otherwise splits above it (inferred, not yet checked in Word), and on a fresh page a nested row taller than the room still splits; `layout::tests::nested_cant_split::nested_cant_split_row_moves_on_with_its_outer_row`, `…::the_outer_row_splits_above_a_nested_cant_split_row`, `…::the_cut_moves_up_until_no_nested_cant_split_row_runs_through_it`, `…::the_outer_row_breaks_between_nested_cant_split_rows_above_its_bottom_band`, `…::a_bottom_aligned_cell_keeps_its_nested_cant_split_row_whole`, `…::header_rows_go_on_with_a_first_row_whose_nested_cant_split_row_comes_first`, `…::a_kept_row_goes_on_with_a_row_whose_nested_cant_split_row_cant_start_below_it`, `…::a_merged_cell_doesnt_stretch_its_cant_split_row`, `…::nested_cant_split_row_taller_than_a_page_still_splits` | — |
|
||||
| Tables: autofit to contents/window, fixed widths, Word 2013 edge | 🟡 | #137; #44: AutoFit Contents measures each column's narrowest and widest text and shares the width like Word, once (not live as you type); consistent a percentage width past 100% is kept, as Word does; a table with its own preferred width keeps it, however far past the margin, and only an automatic-width table over 1.5× the text width is squeezed to the margins (Word squeezes it as soon as it is wider) (#1721); cell widths override stale grid proportions when their totals agree (`cell_widths_override_grid`); conflicting widths and spans still differ | 3–5 |
|
||||
| Tables: autofit to contents/window, fixed widths, Word 2013 edge | 🟡 | #137; #44: AutoFit Contents measures each column's narrowest and widest text and shares the width like Word, once (not live as you type); consistent a percentage width past 100% is kept, as Word does; a table with its own preferred width keeps it, however far past the margin, and only an automatic-width table over 1.5× the text width is squeezed to the margins (Word squeezes it as soon as it is wider) (#1721); cell widths override stale grid proportions when their totals agree (`cell_widths_override_grid`); percentage cell widths size their columns whichever rows give them, cells without a width taking no part, scaled to the table's width (a fixed table without one keeps its grid's width), and past 100% the columns taking their shares left to right until the width runs out, the ones after it getting their longest words, or 2 pt each with their text clipped in a fixed table, as measured in Word (`percentage_cell_widths_size_the_columns_whichever_rows_ask`); conflicting widths and spans still differ | 3–5 |
|
||||
| Floating tables (`w:tblpPr`) | 🟡 | #137; one placed on the page or margin that would cover visible text before it and does not fit below it moves to the next page (#534); empty line-break lines do not count as text; a click below one, outside its cells, goes to the text beside or after it, not to its last row, as checked in Word (#2038); exact line-bottom contact counts for tables only (#3977), both in row-span selection and word skipping; exact-spacing table contact uses the specified height rather than paragraph-mark metrics, with original Source Sans 3 controls in modes 11/12/14/15; expected Word rule from [cyril265's Word for Mac 16.114.1 measurements](https://github.com/storytold/wordcraft/issues/3977#issuecomment-6374217574), not a new Word run of these originals; anchor-order replay remains #3790's scope; other overlap rules untested | 2–3 |
|
||||
| Floating tables (`w:tblpPr`) | 🟡 | #137; one placed on the page or margin that would cover visible text before it and does not fit below it moves to the next page (#534); empty line-break lines do not count as text; a click below one, outside its cells, goes to the text beside or after it, not to its last row, as checked in Word (#2038); the same for a click within 2pt of a cell whose text is turned comes from the issue and synthetic tests, not a check by hand (#4181); other overlap rules untested | 2–3 |
|
||||
| Floating tables (`w:tblpPr`) | 🟡 | #137; one placed on the page or margin that would cover visible text before it and does not fit below it moves to the next page (#534); empty line-break lines do not count as text; a click below one, outside its cells, goes to the text beside or after it, not to its last row, as checked in Word (#2038); exact line-bottom contact counts for tables only (#3977), both in row-span selection and word skipping; exact-spacing table contact uses the specified height rather than paragraph-mark metrics, with original Source Sans 3 controls in modes 11/12/14/15; expected Word rule from [cyril265's Word for Mac 16.114.1 measurements](https://github.com/storytold/wordcraft/issues/3977#issuecomment-6374217574), not a new Word run of these originals; anchor-order replay remains #3790's scope; one with `tblOverlap=never` moved below another keeps its distance from the text's left edge only in Word 2013 layout (mode 15), before it its own left edge, also when its first cell has no left margin (docxide `displaced-anchor-*`); other overlap rules untested | 2–3 |
|
||||
@@ -352,6 +352,7 @@ The front-of-text opt-out is retained from the earlier implementation; this patc
|
||||
| 2026-11-01 | trivial | #3915: preserve guarded whole-line ordinary-tab alignment with current main. Existing controls retained; source checks only, primary qualification pending. |
|
||||
| 2026-10-25 | trivial | Justified and distributed lines no longer stretch the spaces before a line's first character: Thai official letters indent paragraphs with ~20 spaces, and their first line moved right by up to the line's slack (86 pt in a measured case). Measured in Word with synthetic documents: left, `both`, `distribute` and `thaiDistribute` put the first character at the same place, for Thai and Latin text, at the paragraph start, after a line break and after a tab. A distributed line no longer counts the space it wrapped at, or the manual line break it ends with, so its text reaches the margin as in Word |
|
||||
| 2026-11-01 | trivial | #2437: Preserve finite paragraph-border flow extents and terminal-break keep preflight with current-main changes. Recursive terminal-successor lookahead remains outside scope. Source checks only; primary qualification pending. |
|
||||
| 2026-10-31 | trivial | Percentage cell widths size their columns whichever rows give them, as measured in Word: rows that disagree giving each column its largest and a merged cell's percentage shared by the columns under it; a header row of percentages over rows without cell widths, autofit or fixed, scaled to the table's width, the text width or a fixed table's grid width, and past 100% the columns taking their shares left to right until the width runs out (the ones after it 2 pt and clipped in a fixed table); conflicting percentages, unsized columns, spans and absolute widths keep the grid |
|
||||
| 2026-10-30 | trivial | Keep with next: a kept heading before a three-line paragraph under widow/orphan control needs room for all three lines, since that paragraph can only move over whole; with room for two, the heading goes to the next page with it instead of staying alone at the bottom, as in Word for Mac 16.93. `layout::tests::keep_with_next_carries_the_heading_when_a_three_line_paragraph_moves_whole` |
|
||||
| 2026-10-28 | trivial | Connector object lookups retain the typed column-selection inputs on current main (#3631); readiness estimates unchanged |
|
||||
| 2026-10-27 | trivial | Connector rerouting indexes laid-out object positions once per batch, preserving page hints, first-match order and same-page glue; synthetic equivalence, geometry and scaling regressions (#3631); routing policy and readiness estimates unchanged |
|
||||
|
||||
Reference in new issue
Block a user