forked from 1b-agent/opencadstudio-upstream
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 <[email protected]>
This commit is contained in:
1 parent
3d761bdcd3
commit
2bc5c2a686
2 files changed
+23
-2
No files matched your search
+22
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user