Skip to content

SwiftDWG 0.1.0

Choose a tag to compare

@gsdali gsdali released this 14 Nov 03:27
· 4 commits to main since this release
999c936

First release of SwiftDWG: a native-Swift reader for DWG, AutoCAD's binary drawing format. DWG.read(contentsOf:) returns a SwiftDXF DXF.Drawing: the same model SwiftDXF gives for a DXF, with each entity's handle as its identity, blocks, layers, line types and dimension styles. No binary, no subprocess, no C or Rust dependency.

.package(url: "https://github.com/SecondMouseAU/SwiftDWG.git", from: "0.1.0")

What is checked

A DWG is read into DXF text with AutoCAD's own group codes and handed to SwiftDXF, so a drawing from a DWG goes through the same code as one from a DXF. Every comparison is against SwiftDXF's reading of the DXF AutoCAD itself wrote from the same drawing.

  • R2000, R2004, R2007, R2010, R2013 and R2018: 262 of 267 entities identical on each, handles included. Layers, line types, dimension styles, blocks, units and extents agree.
  • R14: read, and compared with the R2000 file for lines, circles, arcs and points. R13 is written and has never been run (no sample). R12 and older are not read.
  • The comparisons against AutoCAD's sample drawings need DWG_CORPUS and run on a developer machine, not in CI; CI runs the unit tests and the two small committed drawings.

Limits (the README lists them all)

  • Splines AutoCAD R2013 and later keeps as fit points only come through without control points; a leader's hook-line vertex is not synthesised.
  • Not decoded: polyface and polygon meshes, and the attributes of an insert.
  • A layer's true colour gets the nearest palette index.
  • Text in a code page before R2007 that SwiftDWG has no table for reads as Windows-1252.
  • Many paths are checked only against hand-built bit streams, not against drawings AutoCAD wrote: MINSERT, TEXT alignment and oblique, TRACE, 2D polylines, hatch arc, ellipse and spline edges, and every R13 path.
  • Anything that cannot be read is left out and counted in SwiftDXF's skipped types (UNREADABLE_<type>), and a damaged table control object makes DWG.read throw. Before R2004 an unreadable entity no longer takes the ones after it: the links are followed from both ends of the block and the rest is found by owner. With three or more unreadable entities in one block, the draw order between them can be lost.
  • A corrupt file ends in a DWG.Error or a drawing that counts what it lost; it is not meant to trap or never return. That is checked by inverting single bytes of the committed drawings and of the AutoCAD samples (about 1,500 positions each, every byte of the file header and page maps), not proved for every byte. A file found to trap or hang is a bug to report (#6 was the two found before this release).
  • Performance has not been measured.

Provenance

SwiftDWG is a Swift port of ACadSharp (MIT) with the Open Design Specification for .dwg files. It is not clean-room. NOTICE.md carries ACadSharp's licence and the record of what was and was not consulted: no LibreDWG (GPL) or acadrust (MPL) source was read or used. DWG is a trademark of Autodesk, Inc.

Requires Swift 5.9 and SwiftDXF 0.4.0 or later.