Skip to content

feat(objects): decode VISUALSTYLE on R2004 — the flag-less generation (72 records, 92.0% → 95.0%) - #64

Merged
DrunkOnJava merged 2 commits into
mainfrom
feat/visualstyle-r2004-r2007
Aug 30, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
feat/visualstyle-r2004-r2007

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Closes the R2004 half of #48: VISUALSTYLE now dispatches on AC1018,
taking all 72 of its corpus records — the largest remaining
Unhandled block. The R2007 half stays open, and the reason is upstream
rather than this object (see below).

Measured coverage

cargo run --release --example coverage_report -- <samples>, re-run on
the merged tree (origin/main is 7418d25; nothing moved under it
during this work, so the merge was a no-op).

Version Decoded Skipped Errored Ratio
R2004 (AC1018) 510 → 582 87 → 15 0 → 0 85.4 % → 97.5 %
R2010 (AC1024) 531 → 531 12 → 12 0 → 0 97.8 %
R2013 (AC1027) 384 → 384 12 → 12 0 → 0 97.0 %
R2018 (AC1032) 762 → 762 80 → 80 0 → 0 90.5 %
Aggregate 2187 → 2259 191 → 119 0 → 0 92.0 % → 95.0 %

Per-file: arc_2004.dwg, circle_2004.dwg and line_2004.dwg each go
170 / 29 / 0 → 194 / 5 / 0. Zero errors corpus-wide is preserved, and
VISUALSTYLE now reaches 240 of the 240 records the class census
declares across the walkable files.

The R2004 layout

30 fields, no (value, flag) pairs, one fewer property than R2010, and
a different order. Delta 0 on all 24 records of all three *_2004.dwg
files.

TV   description                  -- inline on R2004
BS   internal_style_type          BS  face_lighting_model
BS   face_lighting_quality        BS  face_color_mode
BD   face_opacity                 BD  face_specular
CMC  face_mono_color              BS  face_modifier
BS   edge_model                   BS  edge_style
CMC  edge_intersection_color      CMC edge_obscured_color
BS   edge_obscured_linetype       BD  edge_crease_angle
BS   edge_modifier                CMC edge_color
BD   edge_opacity                 BS  edge_width
BS   edge_overhang                BS  edge_jitter
CMC  edge_silhouette_color        BS  edge_silhouette_width
RC   edge_unknown_byte            BS  edge_halo_gap
B    edge_hide_precision          BS  edge_isoline_count
BS   edge_intersection_linetype   BS  edge_style_apply
BL   display_brightness           BS  display_shadow_type
B    is_internal_use_only

Three slots of the R2010 head are gone or moved: there is no
format_version at all, face_modifier sits after face_mono_color,
and is_internal_use_only is the record's last bit.

Bit evidence

Both ends anchored from the record's own redundancy. At the front,
examples/probe_token_scan.rs reports the self-identifying tokens —
full-form BDs that decode to short decimals and CMCs whose
true-colour word carries a real method octet — which pin face_opacity
(bit 435 on arc_2004.dwg handle 42), face_specular (501) and
face_mono_color (567). Neither pattern survives a one-bit shift.

At the back, a reverse scan for the offset at which BS, BL, BS, B
lands exactly on the RL object-data-size boundary returns exactly
one
position on every one of the 24 records, and its four values
reproduce R2010's edge_style_apply (13 on Flat/FlatWithEdges/
Gouraud/GouraudWithEdges/Realistic/X-Ray, 5 on the two Shaded styles,
1 elsewhere), display_shadow_type (0) and is_internal_use_only.
That last bit splits the 24 styles into precisely the ten AutoCAD's
Visual Styles Manager lists and the fourteen it hides — the same
partition R2010 produces from a bit 500-odd positions earlier.

Two structural findings. is_internal_use_only moved from the head
to the final bit; and display_brightness is a BL where R2010
spends a BD, decoding -50 (Dim), 50 (Brighten) and 0 (the other
22) against R2010's -50.0 / 50.0 / 0.0. The BL is also the whole
explanation for the corpus's bit budgets: the tails after the two edge
CMCs measure 124 bits on 22 records, 156 on Dim (full BL, +32) and
132 on Brighten (byte BL, +8), and nothing else in the record varies
between those three styles.

