Skip to content

feat(dxf): an ASCII DXF reader keyed by handle, for the value oracle - #223

Merged
DrunkOnJava merged 4 commits into
mainfrom
feat/dxf-reader
Oct 26, 2026
Merged

DrunkOnJava merged 4 commits into
mainfrom
feat/dxf-reader

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

An ASCII DXF reader (src/dxf_reader.rs, behind the new default-off dxf-reader feature) that keeps every group of every record in file order, types each value by its group code, and indexes records by handle, so the DWG decode can be compared with AutoCAD's own DXF export record by record (#99, #100).

#100 asks for a development tool rather than library API; the epic's brief asks for it in src/, self-validating and capped like the rest of the crate. A default-off feature does both: library consumers never compile it, while --all-features in CI builds, lints and documents it, and the oracle examples declare required-features = ["dxf-reader"].

Spec reference

Autodesk's public DXF Reference (the group-code/value grammar and its "Group Code Value Types" table), recalled; disclosed in CLEANROOM.md. Two readings were measured on the corpus exports rather than taken from the document, and the module docs record both:

  • on a DIMSTYLE, group 5 is DIMBLK (text; the R12 exports write it empty), which is why DIMSTYLE's handle is group 105;
  • a 102 bracket closes as } or as <name>} (the AC1015-AC1021 ellipse_* exports write XRECORD data as {ATTRRECORD ... ATTRRECORD}).

What the reader refuses (module docs, written before the code): binary DXF, a BOM or UTF-16; every size cap; mixed CRLF/LF; a code with no value line; a non-integer or out-of-table group code; a value that does not parse as its code's type (non-finite real, integer out of width, boolean other than 0/1, bad hex handle or binary chunk); non-ASCII text before AC1021 (it would need $DWGCODEPAGE) or non-UTF-8 after; a broken section/table/block structure, no EOF or data after it; a repeated or orphan header variable; an unbalanced 102 bracket; and from AC1012 on, a record in TABLES/BLOCKS/ENTITIES/OBJECTS with no handle, handle 0, or a duplicate handle.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • cargo +1.85 check --all-features --all-targets
  • Shown working on real files, no new unit tests:

The 42 .dxf files of nextgis/dwg_samples at ff05d5a89ce123da511ed93c5fe5e6df85e02ab8 (each checked against its git blob hash), fetched into a cache outside the repo:

cargo run --release --features dxf-reader --example dxf_census -- <corpus-dir> --mutations
file                       acadver secs hdrvar records handles digits
arc_2000.dxf               AC1015     6    199     229     208     16
arc_2004.dxf               AC1018     6    211     216     197     16
arc_2007.dxf               AC1021     6    251     205     186     16
arc_2010.dxf               AC1024     6    252     203     184     16
arc_2013.dxf               AC1027     6    253     153     134     16
arc_R12.dxf                AC1009     4    133      33       3     17
circle_2000.dxf            AC1015     6    199     229     208     16
...
ellipse_2000.dxf           AC1015     6    199     239     218     16
ellipse_R12.dxf            AC1009     4    133     163     133     17
...
polyline2d_line_2013.dxf   AC1027     6    253     153     134     16
polyline2d_line_R12.dxf    AC1009     4    133      37       7     17
TOTAL 42 files: 9093 header variables, 7425 records, 6538 handles

records by type:
  ACDBDETAILVIEWSTYLE 35   ACDBDICTIONARYWDFLT 35   ACDBPLACEHOLDER 35   ACDBSECTIONVIEWSTYLE 35
  APPID 198   ARC 6   BLOCK 119   BLOCK_RECORD 105   CELLSTYLEMAP 35   CIRCLE 6   CLASS 364
  DICTIONARY 1450   DICTIONARYVAR 280   DIMSTYLE 84   ELLIPSE 5   ENDBLK 119   ENDTAB 371
  LAYER 42   LAYOUT 105   LINE 6   LTYPE 112   LWPOLYLINE 5   MATERIAL 105   MLEADERSTYLE 35
  MLINESTYLE 35   POINT 12   POLYLINE 2   SCALE 595   SEQEND 2   STYLE 84   TABLE 371
  TABLESTYLE 35   VERTEX 132   VISUALSTYLE 840   VPORT 42   XRECORD 1583

