Fields: table cells keep stored values, UPDATEFIELD reaches blocks and tables, measured shading box

Table cell fields show their stored value; only formula cells evaluate
live. UPDATEFIELD on a block reference also updates the fields of its
block definition, and on a table the fields of its cells; a changed
table cell text redraws the table. The FIELDDISPLAY box is placed from
the text layout (MTEXT layout cells, TEXT / attribute pen advances) and
spans 0.345 text heights below the baseline to 1.19 above it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ramox81andClaude Opus 5.5 committed 2026-10-06 12:25:24 +03:00
1 parent 1c242eb489
commit 383eba14e5
8 files changed
+134 -95

No files matched your search

+4 -6
View File
@@ -110,12 +110,10 @@ pub fn update_fields(
document.update_fields(&OcsFieldContext(Some(&snapshot)), event, hosts)
}
pub fn resolve_handle(
document: &CadDocument,
field: Handle,
host: Handle,
) -> Option<String> {
codec::fields::resolve_handle(document, field, host, &OcsFieldContext(Some(document)))
/// The text a table cell shows for its field: a formula is evaluated live
/// (it reads other cells), any other field shows its stored value.
pub fn cell_text(document: &CadDocument, field: Handle, table: Handle) -> Option<String> {
codec::fields::cell_field_text(document, field, table, &OcsFieldContext(Some(document)))
}
/// Evaluate one field code (`\AcVar Date \f "yyyy-MM-dd"`, or the `%<…>%`
+1 -1
View File
@@ -646,7 +646,7 @@ fn content_display_value(
) -> String {
if let Some(handle) = content.field_handle {
if let Some(value) =
crate::entities::field::resolve_handle(document, handle, table.common.handle)
crate::entities::field::cell_text(document, handle, table.common.handle)
{
return value;
}
+21 -10
View File
@@ -488,18 +488,29 @@ fn font_stem(name: &str) -> String {
.to_string()
}
/// How many inked glyphs (non-blank characters, stacked parts included) an
/// MTEXT string draws, in drawing order: the index of the first glyph of
/// what follows `s` in a longer string.
pub fn mtext_glyph_count(s: &str) -> usize {
let ink = |t: &str| t.chars().filter(|c| !c.is_whitespace()).count();
/// The visible-character offset that follows the MTEXT string `s` — the
/// `vis` index [`layout_mtext`]'s glyph boxes give the first character of
/// whatever comes after `s` in a longer string: every laid-out character,
/// a tab or stack slot, and one per paragraph break.
pub fn mtext_visible_count(s: &str) -> usize {
adapt_mtext_paragraphs(s, 1.0, false)
.iter()
.flat_map(|line| &line.runs)
.map(|run| match &run.kind {
MTextRunKind::Glyphs(text) => ink(text),
MTextRunKind::Tab => 0,
MTextRunKind::Stack { numerator, denominator, .. } => ink(numerator) + ink(denominator),
.enumerate()
.map(|(i, para)| {
usize::from(i > 0)
+ para
.runs
.iter()
.map(|run| match &run.kind {
MTextRunKind::Glyphs(text) => text.chars().count(),
MTextRunKind::Tab => 1,
MTextRunKind::Stack { numerator, denominator, .. } => {
numerator.chars().count()
+ denominator.chars().count()
+ usize::from(!denominator.is_empty())
}
})
.sum::<usize>()
})
.sum()
}