Value corroboration against a second file. Twelve BS slots, all
five CMCs and both remaining BDs decode the same value as the same
style
on arc_2010.dwg, on all 24 records — including everything that
varies style by style:

  • internal_style_type 0 Flat … 27 Shaded;
  • edge_modifier 0/8/10/11/12, edge_silhouette_width
    3/5/6, edge_width 1, edge_overhang 6, edge_jitter 2;
  • edge_obscured_linetype 2 on Hidden and Shaded-with-edges, 7 on
    Linepattern, 1 elsewhere — and edge_intersection_linetype 7 on
    Linepattern, 1 elsewhere, the pair that pins the two ends of the
    trailing run;
  • edge_crease_angle 40 on Hidden / Shades of Gray / Sketchy, 179
    on Conceptual, 1 elsewhere;
  • face_mono_color 0xC2FFFFFF everywhere but ColorChange's
    0xC2808080; edge_silhouette_color 0xC3000007 everywhere but
    Shaded's 0xC2787878.

Two slots differ, informatively. face_opacity and face_specular
are signed on R2004. Magnitudes match R2010 on all 24; the sign
tracks whether the property applies — face_specular is positive on
exactly the seven styles that shade faces (Flat, FlatWithEdges, Gouraud,
GouraudWithEdges, Realistic, Shaded, Shaded with edges) and negative on
the other seventeen, and face_opacity is positive on exactly X-Ray,
the one translucent style. Values are surfaced as measured, sign
included. One further value differs for content reasons: Realistic
decodes face_lighting_quality 2 on R2004 and 3 on R2010, with
every other field of that record agreeing — the style being clamped when
saved down, not a mis-read field.

What is not determined — the 13-bit run

Thirteen bits sit between edge_silhouette_width and
edge_intersection_linetype, and they hold the constant
0b0_0000_0001_0010 on every one of the 72 corpus records. A run
that never varies cannot have its internal boundaries measured, only its
width; an exhaustive enumeration returns many splits that fit. The module
reads it as RC BS B BS — the only fit whose first token is a whole byte
— names the last three for the three properties R2010 places in exactly
this position (edge_halo_gap, edge_hide_precision,
edge_isoline_count, all of which decode 0 / false / 0 there on
the same 24 styles), and surfaces the leading byte as
AcadVisualStyle::edge_unknown_byte rather than giving it a
plausible-sounding name. Documented as a reading, not as evidence, in
the module docs, ARCHITECTURE.md §7d.1a and CLEANROOM.md. A future R2004
file with a non-default halo gap or isoline count would settle it.

Why R2007 is still declined