Every file parses, every AC1015+ record outside CLASSES and ENDTAB carries a unique handle, and the 2000+ exports print reals at 16 significant digits (R12 at 17). --mutations puts a 999 comment in three legal places of each file (after 9 $ACADVER, between 0 SECTION and 2 <name>, inside a record): all 126 commented copies read exactly as their originals. It also damages each file twelve ways in memory; all 483 applicable damaged copies are refused and none is accepted (the R12 files have no 102 brackets and optional handles, so three of the twelve do not apply to them). Review fixes: 1004/1005 typed as binary/handle (f909585); 999 skipped where the version and section names are read (9568d0e), before which 35 handle-less copies with a comment where the version is read were accepted and 42 commented copies were refused:

  refused truncated                malformed DXF at line 21519: group code with no value line
  refused non-numeric code         malformed DXF at line 1: group code is not an integer: "x"
  refused unknown code 150         malformed DXF at line 5: group code 150 is not in the DXF Reference
  refused bad real                 malformed DXF at line 19: not a finite real: "1.0.0"
  refused duplicate handle         malformed DXF at line 1097: handle 8 is used twice
  refused open 102 bracket         malformed DXF at line 1947: DICTIONARY leaves a 102 bracket open
  refused mixed line endings       malformed DXF at line 2: CRLF and LF line endings are mixed
  refused no EOF                   malformed DXF at line 21517: no EOF
  refused data after EOF           malformed DXF at line 21521: data after EOF
  refused comment as $ACADVER      malformed DXF at line 1087: TABLE has no handle
  refused handle removed           malformed DXF at line 1085: TABLE has no handle
  refused binary sentinel          unsupported DXF encoding: binary DXF
  same    999 after $ACADVER       as the original
  same    999 after SECTION        as the original
  same    999 inside a record      as the original

Pairing with the DWG records (#101) and the field scorers (#102) follow in their own PRs.

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:

  • Autodesk's public DXF Reference (recalled; recorded in CLEANROOM.md) and the bytes of AutoCAD's own exports in nextgis/dwg_samples (read from a cache, not vendored).
  • No permissively-licensed project's code or comments were read.

Developer Certificate of Origin

By submitting this PR, I certify that the contribution complies with the Developer Certificate of Origin 1.1.

Closes #100

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 08:55
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 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-26T11:19:28.490227Z 8ffcdf8 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: 37496b9c26

ℹ️ 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 src/dxf_reader.rs Resolved

@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: f909585de7

ℹ️ 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 src/dxf_reader.rs Resolved

@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: 087bf6626c

ℹ️ 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 src/dxf_reader.rs Resolved
Comment thread examples/dxf_census.rs Resolved
Reads every group of every record in file order, typed by the DXF
Reference's group-code value table, and indexes records by handle
(group 5, or 105 on DIMSTYLE) with the owner taken from the first 330
outside the 102 brackets. Refuses malformed input instead of guessing:
truncation, unknown codes, unparsable values, open brackets, missing or
duplicate handles from AC1012 on, mixed line endings, binary DXF, and
every size cap.

Behind the default-off dxf-reader feature: a measuring instrument for
all 42 nextgis/dwg_samples exports and damages each eleven ways to show
every damaged copy is refused.

Refs #100
The DXF Reference's extended-data table gives 1004 as a binary chunk and
1005 as a database handle; the 1000-1009 text range swallowed both, so a
malformed 1004 or 1005 parsed silently. No corpus export carries either
code; the census still reads all 42 files and refuses all 448 damaged
copies.
A 999 comment is legal anywhere in a DXF file. The pre-scan that finds
$ACADVER took the group right after `9 $ACADVER` as its value, so a
comment there stood in for the version: UTF-8 decoding and the R13+
handle check followed the comment instead of the file. SECTION's name
was read the same way, so a comment between `0 SECTION` and `2 <name>`
refused a valid file. Both now skip 999 groups, as the HEADER parser
already did.

dxf_census --mutations now also puts a comment in those two places and
inside a record, and each copy must read exactly as the original; and
removes a handle behind a comment placed where the version is read,
which must be refused. Before the fix, over the 42 nextgis exports, 35
such copies were accepted and 42 commented copies were refused; after,
all 126 commented copies read as their originals and all 483 damaged
copies are refused.
…us copies

An XRECORD's groups after its `100 AcDbXrecord` marker are the
application's: the DXF Reference's XRECORD page gives codes 1 to 369 (but
5 and 105) to the application "in any way", so a `102 {data` there is a
value. The reader treated it as a bracket and refused the file ("XRECORD
leaves a 102 bracket open"); bracket, handle and owner checks now stop at
the marker, and top_level() returns every data group.

dxf_census --mutations split a CRLF file on LF and joined its copies with
LF, so every commented copy of a valid CRLF file was refused for mixed
line endings. Copies now keep the file's own ending, and a fourth legal
copy puts an unclosed `102 {` in the first XRECORD's data.

On a CRLF copy of arc_2004.dxf the three commented copies were refused
and are now read as the original; arc_2004.dxf with `102 {data` in its
first XRECORD was refused and now reads. The 42 nextgis DXFs: 483 damaged
copies refused, 161 legal copies (35 of them the XRECORD one) read as the
original, 0 accepted; 9093 header variables, 7425 records, 6538 handles.
@DrunkOnJava
DrunkOnJava merged commit 13fdd65 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/dxf-reader branch October 26, 2026 11:33
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.

An oracle DXF reader: HEADER, TABLES, BLOCKS, ENTITIES and OBJECTS keyed by handle

1 participant