Skip to content

File format and document model

larrygram-vsdx · larrygram-model

Larrygram’s file handling is split into two layers. larrygram-vsdx reads and writes the file; larrygram-model holds the drawing in memory. The model knows nothing about XML or zip files, so other formats (such as the planned .vsd importer) load into the same model.

A .vsdx, .vssx or .vstx file is an OPC package: a zip container with [Content_Types].xml, relationship parts and XML parts, as described in Microsoft’s published [MS-VSDX] specification. The package layer handles only the container. It enforces hard limits so a malformed or hostile file cannot exhaust memory:

Limit Guards against
Number of zip entries Packages with huge part counts
Uncompressed size of one part, and of the whole package Oversized inputs
Compression ratio of one entry Zip bombs
XML nesting depth, and attributes per element Pathological XML
Entity Holds
Document Kind (drawing, stencil or template), document properties, pages, masters, stylesheets
Page Page sheet and shapes
Master A reusable shape definition from a stencil
Shape ShapeSheet sections, rows and cells; geometry; text; child shapes for groups
Stylesheet Line, fill and text styles that shapes inherit
Cell The formula, the cached value and the unit, stored separately

Every entity keeps Visio’s own identifiers (ID, NameU, Name). Inheritance from masters and stylesheets is resolved by lookup when a value is needed, never flattened on load, so a saved file keeps its inheritance.

Larrygram maps only part of the format into the model. Everything else is kept:

  1. Unknown parts stay in the package and are copied byte for byte on save.
  2. Unknown attributes and children of modeled elements are stored on the model entity and written back.
  3. Unknown elements inside supported parts are kept on the nearest modeled ancestor.

A round trip is not byte-identical (the writer generates relationship parts and attribute order its own way), but it is semantically equivalent XML. Every file in the project’s test corpus passes this check.

ShapeSheet formulas In progress

Section titled “ShapeSheet formulas ”

Each cell stores its formula as text next to its cached value. The larrygram-shapesheet crate parses, prints and evaluates formulas: it parses 976 of the 994 distinct formulas in the test corpus and prints every parsed one back unchanged, has 42 functions, resolves references across shapes, masters, pages and styles, and recalculates incrementally with cycle detection. It is not yet connected to editing, opening or saving.

larrygram-render builds a scene from cached cell values and draws it to PNG (with tiny-skia) or SVG. Text is shaped with the bundled Carlito and Selawik fonts.