Not for want of a field list. Two upstream gaps stand between an
AC1021 file and any decoder:

  1. the container parse returns SectionMapStatus::Deferred for R2007
    (Publish from a signed tag through trusted publishing #110, second Sec_Mask obfuscation layer);
  2. string_stream::data_section_end locates the split-stream trailer
    from the leading MC handle-stream size that only R2010 and newer
    write, so it declines R2007 outright.

probe_object_layout on arc_2007.dwg panics with "this version has
no object-stream walk"
, and probe_class_census reports "no
AcDb:Classes section"
. No R2007 object of any type reaches this module,
so the corpus cannot say whether R2007 writes the flag-less list or the
paired one. decode_object returns Error::Unsupported for that band
rather than shipping a reading no byte has ever confirmed, and the
dispatcher maps that to Unhandled. #48 stays open for R2007 — this
PR says Refs #48, not Closes.

Tests

Four new BitWriter fixtures alongside the existing R2010/R2013 ones:

  • r2004_inline_visual_style_closes_on_its_object_data_size — the
    flag-less body on the inline layout, checking format_version == 0
    (no such slot on R2004), the signed face_opacity, the BL
    brightness, edge_unknown_byte and an empty property_flags;
  • r2004_body_rejected_by_the_r2010_field_list — the two lists differ
    by 28 BS flags, so the boundary check has to reject the crossover;
  • rejects_r2007 / rejects_pre_r2004 — both decline with
    Error::Unsupported, so a dispatched record lands in the Unhandled
    bucket rather than being reported as broken.

Gate: cargo fmt --all, cargo clippy --all-targets --all-features -D warnings, cargo test --release (16 suites, all green),
cargo +1.85.0 test --no-run, cargo deny check all,
RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --all-features — all
clean.

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. This PR needs no new outside vocabulary: the R2004 field list was
    derived entirely from the corpus bytes and the boundary the format
    itself carries, and every name on it is carried over from the R2010
    list already disclosed in CLEANROOM.md (2026-08-30, VISUALSTYLE
    property names), justified slot by slot against the value the same
    style decodes on arc_2010.dwg. The one slot with no R2010
    counterpart is labelled edge_unknown_byte. ODA spec v5.4.1 §20.4
    carries no VISUALSTYLE entry, and no citation is claimed for it.
    CLEANROOM.md records this in the VISUALSTYLE section.
  4. I have never had access to any of the forbidden sources in a
    commercial or NDA'd context.

Refs #48


Note

Medium Risk
Non-spec binary layout decoding affects 72 real records; wrong field boundaries would mis-read style data, though boundary self-checks and cross-file corroboration reduce that risk.

Overview
Adds R2004 (AC1018) decoding for ACAD_VISUALSTYLE, clearing the largest remaining unhandled block (72 corpus records) by routing decode_object to a new 30-field, flag-less wire layout distinct from the R2010+ (value, flag) list.

The R2004 path reads inline TV, uses BL for display_brightness (widened to f64), leaves format_version at 0, moves is_internal_use_only to the record tail, and exposes a constant 13-bit gap as edge_unknown_byte plus documented halo/isoline slots rather than inventing names. R2010+ behavior is unchanged behind decode_paired; pre-R2004 and R2007 still return Error::Unsupported (upstream object-stream gaps, not guessed).

Coverage docs (README, STATUS, CHANGELOG, ARCHITECTURE, CLEANROOM) now report 2,259 decoded / 119 skipped / 0 errored (95.0% aggregate), with R2004 at 97.5%. New unit tests assert the R2004 body closes on RL boundary and is rejected if parsed with the R2010 field list.

Reviewed by Cursor Bugbot for commit 723a6bb. Configure here.

R2004 stores the same 24 shipped styles on a second field list: 30
fields, no (value, flag) pairs, one fewer property and a different
order. It closes with delta 0 on all 24 records of each of
arc_2004.dwg, circle_2004.dwg and line_2004.dwg — the whole 72-record
Unhandled block.

Both ends of the record are anchored from its own redundancy: the
front from probe_token_scan's full-form BDs and method-carrying CMCs,
the back from the unique offset at which BS, BL, BS, B lands exactly
on the RL object-data-size boundary. Two structural findings fall out:
is_internal_use_only is the record's final bit rather than part of its
head, and display_brightness is a BL where R2010 spends a BD, which is
why Dim's record runs 32 bits longer than its neighbours' and
Brighten's 8.

Twelve BS slots, all five CMCs and both remaining BDs decode the same
value as the same style on arc_2010.dwg, on all 24 records.
face_opacity and face_specular are signed on R2004; magnitudes match
R2010 everywhere and the sign tracks whether the property applies.

The 13 bits between edge_silhouette_width and
edge_intersection_linetype are constant on all 72 records, so only
their width is evidence: read as RC BS B BS, with the leading byte
surfaced as edge_unknown_byte rather than given an invented name.

R2007 stays declined — the container parse is Deferred for AC1021 and
the split-stream trailer is located from an MC field only R2010+
writes, so no R2007 object reaches a decoder at all.

Corpus: 2187/191/0 (92.0%) -> 2259/119/0 (95.0%); R2004 85.4% -> 97.5%.

Refs #48
@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_c0a24daf-d7b8-4232-9156-ec96d19610fc)

…4-r2007

# Conflicts:
#	README.md
#	STATUS.md
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