JFLib

diagram_core/src/design/apply.rs#

Source: lib/diagram_core/src/design/apply.rs

apply -- a design or a variant on a page or on every page (TH-02, TH-04)

  apply(tx, eng, id, part, scope, variant)   the design whose theme part is `part` (its
                                             scheme number `id`) with a variant 0 .. 3
  set_variant(tx, eng, scope, variant)       another variant of the design the pages have
  remove(tx, eng, scope)                     no design ("Kein Design": the index cells 0)
  page_design(doc, page) -> Some((id, variant))
  part_id(bytes) / find_part(doc, id)        the scheme number of a theme part, and back

What applying does, in one transaction (one undo step; a live preview is that transaction
taken back):
1. The theme part goes into the document: a part with the same scheme number is replaced,
   else it is added as /visio/theme/themeN.xml.  Parts of JFLib's own designs that no page
   or shape names any more are dropped again; parts read from a file (Visio's designs) stay
   -- they are shown, kept and saved, never shipped.
2. Each page of the scope gets the scheme numbers of the part's components in ThemeIndex,
   ColorSchemeIndex, EffectSchemeIndex, ConnectorSchemeIndex and FontSchemeIndex (the own
   designs use one number for all; Visio's parts mix them), the variant in
   VariationColorIndex and VariationStyleIndex, EmbellishmentIndex 0 (the variant's).
3. Each shape of these pages (also inside groups) loses its own formatting of the cells a
   design sets, so that the theme shows -- as Visio does: a design overrides formatting made
   by hand.  Kept are: cells whose formula is protected (THEMEGUARD or GUARD at the top),
   cells of a kind the shape locks (LockThemeColors: colours; LockThemeEffects: line, fill
   and shadow properties; LockThemeFonts: typeface and font style; LockThemeConnectors:
   the line of a connector), the shape's own index cells while LockThemeIndex is set, and
   the QuickStyle cells (they choose within any design).  Removing a cell lets the shape
   inherit again -- from its master or its style.
4. The engine forgets the parsed theme parts and recalculates the pages and their shapes.
  • enum Scope which pages a design goes to
    • Page(PageRef) -- one page
    • All -- every page, foreground and background
/// the index cells that choose the design's parts
INDEX_CELLS: [&str; 5] = ["ThemeIndex", "ColorSchemeIndex", "EffectSchemeIndex", " ...
/// the index cells of the variant
VARIANT_CELLS: [&str; 2] = ["VariationColorIndex", "VariationStyleIndex"]
  • fn part_id(data: &[u8]) -> Option<u32> the scheme number of a theme part (its vt:themeScheme), None without one

  • fn find_part(doc: &Document, id: u32) -> Option<usize> the index into Document::themes of the part with this scheme number

  • fn page_design(doc: &Document, page: PageRef) -> Option<(u32, u32)> the design a page shows: its ThemeIndex and VariationColorIndex (None: no design)

  • fn apply(tx: &mut Transaction, eng: &mut Engine, id: u32, part: &[u8], scope: Scope, variant: u32) -> Result<Vec<SheetRef>, EditError> apply the design whose theme part is part (scheme number id) with variant 0 .. 3 to the pages of scope -> the sheets recalculated

  • fn set_variant(tx: &mut Transaction, eng: &mut Engine, scope: Scope, variant: u32) -> Result<Vec<SheetRef>, EditError> another variant of the design each page of scope shows (pages without one stay)

  • fn remove(tx: &mut Transaction, eng: &mut Engine, scope: Scope) -> Result<Vec<SheetRef>, EditError> no design on the pages of scope: the index cells 0, themed cells fall back to the root style ("Kein Design")

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