forked from 1b-agent/opencadstudio-upstream
feat(mtext): evaluate dynamic text fields at render time
Re-evaluate AcDbField-driven MTEXT — date/login/document-property fields, table formulas and object properties — against the current system instead of showing the frozen last-save cache. The evaluation engine lives in `acadrust::fields`; OCS supplies only the environment (system clock, OS login, env vars) through a FieldContext implementation, and hooks the resolved text into MTEXT rendering, falling back to the cached value for anything it can't evaluate. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
b30f9b9741
commit
1b6a3a6f5b
4 files changed
+83
-3
No files matched your search
+10
-2
@@ -71,6 +71,12 @@ fn drawing_dir_str(d: &DrawingDirection) -> &'static str {
|
||||
/// Per-visible-character world-space boxes for the MText editor's
|
||||
/// click-to-select preview. Uses the exact same layout opts as `to_truck`
|
||||
/// so the boxes line up with the rendered glyphs.
|
||||
/// The MTEXT string to render: the live re-evaluated value when the entity
|
||||
/// hosts a dynamic field, otherwise its stored (cached) value.
|
||||
fn display_value(t: &MText, document: &acadrust::CadDocument) -> String {
|
||||
crate::entities::field::resolve(document, t.common.handle).unwrap_or_else(|| t.value.clone())
|
||||
}
|
||||
|
||||
pub fn glyph_boxes(t: &MText, document: &acadrust::CadDocument) -> Vec<GlyphBox> {
|
||||
let resolved_style = resolve_text_style(&t.style, document);
|
||||
let attach_h_anchor: f32 = match t.attachment_point {
|
||||
@@ -98,8 +104,9 @@ pub fn glyph_boxes(t: &MText, document: &acadrust::CadDocument) -> Vec<GlyphBox>
|
||||
} else {
|
||||
t.rotation as f32
|
||||
};
|
||||
let display = display_value(t, document);
|
||||
let layout = layout_mtext(&MTextRenderOpts {
|
||||
value: &t.value,
|
||||
value: &display,
|
||||
insertion: [
|
||||
t.insertion_point.x,
|
||||
t.insertion_point.y,
|
||||
@@ -146,8 +153,9 @@ fn to_truck(t: &MText, document: &acadrust::CadDocument) -> TruckEntity {
|
||||
} else {
|
||||
t.rotation as f32
|
||||
};
|
||||
let display = display_value(t, document);
|
||||
let layout = layout_mtext(&MTextRenderOpts {
|
||||
value: &t.value,
|
||||
value: &display,
|
||||
insertion: [
|
||||
t.insertion_point.x,
|
||||
t.insertion_point.y,
|
||||
|
||||
Reference in new issue
Block a user