JFLib

diagram_core/src/render/mod.rs#

Source: lib/diagram_core/src/render/mod.rs

render -- a page as a display list (JD4, milestone "viewer"): what is drawn where, in which
order, with which look; the drawing itself is someone else's (diagram_view on render2d and
gfx, later the exports of diagram_io)

  render::build(&doc, page, &mut measure, &Options) -> Drawing
  render::rebuild(&doc, &mut drawing, &mut measure, &Options, &shapes) -> bool
                                  (JD7, rebuild.rs) the items of some top-level shapes made
                                  anew in their place; false: shapes came, went or changed
                                  their order (build anew)
  render::affected(&doc, &drawing, &Options, &shapes) -> tops   (JD21) the top-level shapes
                                  rebuild makes anew for these shapes
  Drawing { width, height, scale, items, fonts, notes }   in paper inches, y up, the origin at
                                  the page's bottom left corner; items in painter's order
  drawing.query(rect, &mut out)   the items whose boxes touch a rectangle (a grid over the
                                  page: culling and hit tests without looking at every item)
  drawing.range_of(top) / tops()  the items of a top-level shape: they lie together
  Item { shape, top, bbox, role, kind }   role: Shape | Arrow | Shadow | Text; kind: Fill { path, paint } | Stroke { path, stroke } |
                                  Text(TextItem) | Image(ImageItem)
  Paint::Solid | Hatch | Gradient, Stroke { color, width, dash, cap, join }
  Measure / Face / ApproxMeasure  (text.rs) what the text layout asks of fonts
  measure_text(&mut measure, &face, size, text, max_width)   (text.rs) a text's size as the
                                  layout wraps it (the formula engine's TEXTWIDTH, JD7)
  ThemeInfo                       (theme.rs) colours and fonts of a theme part
  style::{dash, fill_pattern, arrow, PALETTE}   the tables behind lines and fills

Everything comes from the cached values (decision: the viewer shows what the file cached,
the formula engine of JD6 is not needed).  Per page: its background page first (and theirs),
then its shapes in z-order; a group draws its children and its own geometry and text behind
them (DisplayMode 1) or in front (2, the default; 0 hides the group's own geometry).  Per
shape: the shadow (ShdwPattern above 0, offset by ShapeShdwOffsetX/Y), the fill of all
closed sub-paths of the Geometry sections without NoFill (even-odd), a Foreign shape's
picture, the lines of the sections without NoLine with their line ends, the text.  Not
drawn: deleted subshapes (Del, ID 4294967295, no Type), guides, sections with NoShow,
shapes whose layers are all hidden.  A layer's colour (Color not 255) colours its members.
(JD21) Line jumps are rows of the connectors' Geometry (crate::jumps writes them when
connectors are laid): drawn as the rest of the geometry.

Values Visio caches as "Themed" (the Theme style and a few shapes) are resolved against the
page's theme: the theme part whose schemeEnum the page's ThemeIndex names (colours by
ColorSchemeIndex, fonts by FontSchemeIndex), the QuickStyle colour indices of the shape, the
variation of VariationColorIndex; the rest falls back to plain values (solid, 0.75 pt,
no gradient, no shadow).  On a page with a drawing scale, geometry is in drawing units and
line weights, text sizes and margins are in page units: the display list is in paper
inches (geometry times PageScale / DrawingScale).
  • struct Options what build draws

    • background: bool -- draw the page's background pages under it
    • hidden_layers: bool -- draw shapes on hidden layers too
    • print: bool -- (JD8 rest) the page as printed and exported: shapes on layers that do not print (Layer row Print 0, LY-02) and shapes with NonPrinting set are left out
  • struct Drawing a page as items to draw

    • page: Option<PageRef>
    • width: f64 -- the page's size in paper inches
    • height: f64
    • scale: f64 -- paper inches per drawing inch (PageScale / DrawingScale)
    • color: u32 -- the page's colour (0xRRGGBB)
    • items: Vec<Item>
    • fonts: BTreeSet<String> -- the font families the texts ask for
    • notes: Vec<(Note, u32)> -- what was left out or drawn only roughly, with counts

impl Drawing

  • fn query(&self, rect: [f64; 4], out: &mut Vec<u32>) the items whose boxes touch rect (x0, y0, x1, y1, paper inches), ascending

  • fn bounds(&self) -> Option<[f64; 4]> the box of all items (None: nothing to draw)

  • fn range_of(&self, top: ShapeRef) -> Option<Range<usize>> the items of a top-level shape (they lie together in painter's order; empty when it draws nothing); None: not a top-level shape of this drawing

  • fn tops(&self) -> impl Iterator<Item = (ShapeRef, Range<usize>)> + '_ the top-level shapes in painter's order (those of the background pages first) with their items

  • enum Note what the viewer does not draw (yet), or draws only roughly

    • Metafile -- a picture in a format the drawing side does not decode (EMF, WMF, OLE): a placeholder
    • NoPicture -- a Foreign shape without picture data
    • CompoundLine -- a double or triple line (CompoundType): drawn single
    • LineGradient -- a line gradient: drawn in the first stop's colour
    • Effects -- 3D, bevel, glow, reflection, soft edges, sketch: left out
    • CustomLinePattern -- a line pattern of a master (LinePattern above 23): drawn solid
    • Guide -- a guide: not drawn
    • SimpleShadow -- a shadow drawn without blur, oblique type or scale
  • struct Item one thing to draw

    • shape: ShapeRef -- the shape it belongs to
    • top: ShapeRef -- that shape's top-level group (or itself): what a click selects
    • bbox: [f64; 4] -- its box (paper inches), lines with half their width
    • role: Role -- what it is part of
    • kind: ItemKind
  • enum Role what an item draws of its shape

    • Shape -- the geometry, its fill and its lines, or the picture
    • Arrow -- a line end
    • Shadow
    • Text -- the text, its background, its underlines
  • enum ItemKind

    • Fill { path: Path, paint: Paint } -- closed sub-paths filled even-odd
    • Stroke { path: Path, stroke: Stroke }
    • Text(Box<TextItem>)
    • Image(Box<ImageItem>)
  • enum Paint how an area is filled

    • Solid(u32) -- 0xAARRGGBB
    • Hatch { color: u32, lines: Vec<(f64, f64)> } -- parallel lines in a colour (the background is an item of its own before it): angle (radians, counter-clockwise) and spacing (inches) per family
    • Gradient(Box<Gradient>)
  • struct Gradient a gradient: linear from from (position 0) to to (1), or radial around from with the radius |to - from|; stops ascending

    • radial: bool
    • from: [f64; 2]
    • to: [f64; 2]
    • stops: Vec<(f64, u32)> -- (position 0..1, 0xAARRGGBB)

impl Gradient

  • fn at(&self, t: f64) -> u32 the colour at position t (0 .. 1), straight alpha

  • enum Cap how a line ends and turns

    • Round
    • Butt
    • Square
  • enum Join

    • Round
    • Miter
    • Bevel
  • struct Stroke a line's look

    • color: u32 -- 0xAARRGGBB
    • width: f64 -- inches; 0: a hairline (one pixel)
    • dash: Vec<f64> -- lengths on and off in inches (empty: solid)
    • cap: Cap
    • join: Join
  • struct ImageItem a picture: its pixels' rectangle (0..1 by 0..1 of the picture, y up) mapped to the page, clipped to the shape's box

    • xform: Xform
    • clip: [[f64; 2]; 4] -- the shape's box on the page (the picture is cut there)
    • source: ImageSource
    • format: String -- what ForeignData says it is (CompressionType, ForeignType), lower case: "png", "jpeg", "emf", "wmf", "bmp", "gif", "tiff" ... ("" unknown); the drawing side looks at the bytes
  • enum ImageSource

    • Part(Sym) -- a part of the package: Document::parts, by name
    • Inline(Box<str>) -- base64 as the file wrote it
  • fn build(doc: &Document, page: PageRef, measure: &mut dyn Measure, opts: &Options) -> Drawing the display list of a page

  • fn parse_color(t: &str) -> Option<u32> "#RRGGBB" (also "RGB(r,g,b)") -> 0xRRGGBB

  • fn with_alpha(rgb: u32, trans: f64) -> u32 0xRRGGBB with a transparency 0 .. 1 -> 0xAARRGGBB

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