render2d/dxf.rs#
Source: lib/render2d/dxf.rs
dxf -- a DXF drawing into a Scene (G6e2; docs/RENDER2D.md "DXF"): lib/dxf reads the file (streaming, bounded), this
module maps what it reads onto render2d as it comes: a render2d layer per run of entities on one DXF layer (the file's
order is the painter's order, as in AutoCAD), styles from colours, linetypes, lineweights and transparency resolved
by layer and by block, blocks as blocks (DIMENSION and ACAD_TABLE through their anonymous blocks), the object
coordinate systems projected onto the drawing's plane, polyline bulges as arcs, text in substitute fonts of the
repository, MTEXT's format codes laid out here into single-line texts.
dxf::load(&mut scene, &bytes, &Options) -> Result<Loaded, ::dxf::Error> a file in memory
dxf::read(&mut scene, &mut source, &Options) -> Result<Loaded, ::dxf::Error> piece by piece (a file of a gigabyte)
loaded.extents, kinds (per DXF kind: read, drawn, skipped in paper space, hidden, unsupported, failed, approximated),
layers (each DXF layer's render2d layers), set_layer_visible, group_of / members (the render2d entities one
DXF entity became)
What render2d refuses of an entity (a degenerate arc, a ring without area) is counted as failed, the rest goes on.
Re-exports: ::dxf::Family
struct Options<'a>how a drawing is mapped. Made withnewand changed field by field (it may grow)background: u32-- the view's background (0xFFRRGGBB): colour 7 is black on a light one and white on a dark one, wipeouts take itlineweights: Option<bool>-- lineweights shown (None: as the header's $LWDISPLAY says, off without it); pixels per millimetre of lineweight (96 / 25.4: 0.25 mm and less a hairline, as AutoCAD shows them in model space)px_per_mm: f64fonts: Option<&'a dyn Fn(Family) -> Option<&'a [u8]>>-- the bytes of a family of the repository's fonts (None, or a family without bytes: Family::Sans's; no fonts: no text)limits: d::Limitsgroups: bool-- keep which render2d entities came from one DXF entity (Loaded::group_of, members; 12 bytes per entity)max_layers: u32-- render2d layers at most for the runs of DXF layers (beyond: an entity goes to the last run of its layer, the order across layers then approximate)order: i32-- the order of the first render2d layer (the next ones count up)
impl<'a> Options<'a>
fn new() -> Options<'a>struct Countwhat happened to the entities of one DXF kind (an entity in a block once, however often it is inserted)read: u64-- read (top level and in blocks), of which drawn (one render2d entity or more), skipped in paper space, hidden (invisible, or in a block on a layer that is off or frozen), unsupported (a kind this module does not draw), failed (render2d refused its geometry, or there was none), approximated (drawn, but simplified: see the notes)drawn: u64paper: u64hidden: u64unsupported: u64failed: u64approximated: u64
struct LayerOfa DXF layer: its render2d layers (one per run of entities on it, in order), whether it is shownname: Stringruns: Vec<LayerId>visible: booltransparency: u32
struct Loadedwhat a drawing becameheader: d::Headerlayers: Vec<LayerOf>extents: Option<[f64; 4]>-- the box of what was drawn in model space (min x, min y, max x, max y), without rays and xlineskinds: BTreeMap<String, Count>-- per DXF kindentities: u64-- render2d entities inserted (on layers and in blocks), blocks madeblocks: u32stats: d::Stats-- the reader's counts and notesnotes: Vec<String>-- what was simplified or skipped, each once (at most 64)
impl Loaded
fn group_of(&self, id: EntityId) -> Option<u32>the DXF entity a render2d entity on a layer came from (Options::groups): its group, numbered from 1 in the order of the drawing's entities that drew somethingfn members(&self, g: u32) -> &[EntityId]the render2d entities a DXF entity became (group_of)fn set_layer_visible(&mut self, scene: &mut Scene, name: &str, on: bool) -> gpu::Result<bool>a DXF layer shown or hidden: its render2d layers (entities of blocks on other layers keep what they had when they were read: docs/RENDER2D.md "DXF")fn load(scene: &mut Scene, bytes: &[u8], o: &Options) -> Result<Loaded, d::Error>a drawing in memory into a scenefn read(scene: &mut Scene, source: &mut dyn FnMut(&mut [u8]) -> usize, o: &Options) -> Result<Loaded, d::Error>a drawing read piece by piece into a scene (::dxf::read: only the tables and blocks are kept)fn linetype_pattern(src: &[f64], scale: f64, max: usize) -> Option<(Vec<f64>, f64)>a linetype's or hatch line's dashes as DXF has them (positive on, negative off, 0 a dot), scaled, as render2d's pattern (on, off, ... at mostmaxentries) and its phase; None: solid (no gap in it). Runs of one sign merge, a leading gap moves to the end (the phase says where an entity starts), too many entries lose their shortest dashes (dots first) to the gaps around them, so the period stays