diff --git a/crates/docx/src/read/chart/plot.rs b/crates/docx/src/read/chart/plot.rs index 255b1c671..901aa9a50 100644 --- a/crates/docx/src/read/chart/plot.rs +++ b/crates/docx/src/read/chart/plot.rs @@ -212,7 +212,8 @@ fn title_left(c: &Chart, cat_on: bool, val_on: bool, area_w: f32) -> f32 { fn flat_title_lines(c: &Chart, area_w: f32) -> Option> { let left = if c.horizontal { &c.cat } else { &c.val }; let r = left.title_rot?.rem_euclid(360.0); - if !(r < 1.0 || r > 359.0) { + // Only near-zero rotations fit the horizontal strip; non-finite rotations do not. + if !r.is_finite() || (1.0..=359.0).contains(&r) { return None; } let width = if area_w.is_finite() { (area_w * 0.18).max(1.0) } else { 1.0 }; diff --git a/crates/docx/src/read/chart/tests.rs b/crates/docx/src/read/chart/tests.rs index d785d4400..1aeab5235 100644 --- a/crates/docx/src/read/chart/tests.rs +++ b/crates/docx/src/read/chart/tests.rs @@ -745,6 +745,11 @@ fn value_axis_title_turns_counter_clockwise_like_word() { assert_eq!(angle(&line_with("", &title(r#""#))), Some(90.0)); // A horizontal title (`rot="0"`) stays horizontal: the plot makes room for it (see below). assert_eq!(angle(&line_with("", &title(r#""#))), Some(0.0)); + // The horizontal tolerance excludes both boundary angles and keeps equivalent full turns. + for (rot, expected) in [(30000, 0.0), (-30000, 0.0), (60000, -90.0), (-60000, -90.0), (10800000, -90.0), (21600000, 0.0)] { + let body = format!(r#""#); + assert_eq!(angle(&line_with("", &title(&body))), Some(expected), "rotation {rot}"); + } // Hostile values stay finite. let odd = angle(&line_with("", &title(r#""#))); assert!(odd.is_some_and(f32::is_finite));