mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-03 22:40:27 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edb536809e | ||
|
|
64960989a1 | ||
|
|
0f83ea9cf4 | ||
|
|
0859a447b6 | ||
|
|
df07115145 | ||
|
|
a761f276d5 |
@@ -160,8 +160,8 @@ fn layout_table_block(input: TableBlockContext<'_, '_, '_>) -> bool {
|
||||
let layout = table::layout_table(ctx, story, t, path, width, depth + 1);
|
||||
let (tx, ty) = match t.props.float {
|
||||
Some(float) => {
|
||||
let legacy = (ctx.doc.settings.compat_mode < 15).then(|| table::first_cell_left_margin(ctx, t));
|
||||
let (rect, area) = box_float_table_rect(frame, width, *y, &layout, &float, legacy, float_tables);
|
||||
let place = FloatPlace { shift: table::float_offset_shift(ctx, t), modern: ctx.doc.settings.compat_mode >= 15 };
|
||||
let (rect, area) = box_float_table_rect(frame, width, *y, &layout, &float, place, float_tables);
|
||||
exclusions.push((area, false, None, WrapText::BothSides, true));
|
||||
float_tables.push(area);
|
||||
table_areas.push(area);
|
||||
@@ -525,17 +525,25 @@ pub(crate) struct BoxLayout {
|
||||
pub(crate) last_top: f32,
|
||||
}
|
||||
|
||||
/// How a floating table placed by an offset stands from it.
|
||||
#[derive(Clone, Copy)]
|
||||
struct FloatPlace {
|
||||
/// How far left of the offset its edge stands ([`table::float_offset_shift`]).
|
||||
shift: f32,
|
||||
/// Word 2013 layout (compatibility mode 15).
|
||||
modern: bool,
|
||||
}
|
||||
|
||||
/// Where floating table `tl` goes in a box `width` wide whose next paragraph starts at `y`, and
|
||||
/// the area text keeps clear of. Positions relative to the page or its margins need the box's
|
||||
/// `frame`; without one (a table cell) they're relative to the box. `legacy` is the first cell's
|
||||
/// left margin before Word 2013 layout, `None` in it.
|
||||
/// `frame`; without one (a table cell) they're relative to the box.
|
||||
fn box_float_table_rect(
|
||||
frame: Option<PageFrame>,
|
||||
width: f32,
|
||||
y: f32,
|
||||
tl: &table::TableLayout,
|
||||
f: &TableFloat,
|
||||
legacy: Option<f32>,
|
||||
place: FloatPlace,
|
||||
float_tables: &[Rect],
|
||||
) -> (Rect, Rect) {
|
||||
let h = tl.rows.iter().map(|r| r.height).sum::<f32>().clamp(0.0, 100_000.0);
|
||||
@@ -571,8 +579,8 @@ fn box_float_table_rect(
|
||||
};
|
||||
// Nor is there an area to align in: the table starts where the text is.
|
||||
let v_align = if frame.is_none() && matches!(f.v_rel, Anchor::Page | Anchor::Margin) { None } else { f.v_align };
|
||||
let x = align_in(h_area, f.x, w, PageFrame::h_align(frame.as_ref(), f.h_align)) - if f.h_align.is_none() { legacy.unwrap_or(0.0) } else { 0.0 };
|
||||
let r = clear_of_float_tables(Rect::new(x, align_in(v_area, y_off, h, v_align), w, h), f, legacy.is_none(), h_area.0, float_tables);
|
||||
let x = align_in(h_area, f.x, w, PageFrame::h_align(frame.as_ref(), f.h_align)) - if f.h_align.is_none() { place.shift } else { 0.0 };
|
||||
let r = clear_of_float_tables(Rect::new(x, align_in(v_area, y_off, h, v_align), w, h), f, place.modern, h_area.0 - place.shift, float_tables);
|
||||
let [dl, dt, dr, db] = f.dist_from_text();
|
||||
(r, r.inset(-dl, -dt, -dr, -db))
|
||||
}
|
||||
|
||||
@@ -333,9 +333,26 @@ pub fn autofit_widths(cols: &[(f32, f32)], avail: f32) -> Vec<f32> {
|
||||
cols.iter().map(|c| c.0 + (c.1 - c.0) * k).collect()
|
||||
}
|
||||
|
||||
/// The first cell's left margin: how far its text sits inside the table's edge.
|
||||
pub(crate) fn first_cell_left_margin(ctx: &Ctx, t: &Table) -> f32 {
|
||||
first_cell_left_margin_in(t, default_margins(t, table_style(ctx, t).as_ref()))
|
||||
/// How far left of its offset (`w:tblpX`) a floating table placed by one has its edge. Before
|
||||
/// Word 2013 layout the first cell's text is at the offset, moved by the table's indent; from it
|
||||
/// the edge is, moved in by half its left border, the indent ignored (measured in Word for
|
||||
/// Windows).
|
||||
pub(crate) fn float_offset_shift(ctx: &Ctx, t: &Table) -> f32 {
|
||||
let style = table_style(ctx, t);
|
||||
if ctx.doc.settings.compat_mode < 15 {
|
||||
first_cell_left_margin_in(t, default_margins(t, style.as_ref())) - t.props.indent.unwrap_or(0.0)
|
||||
} else {
|
||||
-half_edge_border(t, &table_borders(t, style.as_ref()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Half the left border of a table's first cell, which Word (from mode 15) moves the table in by:
|
||||
/// the cell's own border, else its row's `w:tblPrEx`, else the table's (`borders`, with its style's).
|
||||
fn half_edge_border(t: &Table, borders: &Borders) -> f32 {
|
||||
let row = t.rows.first();
|
||||
let own = row.and_then(|r| r.cells.first()).and_then(|c| c.props.borders.and_then(|b| b.left));
|
||||
let exception = row.and_then(|r| r.props.exceptions.as_ref()).and_then(|e| e.borders).and_then(|b| b.left);
|
||||
own.or(exception).or(borders.left).filter(Border::is_visible).map_or(0.0, |b| b.width.clamp(0.0, 12.0) / 2.0)
|
||||
}
|
||||
|
||||
fn first_cell_left_margin_in(t: &Table, def: [f32; 4]) -> f32 {
|
||||
@@ -575,7 +592,6 @@ fn table_frame(ctx: &mut Ctx, t: &Table, avail: f32, depth: usize, style: Option
|
||||
let margins_def = default_margins(t, style);
|
||||
let indent = t.props.indent.unwrap_or(0.0);
|
||||
let tborders = table_borders(t, style);
|
||||
let first_cell = t.rows.first().and_then(|r| r.cells.first());
|
||||
// A right-to-left table (`w:bidiVisual`) mirrors: its first column stands at the right, its
|
||||
// start alignment and indent are measured from the right margin, and each cell's start
|
||||
// (left) margin and border are on its right.
|
||||
@@ -584,8 +600,7 @@ fn table_frame(ctx: &mut Ctx, t: &Table, avail: f32, depth: usize, style: Option
|
||||
let start_offset = if ctx.doc.settings.compat_mode >= 15 {
|
||||
// The border is centred on the edge, so half of it sits outside: Word moves the table in
|
||||
// by that half.
|
||||
let border = first_cell.and_then(|c| c.props.borders.and_then(|b| b.left)).or(tborders.left);
|
||||
indent + border.filter(Border::is_visible).map_or(0.0, |b| b.width.clamp(0.0, 12.0) / 2.0)
|
||||
indent + half_edge_border(t, &tborders)
|
||||
} else {
|
||||
indent - first_cell_left_margin_in(t, margins_def)
|
||||
};
|
||||
|
||||
@@ -207,8 +207,9 @@ pub(crate) fn place_table(ctx: &mut Ctx, pb: &mut PageBuilder, t: &wordcraft_doc
|
||||
let mut tl = table::layout_table(ctx, StoryRef::Body, t, &[block as u32], width, 1);
|
||||
if let Some(f) = t.props.float.filter(|_| !pb.web) {
|
||||
// Before Word 2013 layout (compatibility mode 15) an offset places the first cell's text,
|
||||
// so the edge sits a cell margin further out.
|
||||
let legacy = if ctx.doc.settings.compat_mode < 15 { table::first_cell_left_margin(ctx, t) } else { 0.0 };
|
||||
// so the edge sits a cell margin further out (and the indent further); from it the edge,
|
||||
// half its border in.
|
||||
let legacy = table::float_offset_shift(ctx, t);
|
||||
let h: f32 = tl.rows.iter().map(|r| r.height).sum();
|
||||
if h <= pb.uncapped_bottom() - pb.top + 0.01 {
|
||||
place_floating_table(ctx, pb, &tl, &f, legacy, block, body_top);
|
||||
@@ -400,11 +401,12 @@ fn place_floating_table(ctx: &mut Ctx, pb: &mut PageBuilder, tl: &table::TableLa
|
||||
let x = float_table_x(pb, w, f, legacy, ctx.mirror);
|
||||
let mut obstacles = if f.overlap { Vec::new() } else { header_table_areas(ctx, pb) };
|
||||
obstacles.extend_from_slice(&pb.float_tables);
|
||||
// Moved below another, it keeps its distance from the text's edge, half its border in.
|
||||
let r = clear_of_float_tables(
|
||||
Rect::new(x, align_in(v_area, f.y, h, f.v_align), w, h),
|
||||
f,
|
||||
ctx.doc.settings.compat_mode >= 15,
|
||||
h_area.0,
|
||||
h_area.0 - legacy,
|
||||
&obstacles,
|
||||
);
|
||||
// Like Word, a table that doesn't fit below the text before it moves to the next page with
|
||||
@@ -485,8 +487,8 @@ fn float_table_h_area(pb: &PageBuilder, f: &TableFloat, mirror: bool) -> (f32, f
|
||||
}
|
||||
}
|
||||
|
||||
/// A floating table's left edge on the page (`legacy`: the first cell's left margin before Word
|
||||
/// 2013 layout, when an offset places the cell's text).
|
||||
/// A floating table's left edge on the page (`legacy`: how far left of an offset its edge stands,
|
||||
/// [`table::float_offset_shift`]).
|
||||
fn float_table_x(pb: &PageBuilder, w: f32, f: &TableFloat, legacy: f32, mirror: bool) -> f32 {
|
||||
let align = PageFrame::h_align(Some(&page_frame(pb, mirror)), f.h_align);
|
||||
let x = align_in(float_table_h_area(pb, f, mirror), f.x, w, align);
|
||||
|
||||
@@ -19192,6 +19192,97 @@ fn header_text_covers_the_whole_band_of_centred_and_right_lines() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A floating table placed by an offset from the margin (measured in Word for Windows): before
|
||||
/// Word 2013 its first cell's text is at the offset, moved by `w:tblInd`; from it its edge is,
|
||||
/// moved in by half its left border, and `w:tblInd` doesn't move it.
|
||||
#[test]
|
||||
fn a_floating_table_placed_by_an_offset_takes_its_indent_before_word_2013_only() {
|
||||
crate::test_fonts();
|
||||
use wordcraft_doc::para::Anchor;
|
||||
use wordcraft_doc::props::TableFloat;
|
||||
let text_x = |mode: u32, indent: Option<f32>| {
|
||||
let mut t = Table::new(1, 2, 300.0);
|
||||
t.props.fixed = true;
|
||||
t.props.indent = indent;
|
||||
t.props.cell_margins = Some([0.0, 5.4, 0.0, 5.4]);
|
||||
t.props.borders = Some(wordcraft_doc::props::Borders::all(wordcraft_doc::props::Border::single(0.5)));
|
||||
t.props.float = Some(TableFloat { h_rel: Anchor::Margin, v_rel: Anchor::Paragraph, ..Default::default() });
|
||||
for c in &mut t.rows[0].cells {
|
||||
c.blocks = vec![wordcraft_doc::para_block(wordcraft_doc::Paragraph::with_text("Cell", Default::default()))];
|
||||
}
|
||||
let mut d = Document::from_text("Below");
|
||||
d.settings.compat_mode = mode;
|
||||
d.insert_block(StoryRef::Body, &Path::top(0), wordcraft_doc::Block::Table(t)).unwrap();
|
||||
lay(&d).pages[0]
|
||||
.items
|
||||
.iter()
|
||||
.find_map(|i| match i {
|
||||
Placed::Lines { path, x, .. } if path.0 == [0, 0, 0, 0] => Some(*x),
|
||||
_ => None,
|
||||
})
|
||||
.expect("the first cell's text")
|
||||
};
|
||||
let margin = 72.0;
|
||||
assert!((text_x(14, None) - margin).abs() < 0.01, "mode 14: {}", text_x(14, None));
|
||||
assert!((text_x(14, Some(-5.4)) - (margin - 5.4)).abs() < 0.01, "mode 14, indent: {}", text_x(14, Some(-5.4)));
|
||||
assert!((text_x(15, None) - (margin + 0.25 + 5.4)).abs() < 0.01, "mode 15: {}", text_x(15, None));
|
||||
assert!((text_x(15, Some(-5.4)) - (margin + 0.25 + 5.4)).abs() < 0.01, "mode 15, indent: {}", text_x(15, Some(-5.4)));
|
||||
}
|
||||
|
||||
/// From Word 2013 a table moves in by half its first cell's left border, and a first row's
|
||||
/// `w:tblPrEx` border is that border (measured in Word for Windows): with an 8 pt table border and
|
||||
/// a 2 pt exception the first cell's text is at 78.38, 1 pt in; without the exception at 81.38.
|
||||
/// The same inline and floating, and for every row.
|
||||
#[test]
|
||||
fn a_first_rows_exception_border_is_the_half_border_a_table_moves_in_by() {
|
||||
crate::test_fonts();
|
||||
use wordcraft_doc::para::Anchor;
|
||||
use wordcraft_doc::props::TableFloat;
|
||||
let text_x = |float: bool, exception: bool| {
|
||||
let mut t = Table::new(2, 2, 300.0);
|
||||
t.props.fixed = true;
|
||||
t.props.style = None;
|
||||
t.props.cell_margins = Some([0.0, 5.4, 0.0, 5.4]);
|
||||
t.props.borders = Some(Borders { left: Some(Border::single(8.0)), ..Default::default() });
|
||||
if float {
|
||||
t.props.float = Some(TableFloat { h_rel: Anchor::Margin, v_rel: Anchor::Paragraph, ..Default::default() });
|
||||
}
|
||||
if exception {
|
||||
t.rows[0].props.exceptions = Some(Box::new(wordcraft_doc::props::TableProps {
|
||||
borders: Some(Borders { left: Some(Border::single(2.0)), ..Default::default() }),
|
||||
..Default::default()
|
||||
}));
|
||||
}
|
||||
for r in &mut t.rows {
|
||||
for c in &mut r.cells {
|
||||
c.blocks = vec![wordcraft_doc::para_block(wordcraft_doc::Paragraph::with_text("Cell", Default::default()))];
|
||||
}
|
||||
}
|
||||
let mut d = Document::from_text("Below");
|
||||
d.settings.compat_mode = 15;
|
||||
d.insert_block(StoryRef::Body, &Path::top(0), wordcraft_doc::Block::Table(t)).unwrap();
|
||||
let l = lay(&d);
|
||||
let at = |row: u32| {
|
||||
l.pages[0]
|
||||
.items
|
||||
.iter()
|
||||
.find_map(|i| match i {
|
||||
Placed::Lines { path, x, .. } if path.0 == [0, row, 0, 0] => Some(*x),
|
||||
_ => None,
|
||||
})
|
||||
.expect("the first cell's text")
|
||||
};
|
||||
(at(0), at(1))
|
||||
};
|
||||
for float in [false, true] {
|
||||
for (exception, want) in [(false, 72.0 + 4.0 + 5.4), (true, 72.0 + 1.0 + 5.4)] {
|
||||
let (first, second) = text_x(float, exception);
|
||||
assert!((first - want).abs() < 0.01, "float {float}, exception {exception}: {first}");
|
||||
assert!((second - want).abs() < 0.01, "float {float}, exception {exception}, row 2: {second}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reading_layout_keeps_a_negatively_indented_table_in_the_column() {
|
||||
crate::test_fonts();
|
||||
|
||||
@@ -232,6 +232,7 @@ Page Setup's margin, paper-size and document-grid number boxes scroll long text
|
||||
| 2026-10-31 | trivial | dialogs are dialogs to screen readers, their tabs are tabs, the one shown selected, and colour fields and swatches say their colour |
|
||||
| 2026-11-01 | trivial | formatting shortcuts say what they did to screen readers |
|
||||
| 2026-10-30 | trivial | the Paste button is named "Paste" for screen readers, without macOS's key on other platforms; the status bar's Go To hint shows the platform's key |
|
||||
| 2026-11-17 | trivial | A floating table placed by an offset takes `w:tblInd` before Word 2013 (its first cell's text at the offset moved by the indent) and, from Word 2013, stands half its left border in from the offset with `w:tblInd` ignored, as measured in Word for Windows; no ranked gap changed |
|
||||
| 2026-11-17 | trivial | Right-to-left tables (`w:bidiVisual`): a cell's `w:left` and `w:right` margins (or `w:start` and `w:end`, the cell's or the table's) stay on the sides they name, as measured in Word for Windows; only the left and right borders are drawn mirrored; no ranked gap changed |
|
||||
| 2026-10-30 | trivial | #5: a list item deleted whole under Track Changes shows its number as deleted text, in the deletion's colour and mark, and hides it where deletions are hidden (#4828); estimate unchanged |
|
||||
| 2026-11-03 | trivial | A picture inserted or pasted in a table cell fits the cell (a nested cell too), in text columns the column, in another section that section, instead of the first section's text width (#5428); a fix, so no ranked gap changed; readiness estimates unchanged |
|
||||
|
||||
@@ -352,6 +352,7 @@ The front-of-text opt-out is retained from the earlier implementation; this patc
|
||||
| 2026-11-23 | trivial | Update Field shows CREATEDATE as the document's creation date (`dcterms:created`, in local time, with or without seconds), not today's; a creation date it can't read leaves the result as it was (#6331); readiness estimates unchanged |
|
||||
| 2026-11-09 | trivial | Different first page: a page is its section's first only if the section begins on it; a continuous section starting part-way down a page no longer shows its first-page header (and footer) on its second page (its default header, or its even one on an even page with different odd and even pages), compared with Word for Windows 365 on a synthetic file; the same when its first paragraph begins part-way down the page and runs over onto the next (not measured separately). `layout::tests::continuous_section_first_page_header_is_not_shown_on_its_second_page`, `continuous_section_first_paragraph_running_over_keeps_first_page_header_hidden` |
|
||||
| 2026-11-15 | trivial | A paragraph that starts a table cell's part of a page, in a row split across pages (the row continues from the page before, or starts the page, also under repeated header rows and in a nested table), can split even when only one line fits: a lone first line stays, a three-line paragraph with room for two splits two and one, and a lone continuation line stays, instead of keeping nothing so that the row ran off the bottom of the page. A non-exact row marked Can't Split that is taller than a page goes to a new page first when it starts below text, then splits where the page ends, instead of running off it (#6823; measured with synthetic documents in Word for Windows 16.0, compatibility mode 15, widow control on; `layout::tests::table_first_line`). A paragraph below other content of its cell, or in a row that starts below other content of the page, keeps the widow/orphan rule, which matched Word there. Not matched: Word leaves the repeated header off some pages of such a row (observed, no rule found), WordCraft repeats it on every page |
|
||||
| 2026-11-17 | trivial | A floating table placed by an offset takes `w:tblInd` before Word 2013 (its first cell's text at the offset moved by the indent) and, from Word 2013, stands half its left border in from the offset with `w:tblInd` ignored, as measured in Word for Windows |
|
||||
| 2026-11-17 | trivial | Right-to-left tables (`w:bidiVisual`): a cell's `w:left` and `w:right` margins (or `w:start` and `w:end`, the cell's or the table's) stay on the sides they name, as measured in Word for Windows; only the left and right borders are drawn mirrored |
|
||||
| 2026-10-29 | trivial | A list item deleted whole under Track Changes shows its number in the deletion's colour and with its mark (struck through by default) with markup, and not at all without (#4828) |
|
||||
| 2026-11-11 | trivial | The line a paragraph shares with the one before, whose mark is hidden, shows that one's shading and borders: the next paragraph's shading and borders no longer cover the text before it and start on its own next line, and what follows the shared line starts below the first one's bottom border. The joined copy keeps the paragraph's revision, so the word being typed in it gets no squiggle and its layouts are reused between passes (#3986) |
|
||||
|
||||
Reference in New Issue
Block a user