Skip to content

feat(dxf): write the symbol tables from the decoded records (#126) - #347

Merged
DrunkOnJava merged 24 commits into
mainfrom
feat/dxf-tables
Oct 27, 2026
Merged

DrunkOnJava merged 24 commits into
mainfrom
feat/dxf-tables

Conversation

@DrunkOnJava

Copy link
Copy Markdown
Owner

Summary

dwg-to-dxf now writes the VPORT, LTYPE, LAYER, STYLE, UCS, APPID, DIMSTYLE and BLOCK_RECORD tables from the decoded symbol-table records, each record under its own handle and owner, with the groups of AutoCAD's own export, and a probe pairs every record written with the export's record of the same handle and compares it group by group. Follow-on to #320 (#126); one PR per section, so VIEW (waiting on #284's view-mode fix) and the other sections follow.

The header names a layer, text style, linetype, dimension style or block only when a written table defines it, so $DIMSTYLE and $DIMBLK are now written where #320 had to omit them. A record the export itself creates while saving (a handle at or above the DWG's $HANDSEED) is not in the DWG and not written. UCS is the one exception to "paired with the export": no drawing of the corpus holds a UCS record, so it is written as AutoCAD's empty table when the drawing has none and left out when it has (#285: the decoder has never read a real record and skips a second BS that §20.4.62 lists).

Spec reference

ODA v5.4.1 §20.4.52 (BLOCK_HEADER), §20.4.54 (LAYER), §20.4.56 (STYLE), §20.4.58 (LTYPE), §20.4.64 (VPORT), §20.4.68 (DIMSTYLE), and each section's "Handle refs" list; the group codes, the order and the values AutoCAD omits are measured on the 42 AutoCAD DXF exports (R2000 to R2018) of the public corpus. ARCHITECTURE.md §7ac has the tables and the findings.

  • src/dxf_tables.rs: the builders and the writer. DIM_GROUPS is the DIMSTYLE group table with the imperial default AutoCAD leaves out of each (measured by pairing every decoded variable with the export's record); a block's name is the one its BLOCK entity gives; a handle group is written only when the OBJECTS section defines the object it names.
  • src/tables/handles.rs (new): the handle stream of a table entry: the control object, the reactors, the extension dictionary, and the entry's own handles by position. Measured layouts: LAYER 3, 4 and 5 handles by release (R2000, R2007, R2013), VPORT 3 and 6, DIMSTYLE 6 and 9, BLOCK_RECORD from §20.4.52's list; a list whose length is not the one that order gives is not read.
  • src/tables/vport.rs, block_record.rs, dimstyle.rs: what the decoders read and dropped is now surfaced (VPORT's snap and grid switches, its UCS and R2007 lighting block; BLOCK_RECORD's insert count, preview and R2007 units; dimstyle::decode_with_vars returns every dimension variable of the record). The structs gain fields; the fields they had are unchanged.
  • src/common_entity.rs: CommonObjectData keeps the XDic Missing Flag it read and dropped.
  • Finding: an R2000 file saved by ACadSharp holds an extension dictionary on three true or book colour layers that AutoCAD's export drops (written here, with the dictionary).

Test plan

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • Shown working on real files, no new unit tests: cargo run --release --features dxf-reader --example probe_dxf_tables -- <dwg-corpus> over the 42 drawings that have an AutoCAD export (AC1014 and the two drawings without a twin are skipped and listed), wired into the Corpus job:
table          written  paired  groups  agree relation  disagree  extra  om.grp   om.rec
VPORT              42      42    2226   2224        2         0      0     110        0
LTYPE             132     132     804    804        0         0      0       0       24
LAYER             156     156    1092   1092        0         0      0     368        0
STYLE             108     108     972    972        0         0      0     232        0
UCS                 0       0       0      0        0         0      0       0        0
APPID             393     393     786    786        0         0      0       0        0
DIMSTYLE          108     108    1437   1433        4         0      0     332        0
BLOCK_RECORD      270     270    1117   1114        3         0      0     154        0
TOTAL            1209    1209    8434   8425        9         0      0    1196       24

Relation is a difference the way the export was made explains: the active viewport of geoloc.dwg, whose export is a later save (its $TDUUPDATE is 1.94 days later) with another view height and centre; the dynamic block of the R2000, R2004 and R2007 saves, which AutoCAD loads as *U17; and the fill colour of four DIMSTYLE records, a true colour whose index the DWG does not store. Groups omitted have a stated reason the probe checks: extended data, a true colour's index, a layer colour name, the entities that react to a record or insert a block (ENTITIES carries no handles yet), the object a handle names where OBJECTS does not write it, and a linetype with a shape or text dash (24 records, written by none). One without a reason fails the probe.

Existing tests and code changed

None of the existing tests changed. CommonObjectData, VportEntry and BlockRecord gain fields (nothing in the crate builds them but the decoders); dimstyle::read_cmc_inline now returns the colour it read, where it returned its index.

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 (v5.4.1) is the source for the table sections.
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported.

The only other inputs are the public corpus and AutoCAD's own DXF exports of its drawings. No algorithm-description comments in other projects were read.

Developer Certificate of Origin

I affirm the contribution is my own work and may be distributed under the project's Apache-2.0 license.

…126)

src/dxf_header.rs turns the decoded AcDb:Header into the $VARIABLE groups
AutoCAD's own export writes for the same drawing, and nothing else: a variable
the export omits ($PELLIPSE, $FACETRES, the unknown slots, control-object
handles) is omitted, and so is one the DWG cannot give (local $TDCREATE and
$TDUPDATE, $ACADMAINTVER, a true colour, a null default visual style). Group
codes and the first release of each variable are measured on the 50 AutoCAD
exports of the corpus. Handles that DXF writes as names are resolved through
the decoded symbol-table records (an undecodable record still gives its name
as the first string of its string stream); $CMLSTYLE takes the dictionary key's
case and a standard arrowhead block loses its underscore. $MEASUREMENT is read
from AcDb:Template (§22), $DWGCODEPAGE from the file header and $LASTSAVEDBY
from AcDb:SummaryInfo. R12 and R14 targets keep $ACADVER alone: no AutoCAD
export of either exists to measure against.

examples/probe_dxf_header.rs converts every drawing that has an AutoCAD export,
reads dwg-to-dxf's output back with dxf_reader and compares every variable:
9,514 agree, 173 hold a stated relation (a later save), 0 disagree, 0 extra, and
each of the 147 omissions has a stated reason. The Corpus job runs it.

tests/integration_dxf_roundtrip.rs told group-code lines from value lines by
their shape, which a header value such as $TREEDEPTH's 3020 defeats; it now
reads the file as the code and value pairs it is.
…s angles, text and arrowheads as DXF reads them (#126)

The converter writes layer 0 and no other symbol table, so a header naming any
other layer, style, linetype, dimension style, mline style, UCS or block would
point at nothing: those names are omitted (an empty name is kept), and the probe
lists each as an omission with that reason. $ANGBASE is radians in the database
and degrees in DXF group 50, so groups 50 to 58 are converted. Before R2007,
whose DXF reads bytes in $DWGCODEPAGE, non-ASCII header text is written as
\U+XXXX escapes. The leading underscore is dropped only from AutoCAD's standard
arrowhead block names; any other block keeps its name.
… every value on one line (#126)

$CMATERIAL, $INTERFEREOBJVS and $INTERFEREVPVS name MATERIAL and VISUALSTYLE
objects, which the converter exports as untyped placeholders; the references
are omitted until it exports them as their types ($HANDSEED, the next free
handle, is still written). A control character in a header string, a line feed
above all, would have put the rest of the value on the next group-code line; it
is now written in DXF's caret notation, with the caret itself as a caret and a
space.
…coded records (#126)

src/dxf_tables.rs writes each TABLE block under its control object's handle and
every record under its own, owned by the table, in the group order of AutoCAD's
exports. The header now names a layer, text style or linetype whenever a
written table defines it, which brings the header's agreeing variables from
9,224 to 9,350.

examples/probe_dxf_tables.rs pairs every record written with the export's
record of the same handle (a record the export registered again under another
handle pairs by name): 789 records, 3,183 groups, every one equal, none extra.
What is omitted has a reason the probe checks: handle-stream groups the decoder
does not read (linetype, plot style, material, visual style, extension
dictionary), a true colour's 420 and 62, extended data, and a linetype with a
shape or text dash. The Corpus job runs it. ACAD_SPLINE_DATA is not written
because AutoCAD's export omits it on every drawing that holds it. Targets before
R2000 keep the default layer.
… handle groups (#126)

VPORT now surfaces what its decoders read and dropped (circle zoom, fast zoom,
UCS icon, snap and grid switches, the viewport's UCS, and from R2007 the
lighting and grid block) and BLOCK_RECORD the insert count, preview bitmap and
R2007 insert units, explodability and scaling. dwg-to-dxf writes both tables, an
empty UCS table when the drawing has no UCS record, and from each record's
handle stream (the new tables::handles) the reactors, extension dictionary,
layout handle, and a layer's linetype, plot style, material and visual style. A
handle group is written only when OBJECTS defines the object it names.

The header names a block when the BLOCK_RECORD table defines it. The probe pairs
1101 records of the 42 corpus drawings with AutoCAD's export: 6992 groups agree,
5 are relations it names (a later save's active view, a dynamic block AutoCAD
loads as *U17), none disagree and every omission has a stated reason.
…the record (#126)

tables::dimstyle::decode_with_vars returns all the variables an R2000 to R2018
DIMSTYLE stores, by AutoCAD's name and in stored order, where DimStyleEntry
kept 15 of them. dwg-to-dxf writes a group only when the value differs from the
imperial default AutoCAD leaves out (measured on the 108 DIMSTYLE records of the
corpus), the text style, blocks and linetypes by handle, the table header's 71
and 340 list from the control object, and the header's $DIMSTYLE now names a
style the table defines.

The probe pairs 108 records with AutoCAD's export: 1433 groups agree, 4 are a
true-colour fill colour whose index the DWG does not store, none disagree. The
whole tables probe over the 42 drawings: 1209 records, 8425 groups agree, 9
named relations, 0 disagree, 0 extra.
# Conflicts:
#	.github/workflows/ci.yml
#	ARCHITECTURE.md
#	Cargo.toml
#	examples/probe_dxf_header.rs
#	src/dxf_convert.rs
#	src/dxf_header.rs
#	src/dxf_sections.rs
@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-27T01:31:08.381010Z f09d6dc 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: d6a8f1548b

ℹ️ 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_tables.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: 3b57a87df4

ℹ️ 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_convert.rs Resolved
…on a visible layer (#126)

Table text is written through the header's release-aware escaping: before R2007
what is not ASCII is a \U+XXXX escape and a control character caret notation, so
a layer name in TABLES reads the way $CLAYER names it. The converter's entities,
which carry no layer of their own yet, go on layer 0 when it is neither frozen nor
off, else on the first layer that is, so the decoded layer table cannot hide them.

@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: 77813eb325

ℹ️ 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_header.rs Resolved
Comment thread src/dxf_convert.rs Resolved
…ite and to untyped objects (#126)

The header's $DIMBLK family and a DIMSTYLE's 341 to 344 name an arrowhead block
only when BLOCKS writes it, which is the two empty blocks it writes today
(dxf_tables::BLOCKS_EXPORTED): lift that when BLOCKS writes block contents. A
handle group names an object only when OBJECTS writes it under its own type: a
layout, material or visual style is written as an untyped record, so a block's
340 to a layout, a layer's 347 and 348 and a viewport's 348 are left out until
those objects are written as what they are.

The tables probe is unchanged in what it proves (1,209 records, 0 disagree, 0
extra) and lists each left-out group with its reason; the header probe omits
269 names where it omitted 263.

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

ℹ️ 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_tables.rs Resolved
…release that stores them (#126)

R13 and R14 layers carry neither, and the decoder leaves them clear: that read as
a layer that does not plot (290 = 0) and as lineweight 0 (370 = 0) in an R14 to
R2000+ DXF. They are written from the source release R2000 on, as before.

@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: 83890acc21

ℹ️ 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_tables.rs Resolved
#126)

visible_layer skips a layer with group 290 of 0 (an omitted 290 is the plottable
default), so a non-plotting layer 0 or a non-plotting first visible layer such as
Defpoints does not take the converter's entities out of a plot.
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