diagram_io/src/vdx/mod.rs#
Source: lib/diagram_io/src/vdx/mod.rs
vdx -- the XML formats of Visio 2003-2010 ("DatadiagramML": .vdx drawing, .vsx stencil,
.vtx template) read into diagram_core's model (DF-20, DF-21, DF-22; JD16)
vdx::read(&bytes, DocKind::Drawing, &vsdx::Limits::VSDX) -> Result<vsdx::Loaded, vsdx::Error>
one file of the format; the caller says by its extension what it is
(kind_of): the XML itself does not
vdx::kind_of("vsx") -> Some(DocKind::Stencil) the kind of an extension (vdx vsx vtx)
vdx::sniff(&bytes) -> bool whether the bytes are such a file (root VisioDocument in
the namespace http://schemas.microsoft.com/visio/2003/core)
The model is the one vsdx.rs fills, so a file read here is written as a .vsdx, .vssx or .vstx
(a .vsdm ... with a macro project) by vsdx::write. Microsoft's public "XML for Visio"
schema reference describes the format; nothing of other implementations is used. What goes
where:
cells an element per cell (<PinX F='..' Unit='MM' Err='..'>1.5</PinX>): the text is
the value in internal units, F the formula ("Inh", "No Formula" as in VSDX),
Unit the unit (VSDX's U), Err the error (E). Formula and value stay a pair,
nothing is computed (V1)
single-row sections (XForm, Line, Fill, TextBlock, Misc, PageProps ...) flattened into the
sheet's cells, the names are VSDX's (Char.Locale and Char.Perpendicular, gone
since Visio 2003, are left out)
rows Char -> Character, Para -> Paragraph, Prop -> Property, Act -> Actions,
SmartTagDef -> ActionTag; User, Control, Connection, Scratch, Field, Layer,
Hyperlink, Reviewer, Annotation by their names. Named rows take NameU, else
Name, else Row_<ID> (as Visio names them); Connection rows get T='Connection'
(Visio's previewer hangs on rows without it, JD13)
Geom a Geometry section per element (IX = its index), NoFill .. NoQuickDrag its
cells, MoveTo, LineTo ... its rows (T = the element, IX as written)
Tabs the row stays, its tab stops are left out (Warning::LeftOut "Tab": VSDX
names their cells differently, and the model draws no tabs yet)
fonts the Font cells of Character rows (Font, AsianFont, ComplexScriptFont) and
Paragraph's BulletFont hold a FaceName ID in this format and a font name in
VSDX: the ID becomes the name; FaceName Name / Panos become NameU / Panose
pictures ForeignData's base64 becomes a part /visio/media/imageN.<ext> by what the bytes
are (PNG, JPEG, GIF, TIFF, BMP, EMF, WMF; a bitmap without file header gets
one); anything else is left out with a warning
masters, pages their elements with sheet, icon, shapes and connects; the writer gives them
parts of their own
DocumentProperties docProps core.xml, app.xml and custom.xml (props.rs); Visio's own
entries (AlternateNames, BuildNumber*, TimeEdited, the root's metric) as the
custom properties Visio writes in VSDX
Windows windows.xml as VSDX has it (same elements), EventList and HeaderFooter the
document element's own children as in VSDX
VBProjectData base64 of the macro project: when it is an OLE file it becomes
/visio/vbaProject.bin and Document::macros is set (written as .vsdm, never run);
anything else is left out with a warning
everything else (SolutionXML, DataConnections, DataRecordsets, the preview picture, elements
of other namespaces) has no place in a VSDX file: left out, Warning::LeftOut
Unknown attributes are dropped: this reader converts, it does not keep the file's XML (DF-23,
writing .vdx, is not planned).
Every file is untrusted input, bounded like a VSDX file (vsdx::Limits): the file's size by
Limits::zip.part_bytes, nesting and attributes by the XML reader, counts of shapes, cells,
rows, sections, objects and items, the length of formulas and texts, each picture by the
file's size. Cycles of styles, masters and background pages are refused as in vsdx.rs, a
reference that names nothing is a warning. No DOCTYPE, no external anything, no recursion
(groups at any depth go through a stack of their own), never a panic.
fn kind_of(ext: &str) -> Option<DocKind>the kind of document an extension of the format stands for ("vdx", "vsx", "vtx"; ASCII case ignored)fn sniff(bytes: &[u8]) -> boolwhetherbytesare a file of this format: XML whose root is VisioDocument in the namespace of 2003 (only the start is read)fn read(bytes: &[u8], kind: DocKind, limits: &Limits) -> Result<Loaded, Error>read a file of the XML format of 2003-2010 as a document ofkind(see the module comment);limitsbound everything (vsdx::Limits::VSDX for real files)