mermaid.glyph

index · mermaid

Overview

The glyph painter: a frame drawn in box characters, for a terminal that shows no image. It takes the rows and columns the pixel painter takes.

Each cell holds a mask of the directions its line leaves in: north 1, east 2, south 4, west 8. A stroke ORs its directions into the cells it crosses, so two routes that merge make a tee and two that cross make a cross, with no rule for either. The mask picks the character.

Where strokes of two weights share a cell, the heavier draws it: thick over solid over dotted. A cell keeps the style of the first stroke that entered it.

A shape with no box character form is drawn by its nearest one in the same cells: a slash for a slanted side, a parenthesis for a round one.

Functions

NameSignature
paintpaint(frame) -> rows

paint(frame) -> rows

Paint a frame in box characters

Returns one entry per row of the frame, each { runs = { ... } }. A run is { c, text, style, w }: its first column, its characters, the style name of the element that drew it, and its width in columns. The cells between two runs are blank. rows.cols is the frame's width.

The frame must pass mermaid.frame.check. A text that starts under an earlier text's cells is dropped.