From 882c4d67a6bdc0e48105bf4b13572dff7d0ab4eb Mon Sep 17 00:00:00 2001 From: MarekSpodBiedry <73122968+MarekSpodBiedry@users.noreply.github.com> Date: Sat, 10 Oct 2026 18:26:11 +0200 Subject: [PATCH] Keep dimension text rotation when saving DXF (#78) (#153) --- crates/io/src/dxf_write.rs | 5 ++++- crates/io/src/tests.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/io/src/dxf_write.rs b/crates/io/src/dxf_write.rs index a145103..0650a51 100644 --- a/crates/io/src/dxf_write.rs +++ b/crates/io/src/dxf_write.rs @@ -562,6 +562,9 @@ fn entity(w: &mut W, d: &Drawing, e: &Entity, owner: &str, paper: bool, cx: &Ctx w.s(1, &dm.text); } w.s(3, &dm.style); + if dm.text_rotation != 0.0 { + w.f(53, dm.text_rotation.to_degrees()); + } match dm.kind { DimKind::Linear { rotation } => { w.s(100, "AcDbAlignedDimension"); @@ -819,7 +822,7 @@ fn dim_block_entities(d: &Drawing, dm: &Dimension, layer: &str) -> Vec { height: style.text_height * style.scale.max(1e-9), width: 0.0, attach: 5, - rotation: 0.0, + rotation: g.text_angle, style: style.text_style.clone(), contents: g.value.clone(), line_spacing: 1.0, diff --git a/crates/io/src/tests.rs b/crates/io/src/tests.rs index 48ababa..9f11318 100644 --- a/crates/io/src/tests.rs +++ b/crates/io/src/tests.rs @@ -1272,3 +1272,18 @@ fn attdef_prompt_survives_dxf_roundtrip() { .collect(); assert_eq!(prompts, vec!["Enter value", ""]); } + +#[test] +fn dimension_text_rotation_roundtrips() { + let mut d = Drawing::new_imperial(); + let mut dm = dim(DimKind::Linear { rotation: 0.0 }, Vec3::ZERO, Vec3::new(10.0, 0.0, 0.0)); + dm.text_rotation = 30.0_f64.to_radians(); + let h = d.add(&Space::Model, Common::default(), EntityKind::Dimension(dm.clone())).unwrap(); + let back = roundtrip(&d); + let EntityKind::Dimension(x) = &back.entity(h).unwrap().kind else { panic!("dimension expected") }; + assert!((x.text_rotation - dm.text_rotation).abs() < 1e-9, "got {}", x.text_rotation); + // The anonymous block that renders the reopened dimension carries the same text angle. + let b = x.block.as_deref().and_then(|n| back.block(n)).expect("dimension block"); + let rot = b.entities.iter().find_map(|e| if let EntityKind::MText(t) = &e.kind { Some(t.rotation) } else { None }); + assert!(rot.is_some_and(|r| (r - dm.text_rotation).abs() < 1e-9), "block text rotation {rot:?}"); +}