Skip to content

feat(objects): read XRECORD values and extended entity data in the code page each string names (§28, §20.4.104, #375) - #380

Merged
DrunkOnJava merged 9 commits into
mainfrom
fix/xrecord-xdata-code-page
Oct 27, 2026
Merged

DrunkOnJava merged 9 commits into
mainfrom
fix/xrecord-xdata-code-page

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Reads the two places that hold pre-R2007 text the crate never turned into a string, XRECORD data and extended entity data, as values, with each string decoded in the code page its own page byte names (#375, the XRECORD/XDATA item). XRecord::data stays raw bytes and common_entity::skip_extended_data is untouched; the new src/extended_data.rs adds extended_data::read (the extended data chain of a walked record) and extended_data::xrecord_values (an XRECORD), for R13 to R2004. R2007 and later (UTF-16) return Error::Unsupported.

Spec reference

ODA spec v5.4.1 §28 (extended entity data) and §20.4.104 (XRECORD); the code page of each string, §3.2.5 and src/code_page.rs (#374). ARCHITECTURE.md §7aq (provisional letter; the integrator renumbers).

The specification's two string layouts are one in the data. §20.4.104 says "the string length (RC), the dwgcodepage (RC), and then the string" and §28 "1st byte of value is the length N; this is followed by a 2-byte short indicating the codepage": on every pre-R2007 drawing of the pinned corpus both are the same three bytes before the characters, an RS length and an RC page. No string is 256 bytes or longer (the longest is 250), so the data cannot tell the RS form from an RC followed by a short; the reader takes RS, the form that reads every XRECORD to its last byte. XRECORD value widths follow the DXF group code ranges of Autodesk's public DXF Reference, only for ranges whose codes occur in the corpus; any other code is Error::Unsupported, never read at a guessed width (disclosed in CLEANROOM.md).

Corpus measurement (tools/corpus/measure.py check, 52 pinned drawings): every row matches the baseline, so no baseline is regenerated (no decoded, skipped or errored count moves: XRecord and the skip path are unchanged).

Evidence (cargo run --release --example probe_code_page -- ../dwg-corpus, 2026-10-27; 24 pre-R2007 drawings of the 52):

Measured Result
XRECORD bodies read 2,370 of 2,370 close exactly on their length (R14 1,154; R2000 629; R2004 587)
Records with extended data read 1,263 (every payload closes on its size)
Strings with a page byte 78,242 (76,926 XRECORD, 1,316 extended data); every page byte equals the header short, 0 differ
XRECORDs against AutoCAD's export, group by group (R2000, R2004) 227 compared each, 225 equal + 2 save-time: only #306 (a handle) and #D09 (a GUID and the saved file's path) may differ, under the same group code, with the rest of each record still compared
Extended data records against the export R2000 410 of 410 (2 of them lack a tail the export leaves out, an RTTcAl block; 1 is the VPORT table header #8, whose DbSaveVer item only the export holds), R2004 347 of 347 (1 export-only)
All compared records 1,211 of 1,211 agree
Patched copies (in memory, never written; own page, 29, 30, 31) XRECORD strings 16, 64 of 64 reads; extended data strings 2, 8 of 8 reads

Not measured, and said so in ARCHITECTURE.md: R2007+ strings; XRECORD codes outside the measured ranges; a length of 256 bytes or more; extended data of an application the export omits. R14 has no export that names a page, so R14 rests on the same shorts meaning there what they mean later (the strings of the R14 drawings name 29 and 30, as their headers do).

Overlap with #372 (DXF OBJECTS, adds its own XRecord::items): this PR touches src/objects/xrecord.rs not at all, so the two do not conflict by file today. #380 lands first (queued behind #376); the header lane resolves the src/objects/xrecord.rs conflict when it restacks #372 onto main, to one decode path (one place a pre-R2007 byte string becomes a String: CodePage::decode, each string reading its own page byte). extended_data::xrecord_values and XRecord::items then collapse to one reader, and probe_code_page and the DXF OBJECTS probe are rerun on that side.

README.md and STATUS.md are not refreshed here: tools/maintainer/readme_status.py is not on main yet (#376 adds it), so the integrator regenerates them after this lands.

Test plan

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features, cargo test --release --all-features (921 passed, 0 failed), MSRV cargo +1.85 check --all-features, wasm32 cargo check --lib, cargo deny check advisories bans licenses sources pass locally on this head
  • Shown working on real files: probe_code_page over the 52 pinned drawings (numbers above); the DXF oracle against tools/oracle/baseline.tsv; probe_header_vars, probe_dxf_header, probe_dxf_tables, probe_dxf_entities, probe_dxf_classes, probe_entity_colour, spec_examples at 0 differences; measure.py check (52 of 52 rows)
  • python3 tools/ci/spec_coverage.py --check and python3 tools/maintainer/train/arch.py check pass
  • No new unit tests. Tests touched: none.

Source-provenance declaration

By submitting this PR I certify that my contribution does not incorporate executable code from any source whose license is incompatible with Apache-2.0. Specifically:

  • No Autodesk DWG SDK source (RealDWG, ObjectARX, ObjectDBX) or NDA-protected Autodesk documentation was consulted or imported.
  • No Open Design Alliance Teigha / Drawings SDK source was consulted or imported. The ODA's public Open Design Specification for .dwg files PDF is explicitly allowed (see CLEANROOM.md).
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported. This matters because dwg-rs is Apache-2.0 and must remain compatible.

My contribution is based on:

  • The ODA's freely-redistributable Open Design Specification for .dwg files (v5.4.1);
  • Public reverse-engineering notes, research papers, or blog posts cited inline;
  • Reading algorithm-description comments (not executable code) in permissively-licensed projects (MIT / Apache / BSD) to resolve spec ambiguities — disclose any such reading in this PR body so it can be recorded in CLEANROOM.md.

See CLEANROOM.md for the full allowed/forbidden source list and the honest scope of what "clean-room" means for this project.

For this PR specifically: the layouts come from AutoCAD's own output alone: AutoCAD-written DWG files compared with AutoCAD-written DXF exports of the same drawing, from the pinned public corpus (nextgis/dwg_samples, ACadSharp samples/), as recorded in CLEANROOM.md (2026-10-27). The XRECORD group code widths come from Autodesk's public DXF Reference (recalled; dated entry in CLEANROOM.md). No code of any other DWG implementation was read.

Developer Certificate of Origin

By submitting this PR, I certify that the contribution complies with the
Developer Certificate of Origin 1.1.
Specifically, I affirm that the contribution is my own work (or rightfully
licensed to me) and that it can be distributed under the project's Apache-2.0
license.

I will sign off commits with git commit -s when asked, which adds a
Signed-off-by trailer to the commit message asserting the DCO.

…de page each string names (§28, §20.4.104, #375)

extended_data::read turns a record's extended entity data chain into values, and extended_data::xrecord_values an XRECORD's body, for R13 to R2004, each string decoded by CodePage::decode in the page its own byte names. The string layout, the handle byte orders and the value widths are measured against AutoCAD's exports: 1,209 of 1,209 compared records agree, and every one of 78,242 strings names its header's page.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T15:19:48.584087Z d4bc430 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29e0eddddd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/probe_code_page.rs Resolved
Comment thread examples/probe_code_page.rs Resolved
…ck export-only extended data (#375)

A save-time handle or GUID ended the XRECORD comparison there and any handle difference was accepted, and a record whose chain the reader returned empty was never compared with the export. Differences are now accepted only in the two records and for the three values the save makes anew, under the same group code, and the rest of the record is still compared; application data the export holds for a record the reader returned nothing for fails the probe unless it is the table header's DbSaveVer item. The probe also refuses to report when it paired nothing or patched no XRECORD or extended data string.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 62d10d5fb5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/probe_code_page.rs Resolved
Comment thread examples/probe_code_page.rs Resolved
# Conflicts:
#	ARCHITECTURE.md
#	CLEANROOM.md
…Al block to be missing (#375)

Applications are paired by identity: each application of the export, named by its group 1001, with the decoded application whose handle resolves through the drawing's APPID entries to the same name, so a wrong application handle fails the probe. The only leading items the export may lack are exactly the RTTcAl block (a string, a short, a long and $$NoName$$) of the two R2000 MTEXT records that carry it, and a decoded application the export omits altogether is counted, 45 on the pinned corpus.
…RTTcAl block (#375)

The exception for the leading RTTcAl block now names its application and its record kind as well as its shape; everywhere else the export's values must equal the decoded ones from the first item. Probe result on the 52 pinned drawings unchanged: 1,211 of 1,211 records agree.
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 27, 2026 15:22
@DrunkOnJava
DrunkOnJava merged commit e7c53e1 into main Oct 27, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/xrecord-xdata-code-page branch October 27, 2026 15:34
DrunkOnJava added a commit that referenced this pull request Oct 27, 2026
…and extended data strings included (#375)

With #380 on main the probe also patches XRECORD and extended data strings, and the R2004 drawings through the DWG writer: 266 strings in 27 kinds, 1,064 of 1,064 reads, 348 of 348 DXF name checks; XRECORD values 24 strings 96 of 96, extended data 3 strings 12 of 12.
DrunkOnJava added a commit that referenced this pull request Oct 27, 2026
…s (§3.2.5, #375) (#382)

* feat(writer): write the drawing's code page, not UTF-8 or bare escapes (§3.2.5, #375)

CodePage::encode is decode's inverse (a character the page holds is its byte, any other the \U+XXXX escape AutoCAD's own R2000 and R2004 saves hold). convert_dwg_to_dxf_bytes and dwg-to-dxf write R12 to R2004 in the drawing's page, the class table writer encodes through the page in force, and the R2004-family header carries the page again, so DwgFile::to_bytes keeps the text readable.

* fix(code_page): encode a character only when its bytes decode back to it (#375)

The WHATWG encoders map a few extra code points onto bytes the decoder reads as another character (U+00A5 to 0x5C and U+203E to 0x7E on Shift_JIS, U+0080 on Shift_JIS, U+20AC on GBK). encode_char now returns the bytes only when decode gives the character back, so those characters take the escape and a written string reads as the text it was. The 128 of 128 round trip of each named page in probe_code_page is the same check over the whole page.

* docs(architecture): the merged probe's patched-copy numbers, XRECORD and extended data strings included (#375)

With #380 on main the probe also patches XRECORD and extended data strings, and the R2004 drawings through the DWG writer: 266 strings in 27 kinds, 1,064 of 1,064 reads, 348 of 348 DXF name checks; XRECORD values 24 strings 96 of 96, extended data 3 strings 12 of 12.
DrunkOnJava added a commit that referenced this pull request Oct 27, 2026
…rove, and pin three public sources (§3.2.5, #375) (#384)

* feat(writer): write the drawing's code page, not UTF-8 or bare escapes (§3.2.5, #375)

CodePage::encode is decode's inverse (a character the page holds is its byte, any other the \U+XXXX escape AutoCAD's own R2000 and R2004 saves hold). convert_dwg_to_dxf_bytes and dwg-to-dxf write R12 to R2004 in the drawing's page, the class table writer encodes through the page in force, and the R2004-family header carries the page again, so DwgFile::to_bytes keeps the text readable.

* fix(code_page): encode a character only when its bytes decode back to it (#375)

The WHATWG encoders map a few extra code points onto bytes the decoder reads as another character (U+00A5 to 0x5C and U+203E to 0x7E on Shift_JIS, U+0080 on Shift_JIS, U+20AC on GBK). encode_char now returns the bytes only when decode gives the character back, so those characters take the escape and a written string reads as the text it was. The 128 of 128 round trip of each named page in probe_code_page is the same check over the whole page.

* feat(code_page): name the header shorts 28 to 41 that real drawings prove, and pin three public sources (§3.2.5, #375)

The short at 0x13 is AutoCAD's own enumeration, not a Windows code page number. Eight rows are added, each backed by a drawing: 38 and 39 by the localized layout name decoding in the nine newly pinned drawings (kurema/BookViewerApp3 MIT, Seeed-Studio/OSHW-Jetson-Series and huifer/planar_algorithm Apache-2.0), and 28, 32, 33, 36, 40 and 41 by local-only evidence recorded by sha256 in ARCHITECTURE.md (DXF twins that name the page, Greek and Korean text). fetch.py percent-encodes the path of a file. The probe pairs the header short of every release with its export, checks the known texts, counts the strings that occur in the export, and lists the drawings whose strings hold a \U+ or \M+ escape.

* test(corpus): ratchet the nine new pinned drawings, nine BLOCK_HEADER errors included (#375)

Regenerated from the corpus-measurement artifact of the Corpus job: the 52 existing rows are unchanged, the nine new rows decode 106,189 records, skip 90 and error on 9 BLOCK_HEADER records of the four AutoCAD I.18.0.0 drawings, which ARCHITECTURE.md now says.

* docs(code_page): point the module docs at this change's ARCHITECTURE section (#375)

The two references said 7aq, which on main is the PERSSUBENTMANAGER section; the rows section is 7ar.

* docs(architecture): the merged probe's patched-copy numbers, XRECORD and extended data strings included (#375)

With #380 on main the probe also patches XRECORD and extended data strings, and the R2004 drawings through the DWG writer: 266 strings in 27 kinds, 1,064 of 1,064 reads, 348 of 348 DXF name checks; XRECORD values 24 strings 96 of 96, extended data 3 strings 12 of 12.
DrunkOnJava added a commit that referenced this pull request Oct 27, 2026
….52, #386) (#388)

* feat(writer): write the drawing's code page, not UTF-8 or bare escapes (§3.2.5, #375)

CodePage::encode is decode's inverse (a character the page holds is its byte, any other the \U+XXXX escape AutoCAD's own R2000 and R2004 saves hold). convert_dwg_to_dxf_bytes and dwg-to-dxf write R12 to R2004 in the drawing's page, the class table writer encodes through the page in force, and the R2004-family header carries the page again, so DwgFile::to_bytes keeps the text readable.

* fix(code_page): encode a character only when its bytes decode back to it (#375)

The WHATWG encoders map a few extra code points onto bytes the decoder reads as another character (U+00A5 to 0x5C and U+203E to 0x7E on Shift_JIS, U+0080 on Shift_JIS, U+20AC on GBK). encode_char now returns the bytes only when decode gives the character back, so those characters take the escape and a written string reads as the text it was. The 128 of 128 round trip of each named page in probe_code_page is the same check over the whole page.

* feat(code_page): name the header shorts 28 to 41 that real drawings prove, and pin three public sources (§3.2.5, #375)

The short at 0x13 is AutoCAD's own enumeration, not a Windows code page number. Eight rows are added, each backed by a drawing: 38 and 39 by the localized layout name decoding in the nine newly pinned drawings (kurema/BookViewerApp3 MIT, Seeed-Studio/OSHW-Jetson-Series and huifer/planar_algorithm Apache-2.0), and 28, 32, 33, 36, 40 and 41 by local-only evidence recorded by sha256 in ARCHITECTURE.md (DXF twins that name the page, Greek and Korean text). fetch.py percent-encodes the path of a file. The probe pairs the header short of every release with its export, checks the known texts, counts the strings that occur in the export, and lists the drawings whose strings hold a \U+ or \M+ escape.

* test(corpus): ratchet the nine new pinned drawings, nine BLOCK_HEADER errors included (#375)

Regenerated from the corpus-measurement artifact of the Corpus job: the 52 existing rows are unchanged, the nine new rows decode 106,189 records, skip 90 and error on 9 BLOCK_HEADER records of the four AutoCAD I.18.0.0 drawings, which ARCHITECTURE.md now says.

* docs(code_page): point the module docs at this change's ARCHITECTURE section (#375)

The two references said 7aq, which on main is the PERSSUBENTMANAGER section; the rows section is 7ar.

* fix(tables): read the whole insert-count run of a BLOCK_HEADER (§20.4.52, #386)

* docs(architecture): the merged probe's patched-copy numbers, XRECORD and extended data strings included (#375)

With #380 on main the probe also patches XRECORD and extended data strings, and the R2004 drawings through the DWG writer: 266 strings in 27 kinds, 1,064 of 1,064 reads, 348 of 348 DXF name checks; XRECORD values 24 strings 96 of 96, extended data 3 strings 12 of 12.

* docs(arch): number the BLOCK_HEADER section after the code page sections (#386)

* chore(corpus): commit the baselines CI run 40573732934 measured

* docs(architecture): drop the second copy of section 7au the merge with #384's squash appended

* chore(corpus): commit the baselines CI run 40576136864 measured
DrunkOnJava added a commit that referenced this pull request Oct 28, 2026
…10-27 (#416)

* docs: bring README, ROADMAP and CHANGELOG up to the landings of 2026-10-27

README's code-page and DXF writer text named work in review that has landed
(#371, #380, #382, #384); jev_review.py prose ranked those sentences 0.72 to
0.96. ROADMAP's "where it stands" table was a 2026-10-21 snapshot whose
numbers, CI row and release row were all out of date; it now points to the
rendered numbers instead of repeating them. CHANGELOG gains #371, #380, #382,
#384, #385 and #404.

* docs(changelog): record the CI-only merge train (#408)

* docs: OBJECTS landed (#372): README, ROADMAP and CHANGELOG

* docs: LAYOUT, GROUP and MLINESTYLE (#373), the class map writer (#405) and the double-byte round trip (#414) landed

* docs: VISUALSTYLE landed (#413)

* docs(readme): name the skipped types still in review without per-type counts; MATERIAL landed (#325)

* docs(readme): point to the open decoder PRs instead of a list that each landing makes stale
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