diff --git a/crates/docx/src/read/chart.rs b/crates/docx/src/read/chart.rs index 42c7a311c..4b7696eee 100644 --- a/crates/docx/src/read/chart.rs +++ b/crates/docx/src/read/chart.rs @@ -150,15 +150,12 @@ pub(crate) fn chartex_items(space: Option<&El>, w: f32, h: f32) -> Vec 0.0 && h > 0.0) { return out; } - out.push(GraphicItem::Shape { rect: [0.0, 0.0, w, h], kind: ShapeKind::Rectangle, fill: Some(Rgb::WHITE), stroke: Some(AXIS), stroke_width: 0.75 }); + out.push(GraphicItem::Shape { rect: [0.0, 0.0, w, h], kind: ShapeKind::Rectangle, fill: None, stroke: Some(AXIS), stroke_width: 0.75 }); let mut area = Rect { x: PAD, y: PAD, w: (w - 2.0 * PAD).max(1.0), h: (h - 2.0 * PAD).max(1.0) }; let chart = space.and_then(|s| s.child("cx:chart")); let title = chart.and_then(|c| c.child("cx:title")).and_then(|t| { - let mut s = String::new(); - t.find_all("a:t").for_each(|r| s.push_str(&r.text())); - if s.is_empty() { - s = t.find("cx:v").map(|v| v.text().into_owned()).unwrap_or_default(); - } + // Rich text keeps its runs together ("Sales " + "funnel"); a text-data title is one value. + let s = t.find("cx:rich").or_else(|| t.find("cx:v")).map(|e| e.deep_text()).unwrap_or_default(); let s = label(s.trim()); (!s.is_empty()).then_some(s) }); diff --git a/crates/docx/tests/it/fixtures.rs b/crates/docx/tests/it/fixtures.rs index 295b788b9..5ddfb151f 100644 --- a/crates/docx/tests/it/fixtures.rs +++ b/crates/docx/tests/it/fixtures.rs @@ -1893,7 +1893,10 @@ fn office_2016_chart_with_a_text_fallback_keeps_its_size_through_saves() { assert_eq!((*w, *h), (432.0, 252.0)); assert_eq!((graphic.w, graphic.h), (432.0, 252.0)); assert!( - graphic.items.iter().any(|i| matches!(i, craft_wordmodel::graphic::GraphicItem::Text { text, .. } if text.starts_with("Waterfall chart"))), + graphic + .items + .iter() + .any(|i| matches!(i, craft_wordmodel::graphic::GraphicItem::Text { text, .. } if text.starts_with("Waterfall chart"))), "{:?}", graphic.items ); @@ -1911,13 +1914,12 @@ fn office_2016_chart_with_a_text_fallback_keeps_its_size_through_saves() { } } -/// A fallback that holds a run (not run content) can't be written back inside the object's own -/// run, so it is read as before: its text, no chart object. +/// Guard, not fix proof (it passes before the change too): a fallback that holds a run can't be +/// written back inside the object's own run, so it is not turned into a chart placeholder. #[test] -fn office_2016_chart_with_a_run_fallback_is_read_as_before() { +fn office_2016_chart_with_a_run_fallback_is_not_made_a_placeholder() { let d = craft_docx::read(&chartex_text_fallback_docx("Chart not available.")).unwrap(); - assert!(graphics(&d).is_empty()); - assert!(paras(&d).iter().any(|p| p.text.contains("Chart not available."))); + assert!(graphics(&d).is_empty(), "{:?}", graphics(&d)); } #[test]