Files
cadcraft/crates/engine/tests/text_left_justify.rs
Valentin KleinandClaude Opus 5.5 71706f8e6a TL/ML/BL text is placed by its alignment point (fixes #342) (#346)
For every justification but baseline-left (and aligned/fit) the DXF
Reference makes group 11 the point the text is placed by; group 10 is a
computed point on the baseline. Left-justified text with a vertical
alignment was drawn, measured and picked from group 10 and then shifted
by the alignment again: TL and ML too low, BL too high. The renderer
(fonts::place) and text extents (doc text_box, used for picking) now
place it from the alignment point; a mirrored (extrusion 0,0,-1) TL/ML/BL
text keeps its alignment point when it turns right-justified; and the
Properties position moves justified text by its alignment point.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 17:31:56 -04:00

18 lines
859 B
Rust

//! Properties moves justified TEXT by its alignment point: a TL text (placed by its alignment
//! point, #342) lands where its new position says.
use cadcraft_engine::Session;
use cadcraft_engine::doc::{EntityKind, entity_bounds};
use serde_json::json;
#[test]
fn moving_top_left_text_through_properties_moves_it() {
let mut s = Session::new();
let r = s.execute("text", &json!({ "at": [5, 5], "text": "TL", "height": 1, "justify": "TL" })).unwrap();
let h = r["handle"].as_str().unwrap().to_string();
s.execute("properties.set", &json!({ "handles": [h], "position": [20, 20] })).unwrap();
let d = s.doc().unwrap();
let b = d.model.iter().find_map(|e| matches!(e.kind, EntityKind::Text(_)).then(|| entity_bounds(d, e, 0))).unwrap();
assert!((b.max.y - 20.0).abs() < 1e-9 && (b.min.x - 20.0).abs() < 1e-9, "moved text {b:?}");
}