JFLib

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 ShapeKind the shape type (attribute Type)
    • Shape -- Shape: a shape with geometry
    • Group -- Group: has subshapes
    • Foreign -- Foreign: shows its ForeignData (a picture, a metafile, an OLE object's image)
    • Guide -- Guide: a guide line or guide point, not shown
    • Unspecified -- 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) -> ShapeKind the kind of a Type attribute

  • fn as_str(self) -> Option<&'static str> the Type attribute (None: Unspecified or Other, whose Sym holds it)

  • struct StyleRefs the style IDs a sheet inherits from (LineStyle, FillStyle, TextStyle); for a style these are the styles it is based on

    • line: Option<u32> -- LineStyle
    • fill: Option<u32> -- FillStyle
    • text: Option<u32> -- TextStyle

impl StyleRefs

  • const fn all(id: u32) -> StyleRefs all three the same style

  • fn get(&self, cat: Category) -> Option<u32> the style of a category

  • fn uses(&self, id: u32) -> bool whether id is one of the three

  • struct ShapeHeader the attributes of a shape

    • kind: ShapeKind -- Type
    • name: 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: derived
    • is_custom_name: Option<bool> -- IsCustomName as written
    • is_custom_name_u: Option<bool> -- IsCustomNameU as written
    • master: Option<u32> -- Master: the ID of the master this shape is an instance of
    • master_shape: Option<u32> -- MasterShape: the ID of the shape in the master that this subshape inherits from
    • styles: StyleRefs -- LineStyle, FillStyle, TextStyle
    • del: bool -- Del="1": the subshape the master passes on is deleted here
    • original_id: Option<u32> -- OriginalID as written
    • unique_id: Option<Sym> -- UniqueID as written
  • enum TextItem one item of a shape text

    • Chars(Box<str>) -- characters
    • Cp(u32) -- cp IX: from here on the Character row IX applies
    • Pp(u32) -- pp IX: from here on the Paragraph row IX applies
    • Tp(u32) -- tp IX: from here on the Tabs row IX applies
    • Field(u32) -- fld IX: the text field of Field row IX
    • Other(Sym) -- an element the crate does not know, as XML text
  • struct Text the text of a shape (element Text)

    • items: Vec<TextItem> -- characters and marks in file order
    • extras: Extras -- unknown attributes of the Text element

impl Text

  • fn plain(text: &str) -> Text a text of plain characters

  • fn chars(&self) -> String the characters without marks (fields left out)

  • enum ForeignPayload where the picture of a Foreign shape is

    • None -- none
    • Inline(Box<str>) -- inline, base64 as written
    • Part(Sym) -- a part of the package (its name, e.g. /visio/media/image1.png)
  • struct ForeignData the picture data of a Foreign shape (element ForeignData)

    • attrs: Vec<(Sym, Sym)> -- the attributes in file order (ForeignType, CompressionType, ObjectWidth ...)
    • payload: ForeignPayload -- the data
    • extras: Extras -- unknown children
  • struct ShapeData one shape without its subshapes

    • header: ShapeHeader -- the attributes
    • sheet: Sheet -- the ShapeSheet: only what the shape sets itself, the rest is inherited
    • text: Option<Box<Text>> -- the text; None: inherited from the master shape (or none)
    • foreign: Option<Box<ForeignData>> -- the picture of a Foreign shape
    • data: [Option<Sym>; 3] -- Data1, Data2, Data3 as written
    • extras: Extras -- unknown items of the Shape element

impl ShapeData

  • fn new(kind: ShapeKind) -> ShapeData a 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 TreeError why a shape could not be put into a tree

    • DuplicateId(u32) -- another shape of the tree has this ID
    • NoParent -- the parent slot holds no shape
  • struct ShapeTree the shapes of a page or a master

impl ShapeTree

  • fn new() -> ShapeTree an 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 under parent (None: top level), on top of its siblings -> its slot (untracked: no undo step; loaders build trees with it); NO_ID may repeat

  • fn get(&self, slot: u32) -> Option<&ShapeData> the shape in a slot

  • fn id(&self, slot: u32) -> Option<u32> the file ID of the shape in a slot

  • fn 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-order

  • fn parent(&self, slot: u32) -> Option<u32> the group a shape belongs to (None: top level or no shape)

  • fn len(&self) -> usize the number of shapes (all levels)

  • fn is_empty(&self) -> bool whether the tree has no shapes

  • fn 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-order

  • fn is_within(&self, mut slot: u32, ancestor: u32) -> bool whether slot is ancestor or lies inside it

  • struct TreeIter<'a> the slots of a tree, groups before their subshapes (ShapeTree::iter)

Source: docs/API.md in the JFLib repository.