Repository navigation
feat(objects): derive the ACAD_VISUALSTYLE field list from the data-stream boundary and dispatch it on R2010+ - #47
Merged
Conversation
…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
Bugbot couldn't run - usage limit reachedBugbot 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) |
…ISUALSTYLE slot names
This was referenced Aug 30, 2026
Open
…rial-field-lists # Conflicts: # CHANGELOG.md # README.md # STATUS.md
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
VISUALSTYLEwas the largest single undispatched class on the corpus (240 records) andMATERIALthe third (30). Both had "partial prefix" decoders that could not satisfy theobjects::modern::ObjectStream::finishboundary check, so both stayedUnhandled.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 Datato20.4.104 XRECORDand stops.VISUALSTYLEandMATERIALappear 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 / CMCthat lands all 24 VISUALSTYLE records of a file on that bit, requiring everyBDto be a plausible double, everyCMCtrue-colour word to carry a real colour-method octet (0xC0…0xC8), and every alternating slot to be aBSflag in0..=7:arc_2010.dwg→ exactly one answer: fixed head (TVdescription,BSinternal style type,BS2,Binternal-use flag) then 28(value, flag)pairs;arc_2013.dwg→ exactly one answer: the same 28 pairs plus 30 more;sample_AC1032.dwgwith zero delta.The
(value, flag)pairing is what explains the corpus's bit budgets. A flag of1costs 10 bits (BSbyte form) and a flag of0costs 2, so the records of one file differ only in multiples of 8 —arc_2010.dwgmeasures 574 / 774 / 782 / 790 / 798 / 806 / 854 / 862 bits — and the three internal styles that carry0in every flag (JitterOff,OverhangOff,EdgeColorOff) are exactly the 574-bit ones.Corroboration from the decoded values, none of which is used by the search:
is_internal_use_only(the loneBof the head)falseon 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;trueon the fourteen it hidesface_opacity0.6on every style butX-Ray, which is0.5face_mono_color0xC2FFFFFFeverywhere butColorChange, which is0xC2808080edge_crease_angle179onConceptual,40onHidden/Sketchy/Shades of Gray,1elsewhereinternal_style_type0..=27in ship order (Flat=0 …Shaded=27)description"Flat","Shaded with edges","Shades of Gray", … — from the string streamDescriptions and the per-record second string (
strokes_ogs.tif) come from the R2007+ string stream; the previous decoder readTVfrom 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
RLobject-data-size boundary.decode_objectreturnsError::Unsupportedthere. The dispatcher now maps anUnsupportedfrom an object-class decoder toUnhandledrather thanError— "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. Onarc_2004.dwghandle 17 — theByLayermaterial, whose twoTVs occupy body bits 0..76 — it decodesambient_color_method = 542113793andambient_color = 17728, then eight consecutiveBD = 1.0.objects::acad_material::read_stringsnow returns only what the bytes prove:arc_2004.dwgByLayer/ByBlock/GlobalTVs, identical in all threearc_2010.dwgarc_2013.dwgsample_AC1032.dwgDocumented but not implemented, per the honesty rule: twelve
BDslots decode to exactly1/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 R2018Globalrecord shows four such pairs each bracketed byCMCwords0xC1000000/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 stayUnhandled.Measured coverage
cargo run --release --example coverage_report -- <19-file samples dir>, before =0914187(post-#41):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 inobjects::acad_material:Unsupported;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 0is the only result that means the list is right.examples/dump_decoded_entities.rsgained a VISUALSTYLE arm.Spec sections
CMCcolour form, as already read bytables::modern::read_cmc_fullfor VIEW / VPORT.Source provenance
Clean-room declaration. I certify that:
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.ARCHITECTURE.md§7d.1.Two disclosures beyond the boilerplate, both about naming rather than layout:
nextgis/dwg_samplesfiles, using the boundary check as the arbiter. No external implementation was read.AcDbVisualStyleproperty 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 positionalVeclike the R2013 tail already is.Not closing #38
Closes #38is 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);AcadMaterialAPI shrinks and no longer pretends to decode data fields.Overview
Adds a boundary-validated
ACAD_VISUALSTYLEdecoder 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 throughobjects::modern, expose a newDecodedEntity::VisualStyle, and route from custom-class dispatch forVISUALSTYLE/ACDBVISUALSTYLE. R2004/R2007 returnError::Unsupported; the dispatcher now maps that toUnhandledinstead ofErrorso 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, measureddata_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.rsprobes candidate field lists against one object handle;dump_decoded_entitiesprints 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.