From 20447554188cd7bfe1c31f823e9cdd64fbb06e69 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Wed, 10 Jun 2026 19:17:07 +0300 Subject: [PATCH] feat(styles): read current table/multileader style from DWG too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DWG has no header field for the current table / multileader style — they live in the variable dictionary as DICTIONARYVAR entries keyed CTABLESTYLE / CMLEADERSTYLE. Resolve them on load via the document's dictionaries and set the header names, so the green ✓ marks the right style for DWG files as well (DXF already worked via the header vars). A missing entry leaves the value untouched, so there is no risk to the binary header parse. Co-Authored-By: Claude Opus 4.8 --- src/io/mod.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/io/mod.rs b/src/io/mod.rs index 2c7e5c9de..89ab29d5b 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -267,6 +267,44 @@ fn fix_current_style_names(doc: &mut CadDocument) { doc.header.multiline_style = name; } } + + // Current table / multileader style. DXF carries these as $CTABLESTYLE / + // $CMLEADERSTYLE header vars (already read). DWG has no header field for + // them — they live in the variable dictionary as DICTIONARYVAR entries + // keyed "CTABLESTYLE" / "CMLEADERSTYLE". Resolve from there when present; + // a missing entry simply leaves the existing value untouched. + if let Some(v) = vardict_value(doc, "CTABLESTYLE") { + if !v.is_empty() { + doc.header.current_table_style_name = v; + } + } + if let Some(v) = vardict_value(doc, "CMLEADERSTYLE") { + if !v.is_empty() { + doc.header.current_mleader_style_name = v; + } + } +} + +/// Look up a system-variable value stored in the document's variable +/// dictionary: find the dictionary entry whose key matches `name`, then read +/// the `DictionaryVariable` it points at. +fn vardict_value(doc: &CadDocument, name: &str) -> Option { + use acadrust::objects::ObjectType; + let handle = doc.objects.values().find_map(|o| { + let entries = match o { + ObjectType::Dictionary(d) => &d.entries, + ObjectType::DictionaryWithDefault(d) => &d.entries, + _ => return None, + }; + entries + .iter() + .find(|(k, _)| k.eq_ignore_ascii_case(name)) + .map(|(_, h)| *h) + })?; + match doc.objects.get(&handle) { + Some(ObjectType::DictionaryVariable(v)) => Some(v.value.clone()), + _ => None, + } } // ── Corrupt-entity guard ──────────────────────────────────────────────────