Repository navigation
feat(objects): derive the LAYOUT + PLOTSETTINGS field list and dispatch it on R2004 and R2010+ - #52
Merged
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
…ISUALSTYLE slot names
…ch it on R2004 and R2010+ wip
# Conflicts: # CHANGELOG.md # README.md # STATUS.md # examples/dump_decoded_entities.rs # src/entities/dispatch.rs # src/objects/mod.rs
…ch 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
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_6ec3c906-2211-4c21-a0a7-67fc227bfd8f) |
This was referenced Aug 30, 2026
This was referenced Aug 30, 2026
Merged
Merged
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
LAYOUT was the largest undispatched non-entity class after #47 — 31 records across the corpus, every one
Unhandled. Unlike VISUALSTYLE, the ODA spec does prescribe it, in one place: §20.4.84 LAYOUT opens with the complete plot-settings block (every row glossedplotsettings …) and continues into LAYOUT's own fields. There is no separate §20.4 PLOTSETTINGS entry, and no §19.6 chapter at all.What this tree carried was neither.
acad_layoutcited a "§19.6.12 (L6-12)" that does not exist and listed a field order missing the six margin/paperBDs, the paper-sizeTVand the shade-plot triple;acad_plot_settingscited "§19.6.6 (L6-14)" and modelled three of the fiveTVs. Both citations and both field lists are withdrawn, replaced by one shared implementation (acad_plot_settings::read_fields) that LAYOUT and a standalone PLOTSETTINGS record both go through, so the two cannot drift apart.Read straight and measured against the boundary, §20.4.84 closes every record on four release bands at once — no band declines.
The derived field list
The handle references §20.4.84 lists after
viewport_countlive in the object's handle stream, past the data-stream boundary, so they are not fields of the data record and the fiveHandlemembersAcadLayoutused to carry are gone.Bit-budget evidence per version
Every record's data fields must end exactly on the first bit of its string stream (R2010+) or on the
RLobject-data-size (R2004).examples/probe_field_list.rsprints the delta;delta 0is the only passing result.RLobj-size, inlineTVsPer-record budgets, from the end of the common object prefix to the boundary:
viewport_countarc_2004.dwgLayout1arc_2004.dwgModelarc_2004.dwgLayout2arc_2010.dwgLayout1/Model/Layout2arc_2013.dwgLayout1/Model/Layout2sample_AC1032.dwgModelsample_AC1032.dwgLayout1/Layout2sample_AC1032.dwgMyLayout(
circle_*andline_*are bit-identical to theirarc_*siblings.)Two places the spec and the bytes disagree
1.
viewport_countis aBL, not theRL§20.4.84 prints. Onsample_AC1032.dwghandle 89 the field starts 10 bits before the string-stream start bit. A 32-bitRLcannot fit; aBLin its 8-bit form is exactly 10 bits and decodes2— the number of viewports that layout owns. The 28 records with no viewport spend 2 bits there, where anRLwould overrun the boundary by 30. A test builds a body with anRLin that slot and asserts the boundary check rejects it.2. The R2013+
has_ds_binary_dataflag carries 16 further bits. The spec's common-object-data table gives only theB.objects::modernconsumed a singleRCafter it — an unvalidated guess that no test or corpus record had ever reached, because until now nothing that set the bit was dispatched. Exactly four non-entity records in the corpus set it — the four LAYOUTs ofsample_AC1032.dwg, against 327 that clear it across the R2013 and R2018 files — and on all four the field list closes only with 16 bits consumed, the first byte0x2Con every one (the second is0x0BonModel,0x00on the three paper layouts). 8 bits leaves each record 8 short of its boundary; 0 bits leaves it 16 short.Two readings fit the corpus: the marker is 16 bits wide, or it is absent and LAYOUT gained two leading bytes in R2018. This PR takes the first — the extra bits appear exactly when the flag is set and not on the R2013 records that clear it, the constant leading
0x2Creads as data-store bookkeeping rather than page-setup state, and the second reading would require §20.4.84 to be wrong at its very first field. Nothing in the corpus separates them outright; a non-LAYOUT record with the bit set would. Both readings are written down insrc/objects/modern.rsrather than one being quietly assumed.Value corroboration
A field list off by a single bit reproduces none of this:
paper_width×paper_heightmatches each record's ownpaper_sizestring:215.9 × 279.4mm forANSI_A_(8.50_x_11.00_Inches)andLetter_(8.50_x_11.00_Inches)(8.5 × 11 in),210 × 297forA4;6.35mm (0.25 in) on thenone_devicerecords,≈4.23mm on theMON-MUR-09-PRINT (HP LaserJet Pro M148fdw)record;limmin/limmaxare the sheet less those margins, in inches:(-0.25, -0.25) … (10.75, 8.25)on Letter,(-0.1667, -0.1667) … (11.526, 8.101)on A4;Modelrecord carries AutoCAD's default(0, 0) … (12, 9); the A3Layout1of the R2004/R2010/R2013 files carries(0, 0) … (420, 297);ucs_x_axisis(1,0,0)anducs_y_axis(0,1,0)on all 31 records;ucs_originis(0,0,0);extent_min/extent_maxhold AutoCAD's+1e20/-1e20uninitialised sentinel on the emptyLayout1records;tab_orderis0on eachModeland1/2/3on the paper tabs, matching thelayout_namestrings;scale_factorequalsreal_world_units / drawing_unitson every record —0.38686283977 = 1 / 2.5848954647on theModelofsample_AC1032.dwg,1 / 1on its paper layouts;shade_plot_custom_dpiis300andshade_plot_resolution_level2on all 31.Versions declined
Per the honesty rule, bands whose layout is not measured return
Error::Unsupported, which the dispatcher maps toUnhandled(neverError):T plot_view_name(6) into the block for those releases and omits the shade-plot triple andviewport_count. Those files have no walkable object stream in this crate (Epic: Trace every ODA spec section #104), so the branch cannot be measured.Measured coverage
examples/coverage_report.rsover the 19-file local corpus, before =f706937(main, after #46 + #47), measured in a clean worktree at that commit:All 31 LAYOUT records decode; LAYOUT drops out of the unhandled histogram entirely. The error count is unchanged at 39 — the
objects::modernprefix change is a no-op for every record that clears the AcDs bit, which is all of them outside these four.API changes
DecodedEntity::Layout(Box<AcadLayout>)andDecodedEntity::PlotSettings(AcadPlotSettings)are new variants (the enum is#[non_exhaustive];Layoutis boxed to keeplarge_enum_variantquiet).AcadLayoutembeds anAcadPlotSettingsand drops its fiveHandlefields.paper_min_limits/paper_max_limits/min_extents/max_extentsare renamed to the spec'slimmin/limmax/extent_min/extent_max;paper_width()/paper_height()becomelimits_width()/limits_height()(paper size proper now lives on the embedded plot settings);has_uninitialised_extents()is new andextents_diagonal()returns0.0for the sentinel.AcadPlotSettingsgains the twelve fields the old list was missing andprintable_width()/printable_height()/custom_scale().acad_layout::decodeandacad_plot_settings::decodeare replaced bydecode_object(payload, body_start, inline_data_end, version), which takes the raw payload so it can reach the string stream.examples/dump_decoded_entities.rsprints LAYOUT and PLOTSETTINGS values.Tests
BitWriter-built R2018 fixtures in both modules: a full split-stream LAYOUT that closes on its string stream (name, tab order, viewport count, UCS axes, limits, and the embedded plot-settings values), a
Modelvariant, a standalone PLOTSETTINGS record, plus four negative tests — anRL-sizedviewport_count, a body missing the plot-settings block, a body one field long, and the declined release bands. Dispatch-level tests cover empty-payload →Errorand undetermined-release →Unhandled.tests/code_table_agreement.rsandtests/dispatch_roundtrip.rsmove0x52from the "no decoder" list to the routed list.Source provenance
Clean-room declaration. I certify that:
CLEANROOM.md— specifically the freely-redistributable ODA Open Design Specification for .dwg files v5.4.1 (§20.4.84 LAYOUT, and the common-object-data table for the R2013+ AcDs flag) and first-party byte inspection of publicly-available DWG sample files. 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.CLEANROOM.mdfor feat(objects): derive the ACAD_VISUALSTYLE field list from the data-stream boundary and dispatch it on R2010+ #47, which had no spec prescription to draw on. The two departures from the spec (viewport_countasBL, the 16-bit AcDs trailer) are derived from the corpus's own data-stream boundary and are documented as measurements in the modules.CLEANROOM.mdcarries a dated entry recording all of the above and withdrawing the two non-existent §19.6.x citations.Closes #50
Closes #39
Note
Medium Risk
Touches shared R2013+ common-object prefix parsing and breaks
AcadLayout/AcadPlotSettingsAPIs, but behavior is gated by boundary checks, corpus validation, and explicit unsupported release bands.Overview
Implements LAYOUT and standalone PLOTSETTINGS using ODA §20.4.84 via a shared
acad_plot_settings::read_fields, with boundary-checkeddecode_objectpaths throughobjects::modern. All 31 corpus LAYOUT records decode on R2004/R2010/R2013/R2018; aggregate coverage rises from 84.3% to 85.7%.Spec vs bytes:
viewport_countis read asBL(not specRL); when R2013+has_ds_binary_datais set,objects::modernnow consumes 16 bits (was oneRC) so R2018 LAYOUTs close on the string-stream boundary.Dispatch/API:
DecodedEntity::Layout/PlotSettings; LAYOUT 0x52 routed indispatch_object; custom PLOTSETTINGS by class name.AcadLayoutembedsAcadPlotSettings, drops data-stream handles, renames limits/extents fields; pre-R2004 and R2007 returnUnsupported→Unhandled.Docs, CLEANROOM, coverage tables,
dump_decoded_entities, and integration tests updated accordingly.Reviewed by Cursor Bugbot for commit 2555331. Configure here.