text

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const LineHeight = 1.5

LineHeight is the height of a line, in ems.

Variables

This section is empty.

Functions

func DecodeEntities

func DecodeEntities(s string) string

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, or a mix.

const (
	Bold Face = 1 << iota
	Italic
	Mono
)

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

func Layout(raw string, o Options) Label

Layout lays out a label as Pele's layoutLabel does: <br> and new lines break it, <b>, <strong>, <i> and <em> set emphasis, as do ** and _ in markdown, fa:fa-name is an icon, entities are decoded, and lines wider than MaxWidth wrap between words, and between any two Chinese or Japanese characters.

func (*Label) Empty

func (l *Label) Empty() bool

Empty reports whether the label has nothing to draw.

type Measurer

type Measurer interface {
	Width(s string, size float64, f Face) float64
}

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.

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.

type Span

type Span struct {
	Text  string
	Face  Face
	Icon  string // the icon's name, as "fa:fa-car"; Text is then empty
	Width float64
}

A Span is a run of a line in one face: text, or an icon in its place.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL