From 2bc5c2a68634a07284cb8836865174a5a15fe511 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Fri, 3 Jul 2026 09:51:34 +0300 Subject: [PATCH] fix(commands): JUSTIFYTEXT sets vertical alignment for single-line TEXT The Text branch only set horizontal_alignment, so TL/BL/MC etc. never moved the text box vertically. Map the T*/M*/B* codes to Top/Middle/Bottom and re-sync the alignment point. (#246) Co-Authored-By: Claude Opus 4.8 --- src/app/commands/dim.rs | 23 ++++++++++++++++++++++- src/entities/text.rs | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/app/commands/dim.rs b/src/app/commands/dim.rs index 456239f76..acb0744b9 100644 --- a/src/app/commands/dim.rs +++ b/src/app/commands/dim.rs @@ -75,7 +75,10 @@ impl OpenCADStudio { ); return Some(Task::none()); } - use acadrust::entities::{AttachmentPoint as AP, TextHorizontalAlignment as TH}; + use acadrust::entities::{ + AttachmentPoint as AP, TextHorizontalAlignment as TH, + TextVerticalAlignment as TV, + }; let text_align = match opt.as_str() { "L" | "LEFT" | "TL" | "ML" | "BL" => Some(TH::Left), "C" | "CENTER" | "TC" | "BC" => Some(TH::Center), @@ -85,6 +88,15 @@ impl OpenCADStudio { "F" | "FIT" => Some(TH::Fit), _ => None, }; + // Vertical band for single-line TEXT. Bare L/C/R (and Aligned/Fit + // and the special Middle) keep the baseline; the T*/M*/B* codes + // pin the top/middle/bottom of the text box. + let text_valign = match opt.as_str() { + "TL" | "TC" | "TR" => Some(TV::Top), + "ML" | "MC" | "MR" => Some(TV::Middle), + "BL" | "BC" | "BR" => Some(TV::Bottom), + _ => None, + }; let mtext_ap = match opt.as_str() { "TL" => Some(AP::TopLeft), "TC" => Some(AP::TopCenter), @@ -113,8 +125,17 @@ impl OpenCADStudio { { match e { acadrust::EntityType::Text(t) => { + let mut changed = false; if let Some(a) = text_align { t.horizontal_alignment = a; + changed = true; + } + if let Some(v) = text_valign { + t.vertical_alignment = v; + changed = true; + } + if changed { + crate::entities::text::sync_text_alignment_point(t); n += 1; } } diff --git a/src/entities/text.rs b/src/entities/text.rs index 3b5e5ba8c..65135e7eb 100644 --- a/src/entities/text.rs +++ b/src/entities/text.rs @@ -33,7 +33,7 @@ fn text_valign_str(a: &acadrust::entities::TextVerticalAlignment) -> &'static st } } -fn sync_text_alignment_point(t: &mut Text) { +pub(crate) fn sync_text_alignment_point(t: &mut Text) { let needs_alignment_point = !matches!( (t.horizontal_alignment, t.vertical_alignment), (HA::Left, VA::Baseline)