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 Optionswhat build drawsbackground: bool-- draw the page's background pages under ithidden_layers: bool-- draw shapes on hidden layers tooprint: 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 Drawinga page as items to drawpage: Option<PageRef>width: f64-- the page's size in paper inchesheight: f64scale: 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 fornotes: 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 touchrect(x0, y0, x1, y1, paper inches), ascendingfn 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 drawingfn tops(&self) -> impl Iterator<Item = (ShapeRef, Range<usize>)> + '_the top-level shapes in painter's order (those of the background pages first) with their itemsenum Notewhat the viewer does not draw (yet), or draws only roughlyMetafile-- a picture in a format the drawing side does not decode (EMF, WMF, OLE): a placeholderNoPicture-- a Foreign shape without picture dataCompoundLine-- a double or triple line (CompoundType): drawn singleLineGradient-- a line gradient: drawn in the first stop's colourEffects-- 3D, bevel, glow, reflection, soft edges, sketch: left outCustomLinePattern-- a line pattern of a master (LinePattern above 23): drawn solidGuide-- a guide: not drawnSimpleShadow-- a shadow drawn without blur, oblique type or scale
struct Itemone thing to drawshape: ShapeRef-- the shape it belongs totop: ShapeRef-- that shape's top-level group (or itself): what a click selectsbbox: [f64; 4]-- its box (paper inches), lines with half their widthrole: Role-- what it is part ofkind: ItemKind
enum Rolewhat an item draws of its shapeShape-- the geometry, its fill and its lines, or the pictureArrow-- a line endShadowText-- the text, its background, its underlines
enum ItemKindFill { path: Path, paint: Paint }-- closed sub-paths filled even-oddStroke { path: Path, stroke: Stroke }Text(Box<TextItem>)Image(Box<ImageItem>)
enum Painthow an area is filledSolid(u32)-- 0xAARRGGBBHatch { 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 familyGradient(Box<Gradient>)
struct Gradienta gradient: linear fromfrom(position 0) toto(1), or radial aroundfromwith the radius |to - from|; stops ascendingradial: boolfrom: [f64; 2]to: [f64; 2]stops: Vec<(f64, u32)>-- (position 0..1, 0xAARRGGBB)
impl Gradient
fn at(&self, t: f64) -> u32the colour at position t (0 .. 1), straight alphaenum Caphow a line ends and turnsRoundButtSquare
enum JoinRoundMiterBevel
struct Strokea line's lookcolor: u32-- 0xAARRGGBBwidth: f64-- inches; 0: a hairline (one pixel)dash: Vec<f64>-- lengths on and off in inches (empty: solid)cap: Capjoin: Join
struct ImageItema picture: its pixels' rectangle (0..1 by 0..1 of the picture, y up) mapped to the page, clipped to the shape's boxxform: Xformclip: [[f64; 2]; 4]-- the shape's box on the page (the picture is cut there)source: ImageSourceformat: 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 ImageSourcePart(Sym)-- a part of the package: Document::parts, by nameInline(Box<str>)-- base64 as the file wrote it
fn build(doc: &Document, page: PageRef, measure: &mut dyn Measure, opts: &Options) -> Drawingthe display list of a pagefn parse_color(t: &str) -> Option<u32>"#RRGGBB" (also "RGB(r,g,b)") -> 0xRRGGBBfn with_alpha(rgb: u32, trans: f64) -> u320xRRGGBB with a transparency 0 .. 1 -> 0xAARRGGBB