diagram_io/src/stencil.rs#
Source: lib/diagram_io/src/stencil.rs
stencil -- the stencil build tool (JD9): the text sources of a stencil into a stencil document
and a .vssx file
stencil::build(&files, Measure::Metric) -> Result<Built, SourceError>
stencil::build_vssx(&files, Measure::Us) -> Result<(Built, Vec<u8>), SourceError>
Built { doc, stencil, file, category, measure } the stencil document (DocKind::Stencil),
its universal name, the output stem, the category
built.vssx_name() "jfd_standard_m.vssx" / "jfd_standard_u.vssx"
file_name(stem, Measure) / parse_file_name(name) (JD13) the file names of JFDiagrammer's
own stencils: the prefix "jfd_" keeps them apart from
Visio's (its ARROWS_M.VSSX is not our arrows_m)
SourceError { file, line, message } shown as "rectangle.master:12: unbekannter
Abschnitt [Geometrie]" (line 0: the whole file)
`files(name)` gives the text of "stencil.txt", of "<stem>.master" and of an SVG file named by
a master, all of one stencil folder (None: there is none). The source format, and what goes
into the file, is apps/JFDiagrammer/stencils/README.md; the app's build.rs calls this for each
stencil and both measures. The parser is stencil_src.rs, the SVG import stencil_svg.rs, the
icons stencil_icon.rs.
How a stencil is built, in this order:
1. stencil.txt and every master file are parsed and checked for the chosen measure: header
keys, sections, row heads, cell names (each section's own list), the five languages of
every language-suffixed key or cell, Width and Height as lengths or formulas (a box that
fits its text: TEXTHEIGHT ...; not with svg:) (a 1-D master: BeginX, BeginY, EndX, EndY as
lengths and Height), formulas that parse and call only functions the engine knows. A
".metric" / ".us" line replaces the line without suffix.
2. A new stencil (vsdx::new_document: the own styles and the NetLab theme) gets the masters in
one transaction: the Master attributes (Name and Prompt in the build language,
IsCustomName(U), IconSize 1, AlignName 2, MatchByName 0, IconUpdate 1, PatternFlags 0 (1026
with `line_end: true`, JD29),
Hidden 0 (1 with the header key `hidden: true`: a master the Shapes panel does not show,
which code drops), MasterType 2, BaseID and UniqueID), the master page (PageWidth / PageHeight =
the shape's size, scale 1:1 in mm or in, ShapeKeywords, the JFD_ User cells), the master
shape with its cells, sections, text and the SVG geometry. Constants are written as values
with their unit (lengths in inches with U = MM, IN ...), everything else as a formula; the
tool adds PinX / PinY (half the size), LocPinX = Width*0.5, LocPinY = Height*0.5. A 1-D
master (one that sets BeginX ...) gets Visio's 1-D formulas instead: PinX =
GUARD((BeginX+EndX)/2), Width = GUARD(SQRT(...)), Angle = GUARD(ATAN2(EndY-BeginY,
EndX-BeginX)), LocPin = GUARD(Width*0.5) ...; its master page is BeginX+EndX wide and
BeginY+EndY high.
3. Every reference of every formula must name something that is there (a cell of the sheet
or of its styles, a single cell of the ShapeSheet's own list, Sheet.N of the master). The
formula engine computes every formula and its values are stored: a cell the engine keeps
(unknown function, unknown section, cycle) or that comes out as an error is a build error
naming the source line. No stale value goes into the file. A master whose Width or
Height is a formula gets its master page and pin from the computed size afterwards.
4. Each master's icon is rendered from an instance on the stencil's page (stencil_icon.rs);
the instance goes again, the page stays empty.
The GUIDs are name-based (SHA-1, RFC 4122 version 5, namespace of this tool): BaseID from the
stencil's NameU, the master's NameU and the measure; UniqueID from the same and the master's
content as built (the resolved lines, the SVG, the build language, the quick flag, the tool's
version), so an unchanged master keeps its UniqueID and a changed one gets a new one (MS-02).
Upper case in braces, as Visio writes them. The same sources always give the same document
and the same bytes.
The JFD_ cells (diagram_core::instance reads them): the document sheet's User.JFD_Name (the
title in de|en|es|it|fr) and User.JFD_Category; per master page User.JFD_Name, JFD_Prompt,
JFD_Keywords, JFD_Text, JFD_Quick (1 for the first `quick` masters) and JFD_Tr1, JFD_Tr2 ...
("Section.Row.Cell|de|en|es|it|fr" with VSDX section and cell names: Control.Row_1.Prompt; a
source's Tip of a control point is the VSDX cell Prompt, JD21).
(JD15) Text fields: a [Field] section (Value, Format, Type ...; `Unit = mm` gives Value the unit
the field shows) and "{fld N}" marks in a master's text (diagram_core::field::marked); a mark
without its row is a build error.
Sources are files of the repository, trusted but checked all the same: no panic on any input,
counts bounded, no recursion.
struct Builta stencil built from its sourcesdoc: Document-- the stencil (DocKind::Stencil)stencil: String-- its universal name (stencil.txtstencil)file: String-- the stem of the output files (stencil.txtfile)category: String-- the category in "Weitere Shapes" (stencil.txtcategory)measure: Measure-- the measure it was built for
impl Built
fn vssx_name(&self) -> Stringthe file name of the .vssx:jfd_<file>_m.vssx(metric) orjfd_<file>_u.vssx(US)
/// the prefix of the file names of JFDiagrammer's own stencils (JD13, the user's choice): a
/// template names its stencils by file name (windows.xml), and Visio opens a stencil of its own
/// of that name if it has one, so ours never share a name with Visio's (ARROWS_M.VSSX)
FILE_PREFIX: &str = "jfd_"
fn file_name(stem: &str, m: Measure) -> Stringthe file name of the built stencil with stemstem(stencil.txtfile) in measurem: "jfd_standard_m.vssx", "jfd_standard_u.vssx"fn parse_file_name(name: &str) -> Option<(String, Measure)>the stem and measure of a file name file_name gives (a path before it and ASCII case do not count: "C:/x/JFD_Standard_U.VSSX" -> ("standard", Us)); None for every other name, also for Visio's own stencilsstruct SourceErrorwhy a stencil did not build: the source file, the line (from 1; 0: the whole file) and whyfile: String-- the file in the stencil's folder ("rectangle.master")line: u32-- the line, from 1 (0: the file as a whole)message: String-- what is wrong
/// the categories of "Weitere Shapes" a stencil may name
CATEGORIES: [&str; 9] = ["general", "flowchart", "business", "engineering", "netw ...
fn build(files: &dyn Fn(&str) -> Option<String>, measure: Measure) -> Result<Built, SourceError>build the stencil of one folder for one measure (see the module comment)fn build_vssx(files: &dyn Fn(&str) -> Option<String>, measure: Measure) -> Result<(Built, Vec<u8>), SourceError>build the stencil and write it as .vssx bytes (vsdx::write with the default options)