Documentation
¶
Index ¶
Constants ¶
const LineHeight = 1.5
LineHeight is the height of a line, in ems.
const WrappedLineHeight = 1.3
WrappedLineHeight is the height of a line of a label of more than one line, in ems: its lines sit closer, so that it reads as one block.
Variables ¶
This section is empty.
Functions ¶
func DecodeEntities ¶
DecodeEntities turns Mermaid's `#35;` and `#quot;` codes, as Mermaid hides them, and HTML entities into characters.
Types ¶
type Face ¶
type Face uint8
Face is how a run of text is set: bold, italic, monospaced, lowered or raised a little and smaller, underlined, or a mix. Its bits are those of Pele's Style.
type Label ¶
type Label struct {
Lines [][]Span
Widths []float64 // of each line
Width float64 // of the widest line
Height float64
Size float64
LineHeight float64
}
A Label is text laid out in lines to a width, measured.
func Layout ¶
Layout lays out a label as Pele's layoutLabel does: <br> and new lines break it, <b>, <strong>, <i>, <em>, <code>, <sub>, <sup>, <u> and their kin set its faces (tagFaces), as do ** and _ in markdown, other HTML tags are dropped, fa:fa-name is an icon, entities are decoded, and lines wider than MaxWidth wrap between words, between any two Chinese or Japanese characters, and at a zero-width space or a soft hyphen. A label of more than one line has lines WrappedLineHeight high.
type Measurer ¶
A Measurer gives the advance width of text set in a face at a size, in the units the diagram is laid out in. Layout depends on it, so a diagram is drawn in the faces it was measured in. Layout asks it only of Bold, Italic and Mono: it measures a Sub or Sup span at the smaller size it is set at, and an underline takes no room.
var Arial Measurer = arial{}
Arial estimates widths from a table of Arial's advances, with no font at hand. Wide East Asian characters take an em, other characters past ASCII 0.58 of one, and monospaced text 0.6 of an em a character. Its widths are those of Pele's metricsMeasurer, to the last bit.
type Options ¶
type Options struct {
Measurer Measurer
Size float64
MaxWidth float64 // lines longer than this are wrapped; 0 is no limit
Face Face // of text with no emphasis of its own
Markdown bool // read **bold** and _italic_
// Icons reports whether the host can draw an icon by name. A label leaves room for an
// icon only where it can; with nil, it never does.
Icons func(name string) bool
// Bounded takes MaxWidth as it is even at 0 or below, as Pele's layoutLabel does: a width
// worked out to fit text in a box of a set size can come out at nothing or less.
Bounded bool
}
Options says how to lay out a label.