jflib-dxf
DXF import for JFLib. It reads AutoCAD's ASCII exchange format, from R12 to
2018, into a plain data model that needs no GPU: the header's variables, the tables of layers,
linetypes, text styles, block records and dimension styles, blocks with their entities, and the
entities of the drawing. A CAD view, a converter or a test reads the same model;
jflib-render2d maps it into a scene as it is read
(render2d::dxf). It is plain Rust, without the standard library and without a line of unsafe
code.
How it is used
use ;
// a small file in memory: everything kept
let Some = read_file else ;
let doc = match load ;
for e in &doc.entities
// a large one piece by piece: the sink gets the header, the tables, each block and each entity
;
let Some = open else ;
let mut at = 0u64;
let mut source = ;
let mut count = Count;
let _ = read;
The reader knows LINE, POINT, CIRCLE, ARC, ELLIPSE, SPLINE (also HELIX), LWPOLYLINE and POLYLINE
with their vertices (bulges, widths, 3D polylines, polyface and polygon meshes), TEXT, ATTRIB,
ATTDEF, MTEXT (with R2018's columns), INSERT with MINSERT's array and its attributes, HATCH (paths
of lines, arcs, elliptic arcs, splines and bulged polylines; the pattern's line families; solid and
gradient), SOLID, TRACE, 3DFACE, DIMENSION and ACAD_TABLE (through their anonymous blocks), LEADER,
WIPEOUT, RAY and XLINE. Other kinds are counted by name. Strings before AutoCAD 2007 are decoded
from the header's code page (the Western and Cyrillic pages, the DOS pages and the East Asian ones:
Shift_JIS, GBK, EUC-KR, Big5), later ones as UTF-8, and \U+XXXX and \M+NXXXX everywhere. mtext::parse turns
MTEXT's inline format codes into paragraphs of formatted runs, specials TEXT's %% codes into
runs with their underline, overline and strike-through. aci_rgb gives AutoCAD's colour index,
font_substitute which font of JFLib's repository stands in for a text style's font: SHX fonts
belong to Autodesk, and JFLib carries no Microsoft fonts.
Files are untrusted input
Limits bounds the length of a line, the pairs, bytes and points of one entity, the entities,
points, blocks, names and table entries that are kept. A count in a file (vertices, edges, knots)
is never used to allocate: lists grow as their items arrive. Nothing recurses. A value that is not
a number where one belongs is skipped with a note, a group code that is not a number ends the file
with Error::Invalid, a binary DXF is Error::Binary. A file that ends early gives what was read.
How to get it
Like all of JFLib, the crate comes through the one dependency
jflib, as jflib::dxf. All of JFLib's crates share one
version and are released together. It runs on every platform JFLib supports.
What's new in 0.2.2
The crate is new: it reads DXF files in the ASCII format of R12 to 2018 into a model without a GPU,
with the East Asian code pages. render2d::dxf draws what it reads. Everything is in the
changelog.
Documentation
- JFLib's guide: how an app is written
- API reference: every public
item of
dxf, also on docs.rs - RENDER2D.md (in German): what is read, how render2d draws it, the font substitutes, the limits, the decisions and the tests
License
MIT or Apache-2.0, at your choice.