Keep dimension text rotation when saving DXF (#78) (#153)

This commit is contained in:
MarekSpodBiedry 2026-10-10 18:26:11 +02:00 committed by GitHub
parent 3e0de7e4eb
commit 882c4d67a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -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<Entity> {
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,

View File

@ -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:?}");
}