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 <noreply@anthropic.com>
This commit is contained in:
parent
3d761bdcd3
commit
2bc5c2a686
2 changed files with 23 additions and 2 deletions
|
|
@ -75,7 +75,10 @@ impl OpenCADStudio {
|
||||||
);
|
);
|
||||||
return Some(Task::none());
|
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() {
|
let text_align = match opt.as_str() {
|
||||||
"L" | "LEFT" | "TL" | "ML" | "BL" => Some(TH::Left),
|
"L" | "LEFT" | "TL" | "ML" | "BL" => Some(TH::Left),
|
||||||
"C" | "CENTER" | "TC" | "BC" => Some(TH::Center),
|
"C" | "CENTER" | "TC" | "BC" => Some(TH::Center),
|
||||||
|
|
@ -85,6 +88,15 @@ impl OpenCADStudio {
|
||||||
"F" | "FIT" => Some(TH::Fit),
|
"F" | "FIT" => Some(TH::Fit),
|
||||||
_ => None,
|
_ => 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() {
|
let mtext_ap = match opt.as_str() {
|
||||||
"TL" => Some(AP::TopLeft),
|
"TL" => Some(AP::TopLeft),
|
||||||
"TC" => Some(AP::TopCenter),
|
"TC" => Some(AP::TopCenter),
|
||||||
|
|
@ -113,8 +125,17 @@ impl OpenCADStudio {
|
||||||
{
|
{
|
||||||
match e {
|
match e {
|
||||||
acadrust::EntityType::Text(t) => {
|
acadrust::EntityType::Text(t) => {
|
||||||
|
let mut changed = false;
|
||||||
if let Some(a) = text_align {
|
if let Some(a) = text_align {
|
||||||
t.horizontal_alignment = a;
|
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;
|
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!(
|
let needs_alignment_point = !matches!(
|
||||||
(t.horizontal_alignment, t.vertical_alignment),
|
(t.horizontal_alignment, t.vertical_alignment),
|
||||||
(HA::Left, VA::Baseline)
|
(HA::Left, VA::Baseline)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue