Skip to content

feat(objects): derive the ACAD_VISUALSTYLE field list from the data-stream boundary and dispatch it on R2010+ - #47

Merged
DrunkOnJava merged 4 commits into
mainfrom
feat/visualstyle-material-field-lists
Aug 30, 2026
Merged

DrunkOnJava merged 4 commits into
mainfrom
feat/visualstyle-material-field-lists

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

VISUALSTYLE was the largest single undispatched class on the corpus (240 records) and MATERIAL the third (30). Both had "partial prefix" decoders that could not satisfy the objects::modern::ObjectStream::finish boundary check, so both stayed Unhandled.

The first thing this PR establishes is that the ODA spec does not describe either object. §20.4 — the object-prescription chapter — runs from 20.4.1 Common Entity Data to 20.4.104 XRECORD and stops. VISUALSTYLE and MATERIAL appear only in §20.3's list of non-fixed class names. The two modules cited §19.6.10 (L6-17) and §19.6.9 (L6-16); no such sections exist, and those citations are withdrawn.

So the field lists here were derived from bytes, against the one thing the format itself guarantees: a record's data fields must end exactly on the first bit of its string stream.

VISUALSTYLE — decoded and dispatched on R2010, R2013 and R2018

Search for a token sequence over B / BS / BL / BD / CMC that lands all 24 VISUALSTYLE records of a file on that bit, requiring every BD to be a plausible double, every CMC true-colour word to carry a real colour-method octet (0xC0…0xC8), and every alternating slot to be a BS flag in 0..=7:

  • arc_2010.dwg → exactly one answer: fixed head (TV description, BS internal style type, BS 2, B internal-use flag) then 28 (value, flag) pairs;
  • arc_2013.dwg → exactly one answer: the same 28 pairs plus 30 more;
  • that R2013 sequence also closes on all 24 records of sample_AC1032.dwg with zero delta.

The (value, flag) pairing is what explains the corpus's bit budgets. A flag of 1 costs 10 bits (BS byte form) and a flag of 0 costs 2, so the records of one file differ only in multiples of 8 — arc_2010.dwg measures 574 / 774 / 782 / 790 / 798 / 806 / 854 / 862 bits — and the three internal styles that carry 0 in every flag (JitterOff, OverhangOff, EdgeColorOff) are exactly the 574-bit ones.

Corroboration from the decoded values, none of which is used by the search:

Check Result
is_internal_use_only (the lone B of the head) false on exactly ten records — 2dWireframe, Wireframe, Hidden, Conceptual, Realistic, Shades of Gray, Sketchy, X-Ray, Shaded with edges, Shaded — which is precisely the set AutoCAD's Visual Styles Manager lists; true on the fourteen it hides
face_opacity 0.6 on every style but X-Ray, which is 0.5
face_mono_color 0xC2FFFFFF everywhere but ColorChange, which is 0xC2808080
edge_crease_angle 179 on Conceptual, 40 on Hidden / Sketchy / Shades of Gray, 1 elsewhere
internal_style_type dense 0..=27 in ship order (Flat=0 … Shaded=27)
description real text on every record — "Flat", "Shaded with edges", "Shades of Gray", … — from the string stream

Descriptions and the per-record second string (strokes_ogs.tif) come from the R2007+ string stream; the previous decoder read TV from the data cursor, i.e. the wrong stream, on every R2007+ file.

R2004 / R2007 decline rather than guess. Those records store the same styles without the per-property flags and with a different property count (measured: 492–580 data bits vs R2010's 574–862), and no sequence over the same token set lands their 24 records on the RL object-data-size boundary. decode_object returns Error::Unsupported there. The dispatcher now maps an Unsupported from an object-class decoder to Unhandled rather than Error — "this release's layout is not determined" is not a broken record.

MATERIAL — field list withdrawn, strings and budget kept

The previous prefix (BL ambient_color_method, BS ambient_color, BD ambient_color_factor, …) was wrong from its first field. On arc_2004.dwg handle 17 — the ByLayer material, whose two TVs occupy body bits 0..76 — it decodes ambient_color_method = 542113793 and ambient_color = 17728, then eight consecutive BD = 1.0.

objects::acad_material::read_strings now returns only what the bytes prove:

File Records Data-field budget Strings
arc_2004.dwg ByLayer / ByBlock / Global 1264 bits after the two inline TVs, identical in all three 2, inline
arc_2010.dwg same three 1284 bits, bit-identical in all three 2
arc_2013.dwg same three 1284 bits, bit-identical to R2010 2
sample_AC1032.dwg same three 516 / 516 / 1028 bits 7

Documented but not implemented, per the honesty rule: twelve BD slots decode to exactly 1/48 (0.0208333…) at data-stream bits 46, 120, 250, 324, 510, 584, 706, 780, 900, 974, 1096, 1170 — six pairs, one per texture map, 74 bits apart; the R2018 Global record shows four such pairs each bracketed by CMC words 0xC1000000 / 0xC2040300; and its seven string-stream entries (name + six empties) corroborate six map slots. The gaps between pairs are 204 / 260 / 196 / 194 / 196 bits, so no single repeating block layout is pinned. MATERIAL therefore stays undispatched and its 30 records stay Unhandled.

Measured coverage

cargo run --release --example coverage_report -- <19-file samples dir>, before = 0914187 (post-#41):

Corpus slice Before After
R2004 (AC1018) × 3 489 / 108 / 0 / 81.9 % 489 / 108 / 0 / 81.9 %
R2010 (AC1024) × 3 438 / 105 / 0 / 80.7 % 510 / 33 / 0 / 93.9 %
R2013 (AC1027) × 3 291 / 105 / 0 / 73.5 % 363 / 33 / 0 / 91.7 %
R2018 (AC1032) × 1 533 / 166 / 46 / 71.5 % 557 / 142 / 46 / 74.8 %
Aggregate 1751 / 484 / 46 / 76.8 % 1919 / 316 / 46 / 84.1 %

168 of the 240 VISUALSTYLE records now decode; the 72 on the three R2004 files are the remainder. Error count is unchanged at 46.

Top remaining unhandled classes after this PR: VISUALSTYLE-on-R2004 (72), LAYOUT (31), MATERIAL (30), ACDBDETAILVIEWSTYLE (11), ACDBSECTIONVIEWSTYLE (11), MLEADERSTYLE (11), MLINESTYLE (10), TABLESTYLE (10).

Tests

Five BitWriter-built unit tests in objects::acad_visual_style, two in objects::acad_material:

  • an R2018 record with both strings and the 30-property tail closes on its string stream and decodes its description, colours and flags;
  • an R2010 record has no tail and 28 flags;
  • an R2013-length body fed to the R2010 field list is rejected, and an R2010-length body fed to the R2013 field list is rejected — the tail is not optional in either direction;
  • pre-R2010 returns Unsupported;
  • MATERIAL reads its names from the string stream on R2018 (five extra empty map slots) and from the data cursor on R2004, with the budget matching in both.

Full suite: 696 lib + 100 integration, all green.

New tooling

examples/probe_field_list.rs — measures one candidate field list against one real record and prints each field's offset, width and value plus the delta from the boundary. delta 0 is the only result that means the list is right.

cargo run --release --example probe_field_list -- samples/arc_2010.dwg 42 BS,BS,B,BS,BS,BD,BD

examples/dump_decoded_entities.rs gained a VISUALSTYLE arm.

Spec sections

  • ODA v5.4.1 §20.3 — non-fixed object type table (the only place VISUALSTYLE and MATERIAL appear).
  • ODA v5.4.1 §20.4 — object prescriptions; verified to contain no entry for either object.
  • ODA v5.4.1 §19.1 / §19.4.2 — object prologue, string stream, common object data (the boundary this PR relies on).
  • ODA v5.4.1 §2.11 — the CMC colour form, as already read by tables::modern::read_cmc_full for VIEW / VPORT.

Source provenance

Clean-room declaration. I certify that:

  1. All code and tests in this PR were written from scratch by me.
  2. I consulted only sources listed as allowed in CLEANROOM.md. In particular I did not consult Autodesk SDK source, ODA SDK (Drawings SDK / Teigha) source, LibreDWG source, decompilations of Autodesk or ODA binaries, or any copyleft-licensed DWG implementation code.
  3. Citations are in the diff as module comments and in ARCHITECTURE.md §7d.1.
  4. I have never had access to any forbidden source in a commercial or NDA'd context.

Two disclosures beyond the boilerplate, both about naming rather than layout:

  • Every field type, width and order in this PR came from first-party byte measurement of the publicly-redistributable nextgis/dwg_samples files, using the boundary check as the arbiter. No external implementation was read.
  • The names attached to the VISUALSTYLE property slots follow the conventional AcDbVisualStyle property ordering as published in Autodesk's public DXF Reference (official public documentation, not SDK source, and not a leaked or unofficial document). This was recall, not a consulted file, and it was used only to label slots whose layout the bytes had already fixed. The module doc says so explicitly: the face-group names are independently corroborated by the decoded values, the edge and display group names are positional and are not corroborated by this crate. If a reviewer would rather those slots stayed unnamed, say so and I will demote them to a positional Vec like the R2013 tail already is.

Not closing #38

Closes #38 is deliberately omitted. The issue covers VISUALSTYLE, MATERIAL and PROPERTYSET_DATA; only VISUALSTYLE fully decodes, and only on R2010+. Remaining: VISUALSTYLE on R2004/R2007 (72 records), MATERIAL's per-map block layout (30 records), PROPERTYSET_DATA (0 records on this corpus).

https://claude.ai/code/session_01BaHKf1Rw5aJBGK5y3xmx7C


Note

Medium Risk
Large new binary decoder and dispatcher behavior change (Unsupported → Unhandled); AcadMaterial API shrinks and no longer pretends to decode data fields.

Overview
Adds a boundary-validated ACAD_VISUALSTYLE decoder for R2010, R2013, and R2018: field order was derived by searching token sequences that land every record on the string-stream start bit (28 (value, flag) pairs on R2010, plus 30 more on R2013+). Records wire through objects::modern, expose a new DecodedEntity::VisualStyle, and route from custom-class dispatch for VISUALSTYLE / ACDBVISUALSTYLE. R2004/R2007 return Error::Unsupported; the dispatcher now maps that to Unhandled instead of Error so undetermined layouts are not counted as broken records.

ACAD_MATERIAL drops the incorrect prefix decoder and only exposes read_strings (name, description, extra string-stream slots, measured data_field_bits). MATERIAL stays undispatched; corpus coverage rises mainly from VISUALSTYLE (aggregate 76.8% → 84.1% on the 19-file set).

New examples/probe_field_list.rs probes candidate field lists against one object handle; dump_decoded_entities prints VISUALSTYLE fields. Docs (ARCHITECTURE.md §7d.1, changelog, README/STATUS) and withdrawn bogus ODA §19.6 citations for VISUALSTYLE/MATERIAL are updated.

Reviewed by Cursor Bugbot for commit c50fab6. Configure here.

…tream boundary and dispatch it on R2010+

The ODA v5.4.1 object-prescription chapter §20.4 stops at XRECORD and
carries no entry for VISUALSTYLE or MATERIAL; both modules cited
sections (§19.6.10, §19.6.9) that do not exist. The field list here was
derived instead from the boundary the format itself provides: searching
for one token sequence over B/BS/BL/BD/CMC that lands all 24
VISUALSTYLE records of a file exactly on its string-stream start bit
returns exactly one answer per release band — a fixed head plus 28
(value, flag) pairs on R2010, the same 28 plus 30 more on R2013, which
also closes on all 24 R2018 records.

R2004 and R2007 store the same styles without the per-property flags
and with a different property count; no sequence lands their records on
the RL object-data-size boundary, so those bands return
Error::Unsupported and the dispatcher now maps an Unsupported from an
object-class decoder to Unhandled rather than Error.

ACAD_MATERIAL withdraws its previous field list, which was wrong from
its first field, and keeps only what the bytes prove: the strings (now
read from the R2007+ string stream instead of inline) and the measured
data-field budget. It stays undispatched.

Measured on the 19-file corpus: 1751 / 484 / 46 / 76.8 % → 1919 / 316 /
46 / 84.1 %.

Refs #38
@cursor

cursor Bot commented Aug 30, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_04fd7ede-c49a-4079-a392-e85f002bcfd3)

…rial-field-lists

# Conflicts:
#	CHANGELOG.md
#	README.md
#	STATUS.md
@DrunkOnJava
DrunkOnJava merged commit f706937 into main Aug 30, 2026
19 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/visualstyle-material-field-lists branch August 30, 2026 17:04
DrunkOnJava added a commit that referenced this pull request Aug 30, 2026
…ch it on R2004 and R2010+ (#52)

* feat(objects): derive the ACAD_VISUALSTYLE field list from the data-stream boundary and dispatch it on R2010+

The ODA v5.4.1 object-prescription chapter §20.4 stops at XRECORD and
carries no entry for VISUALSTYLE or MATERIAL; both modules cited
sections (§19.6.10, §19.6.9) that do not exist. The field list here was
derived instead from the boundary the format itself provides: searching
for one token sequence over B/BS/BL/BD/CMC that lands all 24
VISUALSTYLE records of a file exactly on its string-stream start bit
returns exactly one answer per release band — a fixed head plus 28
(value, flag) pairs on R2010, the same 28 plus 30 more on R2013, which
also closes on all 24 R2018 records.

R2004 and R2007 store the same styles without the per-property flags
and with a different property count; no sequence lands their records on
the RL object-data-size boundary, so those bands return
Error::Unsupported and the dispatcher now maps an Unsupported from an
object-class decoder to Unhandled rather than Error.

ACAD_MATERIAL withdraws its previous field list, which was wrong from
its first field, and keeps only what the bytes prove: the strings (now
read from the R2007+ string stream instead of inline) and the measured
data-field budget. It stays undispatched.

Measured on the 19-file corpus: 1751 / 484 / 46 / 76.8 % → 1919 / 316 /
46 / 84.1 %.

Refs #38

* docs(cleanroom): disclose the public DXF Reference as the source of VISUALSTYLE slot names

* feat(objects): derive the LAYOUT + PLOTSETTINGS field list and dispatch it on R2004 and R2010+

wip

* feat(objects): derive the LAYOUT + PLOTSETTINGS field list and dispatch it on R2004 and R2010+

LAYOUT was the largest undispatched non-entity class after #47 — 31
records across the corpus, all Unhandled. Unlike VISUALSTYLE, the spec
does prescribe it: §20.4.84 opens with the whole plot-settings block
(every row glossed "plotsettings ...") and continues into LAYOUT's own
fields. What the crate carried was neither — acad_layout cited a
"§19.6.12 (L6-12)" that does not exist (there is no §19.6 chapter) and
listed a field order missing the six margin/paper BDs, the paper-size
TV and the shade-plot triple; acad_plot_settings cited "§19.6.6
(L6-14)" and modelled three of the five TVs. Both citations and both
field lists are withdrawn and replaced by one shared implementation.

Read straight and measured against the data-stream boundary, §20.4.84
closes every record on four release bands at once: 9 on the R2004
files (inline TVs, RL boundary), 9 on R2010, 9 on R2013 and 4 on
sample_AC1032.dwg, delta 0 with no bits to spare. The boundary then
catches the two places the prescription and the bytes disagree:

- viewport_count is a BL, not the RL §20.4.84 prints. On handle 89 of
  sample_AC1032.dwg it starts 10 bits before the string-stream start —
  an RL cannot fit, a BL in its 8-bit form is exactly 10 bits and
  decodes 2. The 28 records with no viewport spend 2 bits there.
- The R2013+ has_ds_binary_data flag carries 16 further bits. The spec
  gives only the B; objects::modern consumed a single RC after it, an
  unvalidated guess no record had reached. Four corpus records set the
  bit — the four LAYOUTs of sample_AC1032.dwg, against 327 that clear
  it — and all four close only with 16 bits consumed, first byte 0x2C
  on every one. The alternative reading is recorded, not hidden.

Corroboration from the values: paper size matches its own name string
(215.9x279.4 mm for ANSI_A, 210x297 for A4), margins 6.35 mm on the
none_device records, paper limits equal to the sheet less those margins
in inches, (1,0,0)/(0,1,0) UCS axes on all 31, AutoCAD's +/-1e20
uninitialised-extents sentinel on the empty layouts, and scale_factor =
real_world_units / drawing_units everywhere.

Pre-R2004 and R2007 decline with Error::Unsupported rather than guess.

Measured on the 19-file corpus: 1923 / 319 / 39 / 84.3 % → 1954 / 288 /
39 / 85.7 %.

Closes #50
Closes #39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant