diagram_core/src/shape.rs#
Source: lib/diagram_core/src/shape.rs
shape -- shapes and their tree on a page or in a master
ShapeData { header, sheet, text, foreign, data, extras } one shape without its children
ShapeHeader the attributes: Type, ID-based references (Master,
MasterShape, LineStyle, FillStyle, TextStyle), Name, NameU,
Del and what else stood there
ShapeKind Shape, Group, Foreign, Guide
StyleRefs { line, fill, text } the style IDs of a shape, page sheet or style (based on)
Text / TextItem the shape text: characters between cp, pp, tp and fld marks
ForeignData picture data of a Foreign shape (inline or a package part)
ShapeTree the shapes of a page or master: slots, IDs, z-order
tree.insert(parent, id, data) -> slot (untracked; loaders build trees with it)
tree.get(slot) / by_id(id) / top() / children(slot) / parent(slot) / iter()
A shape lives in a slot of its tree; the slot is its handle (ShapeRef) and never changes,
even when the shape is deleted and the deletion undone. Slots are not reused. The file's
shape ID is unique per page or master (by_id, a BTreeMap: thousands of shapes, no linear
search). Children are kept in z-order, the last one on top.
One ID is no ID: Visio writes the deleted subshapes of an instance (Del="1", no Type) with
ID 4294967295 (NO_ID), several of them on one page. A tree takes any number of shapes with
it; by_id does not find them, they do not raise the next ID, and NO_ID is never handed out.
enum ShapeKindthe shape type (attribute Type)Shape-- Shape: a shape with geometryGroup-- Group: has subshapesForeign-- Foreign: shows its ForeignData (a picture, a metafile, an OLE object's image)Guide-- Guide: a guide line or guide point, not shownUnspecified-- no Type attribute (the deleted subshapes of an instance)Other(Sym)-- a type the crate does not know, as written
impl ShapeKind
fn parse(text: &str, strings: &mut Strings) -> ShapeKindthe kind of a Type attributefn as_str(self) -> Option<&'static str>the Type attribute (None: Unspecified or Other, whose Sym holds it)struct StyleRefsthe style IDs a sheet inherits from (LineStyle, FillStyle, TextStyle); for a style these are the styles it is based online: Option<u32>-- LineStylefill: Option<u32>-- FillStyletext: Option<u32>-- TextStyle
impl StyleRefs
const fn all(id: u32) -> StyleRefsall three the same stylefn get(&self, cat: Category) -> Option<u32>the style of a categoryfn uses(&self, id: u32) -> boolwhetheridis one of the threestruct ShapeHeaderthe attributes of a shapekind: ShapeKind-- Typename: Option<Sym>-- Name: the language-dependent name (shown); None: derived (Shape::name)name_u: Option<Sym>-- NameU: the universal name (key for formulas and matching); None: derivedis_custom_name: Option<bool>-- IsCustomName as writtenis_custom_name_u: Option<bool>-- IsCustomNameU as writtenmaster: Option<u32>-- Master: the ID of the master this shape is an instance ofmaster_shape: Option<u32>-- MasterShape: the ID of the shape in the master that this subshape inherits fromstyles: StyleRefs-- LineStyle, FillStyle, TextStyledel: bool-- Del="1": the subshape the master passes on is deleted hereoriginal_id: Option<u32>-- OriginalID as writtenunique_id: Option<Sym>-- UniqueID as written
enum TextItemone item of a shape textChars(Box<str>)-- charactersCp(u32)-- cp IX: from here on the Character row IX appliesPp(u32)-- pp IX: from here on the Paragraph row IX appliesTp(u32)-- tp IX: from here on the Tabs row IX appliesField(u32)-- fld IX: the text field of Field row IXOther(Sym)-- an element the crate does not know, as XML text
struct Textthe text of a shape (element Text)items: Vec<TextItem>-- characters and marks in file orderextras: Extras-- unknown attributes of the Text element
impl Text
fn plain(text: &str) -> Texta text of plain charactersfn chars(&self) -> Stringthe characters without marks (fields left out)enum ForeignPayloadwhere the picture of a Foreign shape isNone-- noneInline(Box<str>)-- inline, base64 as writtenPart(Sym)-- a part of the package (its name, e.g. /visio/media/image1.png)
struct ForeignDatathe picture data of a Foreign shape (element ForeignData)attrs: Vec<(Sym, Sym)>-- the attributes in file order (ForeignType, CompressionType, ObjectWidth ...)payload: ForeignPayload-- the dataextras: Extras-- unknown children
struct ShapeDataone shape without its subshapesheader: ShapeHeader-- the attributessheet: Sheet-- the ShapeSheet: only what the shape sets itself, the rest is inheritedtext: Option<Box<Text>>-- the text; None: inherited from the master shape (or none)foreign: Option<Box<ForeignData>>-- the picture of a Foreign shapedata: [Option<Sym>; 3]-- Data1, Data2, Data3 as writtenextras: Extras-- unknown items of the Shape element
impl ShapeData
fn new(kind: ShapeKind) -> ShapeDataa shape of this kind with nothing set
/// the ID of the deleted subshapes Visio writes (Del="1", no Type): no ID of its own, any number
/// of shapes of a tree may have it (see ShapeTree)
NO_ID: u32 = u32::MAX
enum TreeErrorwhy a shape could not be put into a treeDuplicateId(u32)-- another shape of the tree has this IDNoParent-- the parent slot holds no shape
struct ShapeTreethe shapes of a page or a master
impl ShapeTree
fn new() -> ShapeTreean empty tree; new shapes get IDs from 4 on ([MS-VSDX] ShapeSheet_Type: an ID is at least 4)fn insert(&mut self, parent: Option<u32>, id: u32, data: ShapeData) -> Result<u32, TreeError>add a shape with its file ID underparent(None: top level), on top of its siblings -> its slot (untracked: no undo step; loaders build trees with it); NO_ID may repeatfn get(&self, slot: u32) -> Option<&ShapeData>the shape in a slotfn id(&self, slot: u32) -> Option<u32>the file ID of the shape in a slotfn by_id(&self, id: u32) -> Option<u32>the slot of the shape with this file ID (None for NO_ID)fn top(&self) -> &[u32]the top-level shapes in z-order (bottom first)fn children(&self, slot: u32) -> &[u32]the subshapes of a shape in z-orderfn parent(&self, slot: u32) -> Option<u32>the group a shape belongs to (None: top level or no shape)fn len(&self) -> usizethe number of shapes (all levels)fn is_empty(&self) -> boolwhether the tree has no shapesfn next_id(&self) -> Option<u32>the ID the next new shape gets (None: the tree has had the ID 4294967294, no new IDs; NO_ID is never handed out)fn iter(&self) -> TreeIter<'_>every shape slot, each group before its subshapes, in z-orderfn is_within(&self, mut slot: u32, ancestor: u32) -> boolwhetherslotisancestoror lies inside itstruct TreeIter<'a>the slots of a tree, groups before their subshapes (ShapeTree::iter)