text

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const LineHeight = 1.5

LineHeight is the height of a line, in ems.

View Source
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

func DecodeEntities(s string) string

DecodeEntities turns Mermaid's `#35;` and `#quot;` codes, as Mermaid hides them, and HTML entities into characters.

func Width added in v0.3.0

func Width(m Measurer, s string, size float64, f Face) float64

Width is how wide m measures s in the face f at size, as a label's span is measured: a Sub or Sup span at size / 1.2, as Pele's measurers set it, and m asked only of Bold, Italic and Mono.

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.

const (
	Bold Face = 1 << iota
	Italic
	Mono
	Sub // set lower and smaller, as <sub> is
	Sup // set higher and smaller, as <sup> is
	Underline
)

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>, <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.

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. 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.

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