diff --git a/crates/model/src/table.rs b/crates/model/src/table.rs index 0705d1a08..e5a5c2f33 100644 --- a/crates/model/src/table.rs +++ b/crates/model/src/table.rs @@ -23,6 +23,7 @@ pub struct Cell { pub h_merge: bool, pub v_merge: bool, pub vertical: Option, + pub anchor_ctr: Option, } impl Cell { diff --git a/crates/pptx/src/read/shapes.rs b/crates/pptx/src/read/shapes.rs index 6d8acc4ad..6b19f29b1 100644 --- a/crates/pptx/src/read/shapes.rs +++ b/crates/pptx/src/read/shapes.rs @@ -805,6 +805,7 @@ fn cell(imp: &mut Imp, part: &Part, tc: &El) -> Cell { ]); } c.anchor = pr.attr("anchor").and_then(Anchor::from_xml); + c.anchor_ctr = pr.bool("anchorCtr"); c.vertical = pr.attr("vert").and_then(TextDir::from_xml); for (i, n) in ["lnL", "lnR", "lnT", "lnB"].iter().enumerate() { if let Some(ln) = pr.child(n) diff --git a/crates/pptx/src/write/shapes.rs b/crates/pptx/src/write/shapes.rs index 87200a890..58af6ef75 100644 --- a/crates/pptx/src/write/shapes.rs +++ b/crates/pptx/src/write/shapes.rs @@ -746,6 +746,7 @@ fn table(w: &mut W, x: &mut Exp, o: &mut Out, t: &Table) { other => other.xml(), }), ); + a = a.b("anchorCtr", c.anchor_ctr); w.open("a:tcPr", a); for (tag, l) in [ ("a:lnL", &c.borders[0]), diff --git a/crates/pptx/tests/it/roundtrip.rs b/crates/pptx/tests/it/roundtrip.rs index 1ed97f546..95c349c93 100644 --- a/crates/pptx/tests/it/roundtrip.rs +++ b/crates/pptx/tests/it/roundtrip.rs @@ -468,6 +468,24 @@ fn text_and_formatting_round_trip() { assert_eq!(run.text, "x=1"); } +#[test] +fn centered_cell_anchor_survives_two_pptx_round_trips() { + let mut p = Presentation::default(); + let mut slide = new_slide(&mut p, "Cell anchor"); + let mut table_shape = shape(&mut p, "Table", 10.0, 10.0, 200.0, 80.0); + let mut table = Table::new(1, 1, 200.0, 80.0); + table.rows[0].cells[0].anchor_ctr = Some(true); + table_shape.kind = ShapeKind::Table(table); + slide.shapes.push(table_shape); + p.slides.push(Arc::new(slide)); + + let once = round(&p); + let twice = round(&once); + let slide = twice.slides.last().expect("added slide"); + let ShapeKind::Table(table) = &by_name(slide, "Table").kind else { panic!("table") }; + assert_eq!(table.rows[0].cells[0].anchor_ctr, Some(true)); +} + #[test] fn shapes_fills_lines_effects_round_trip() { let p = rich_deck();