Skip to content

Fix DWG/DXF round-trip and version-conversion defects (R2007 output, tables, dimensions, SHAPE, XDATA, transforms) - #1302

Closed
Sring65 wants to merge 0 commit into
DomCR:masterfrom
Sring65:master
Closed

Sring65 wants to merge 0 commit into
DomCR:masterfrom
Sring65:master

Conversation

@Sring65

@Sring65 Sring65 commented Oct 15, 2026

Copy link
Copy Markdown

Note: All modifications are AI-generated code.

Summary

A set of fixes so that DWG/DXF files read/written by ACadSharp open cleanly in
AutoCAD and round-trip (DWG → DWG / DXF) with correct geometry, associations,
and content. The changes are based on the current upstream line (v3.8.16).

This is a fairly large, multi-topic PR. I've grouped the fixes below so they can
be reviewed theme-by-theme.

Dependency: DomCR/CSUtilities

This PR depends on a companion change in DomCR/CSUtilities — a fix to the
Matrix3(Matrix4) constructor. Without it, the transform fixes in this PR
(ellipses, text rotation, arc angles) come out mirrored. The src/CSUtilities
submodule is pointed at that commit.

  • CSUtilities PR:
  • Submodule commit: fbf0723

Please merge the CSUtilities change first, or let me know if you'd prefer I
re-point the submodule.

What's fixed

R2007 (AC1021) DWG write

  • Implemented AC1021 output.
  • Page-record Checksum is computed over decompressed data and CRC over the
    compressed stored data (previously both over compressed data → "Error
    decrypting data").
  • enc=1 sections (SummaryInfo/Preview/AppInfo/AppInfoHistory/FileDepList) stored
    uncompressed for AC1021.
  • Encoded page physical size now accounts for the parity region instead of a fixed
    maxPageSize + 32, so large preview data no longer overflows and shifts pages.

Tables (AcDbTable)

  • DXF read of inlined cell contents now marks ContentType so R2010+ doesn't drop
    the whole table (Error 34 eWrongObjectType).
  • R2004 table write: 4th override bit / object-stream alignment.
  • R2010+ cached block reference restored (table not displaying).
  • Pre-R2007/R2007 legacy table-level override section preserved on write.

Dimensions & DIMASSOC

  • Dimension association read field order corrected to match the ODA spec
    (associativity / trans_space / rotated_type / dimension object) — was reversed,
    so native files' associations came out misaligned.
  • Dimension geometry follows transforms; OsnapPointRef last-point-ref bit kept.

SHAPE

  • DXF/DWG group code 2 writes the shape name (not the style name) so AutoCAD
    doesn't drop it.
  • Added shape-file index and search next to the drawing; fixes AutoCAD AUDIT
    "shape number/index <= 0".

Coordinate / transform (ApplyTransform)

  • Fixed for Arc, Shape, Text, Underlay, MLine, Point, Hatch, Leader, Dimension
    series, Spline, TableEntity; Insert scaling/rotation; Ellipse axis vectors +
    normal (with the CSUtilities Matrix3 transpose fix).

XDATA / string encoding

  • Pre-R2004 Chinese XDATA no longer garbled.
  • TV/TU strings now null-terminated (fixes class-name corruption).

Round-trip fidelity

  • Hatch origin/seed points, LWPOLYLINE width/const-width (43 flag), Leader
    hook line/text width/association, PDFUnderlay scale/rotation, Text/Attrib/Shape
    default omission, Wipeout clip close, HatchPattern angle, Spline nodes.

Gradient fill

  • R2000 gradient definition parse, R2004+ → R2000 down-conversion, R/B channel
    order, LWDISPLAY header variable.

Object stream / handle alignment

  • ACDS dangling reference (file corruption), PolyFaceMesh owned handles
    (HardOwnership), UCS/VIEW control-object handle slots, table-style soft pointer.

Verification

  • Affected files open in AutoCAD without errors (and pass ODA FileConverter audit).
  • Round-trip output compared against AutoCAD-native files: entity counts,
    geometry, associations, and content match.
  • Where a defect existed, the produced file was diffed field-by-field against the
    AutoCAD reference.

Notes for reviewer

  • Please review theme-by-theme using the headings above.
  • R2007 output is new functionality — worth a closer look on the write path.
  • Happy to split this into separate PRs per theme if that's easier to review.

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