Documentation
¶
Overview ¶
Package text measures text for the layout of zuzu (D11).
The okage peer writes the API that measures and shapes text as okage does, when zuzu needs it. Until then, Estimate measures a string from the advance widths of the bundled IBM Plex Sans (D16), with no shaping and no kerning. The layout depends on the interface Measurer, so that the measurement of okage can take its place.
A Fallback is a font for the characters that IBM Plex Sans does not have. The package text/emoji gives one with the emoji of Noto Color Emoji (D32). A character that no font has draws nothing and measures as nothing.
Index ¶
- Constants
- Variables
- func Fonts() fs.FS
- func HasMath(s string) bool
- func MathCommand(err error) string
- func Truncate(m Measurer, f Font, s string, limit float64) string
- func Weight(s string) int
- type Estimate
- type Fallback
- type Font
- type Formula
- type MathFont
- type MathLine
- type MathPath
- type Measurer
- type Piece
- type Run
Constants ¶
const Ellipsis = "…"
Ellipsis is the text that Truncate puts at the end of a cut string, as Vega does.
const EmojiFamily = "Noto Color Emoji"
EmojiFamily is the family of the font of the package text/emoji. The SVG writer names it for a text that holds a character that IBM Plex Sans does not have, so that a viewer draws an emoji in color (D32).
const Family = "IBM Plex Sans"
Family is the family of the bundled font.
const MathGap = 3.0 / 18
MathGap is the space between a run of text and a run of math, in ems of the font of the text: a thin space of TeX.
Variables ¶
var ErrNoMathFont = errors.New("no font of math")
ErrNoMathFont is the error of a run of math with no font of math, which zuzu.WithMath gives.
Functions ¶
func Fonts ¶
Fonts returns the bundled fonts and their license, so that a renderer such as okage can load them. The files are in the folder fonts. The six faces are one TrueType collection, IBMPlexSans.ttc. The package embeds the collection in WOFF2 and decodes it on the first call (D34).
func MathCommand ¶ added in v0.7.5
MathCommand returns the command of TeX that an error of Layout names, such as \phase, or empty when it names none.
Types ¶
type Estimate ¶
type Estimate struct {
// contains filtered or unexported fields
}
Estimate measures text from the advance widths of the bundled font. It does not shape or kern, so a measured width can differ from the width that a renderer draws by a little. Each family measures as IBM Plex Sans, or as the main font of SetMain where it has the character. A character that neither has measures in the first fallback that has it, and as nothing when no fallback has it. It is safe for concurrent use, and it keeps the widths it measured.
func NewEstimate ¶
NewEstimate returns an Estimate, with the fallbacks for the characters that the bundled font does not have, in order.
func (*Estimate) Missing ¶ added in v0.6.0
Missing returns the characters of s that neither the bundled font nor a fallback has, each once, in the order of s. Such a character draws nothing. A character that draws nothing in any font, such as a space, a control character, a joiner or a selector of a variation, is never missing.
func (*Estimate) SetMain ¶ added in v0.8.0
SetMain gives the Estimate a main font, which measures each character that it has before the bundled font, in each family, weight and style. The look like Excalidraw measures its text in Excalifont this way, with IBM Plex Sans for the characters that Excalifont does not have (D40). A nil font measures in the bundled font. Call it before the first measure.
func (*Estimate) SetMath ¶ added in v0.7.5
SetMath gives the Estimate a font of math, which lays out the math of KaTeX in a label of Mermaid (D36). A nil font draws no math.
func (*Estimate) Split ¶ added in v0.6.0
Split splits s into pieces that each draw in one kind of font: the characters of the bundled font, or a sequence of the characters of the fallbacks with the characters that join them, such as a joiner, a selector of a variation or a modifier of skin tone. okage falls back to another font for one character at a time, and it draws a sequence of emoji, such as a flag, as one glyph only when it shapes the sequence on its own, so a renderer shapes each piece apart (D32). A string with no character of a fallback is one piece.
type Fallback ¶ added in v0.6.0
type Fallback struct {
// contains filtered or unexported fields
}
Fallback is a font for the characters that IBM Plex Sans does not have, such as the font of the package text/emoji (D32). It is safe for concurrent use, and it decodes and parses its font once, on its first use.
func NewFallback ¶ added in v0.6.0
NewFallback returns a fallback of a family from the bytes of a font file: TrueType, OpenType, WOFF, WOFF2 or EOT (D34). The bytes must not change after the call.
func (*Fallback) Data ¶ added in v0.6.0
Data returns the bytes of the font as a TrueType or OpenType file, so that a renderer such as okage can load it. It decodes a font in a web format on the first call. It returns nil when the font does not decode. Do not change the bytes.
type Font ¶
type Font struct {
Family string // the family, such as IBM Plex Sans
Size float64 // the size in pixels
Weight int // the weight, from 100 to 900, where 400 is normal
Italic bool
}
Font is a font at a size.
type Formula ¶ added in v0.7.5
type Formula struct {
Width, Height, Depth float64
// Paths are the outlines of the formula, in the syntax of the d
// attribute of SVG, relative to its origin.
Paths []MathPath
}
Formula is a formula of TeX laid out, in pixels. Its origin is the left end of its baseline. Height is its extent above the baseline, and Depth its extent below it.
type MathFont ¶ added in v0.7.5
type MathFont struct {
// contains filtered or unexported fields
}
MathFont is a font of math, with an OpenType table MATH, for the math of KaTeX in a label of Mermaid (D36). The package text/math gives STIX Two Math. A face of go-text is not safe for concurrent use, so a MathFont lays out one formula at a time.
func MathOf ¶ added in v0.7.5
MathOf returns the font of math of a Measurer that has one, such as an Estimate after SetMath, or nil.
func NewMathFont ¶ added in v0.7.5
NewMathFont returns a font of math from the data of an OpenType font with a table MATH. The font is parsed on its first use.
func (*MathFont) Layout ¶ added in v0.7.5
Layout lays out a formula of TeX at a size in pixels, in the display style, as Mermaid 12.3 asks KaTeX to (D36). A formula with no color gives one path. A formula with \color gives a path for each item, so that each keeps its color. An error of the parse wraps okage.ErrTeXMathSyntax, and MathCommand names the command of it.
type MathLine ¶ added in v0.7.5
MathLine is a line of a label with math, laid out as Mermaid 12.3 lays it out: a row of its runs, each centered on the middle of the line, with no wrap. Height is the larger of the height of a line of text, when the line has text, and the height and the depth of its tallest formula. So a line of math alone is as high as its formula (D36).
func LayMathLine ¶ added in v0.7.5
LayMathLine lays out a line of a label with runs of math in a font, with a line of text lineHeight high. Mermaid draws each run as an item of a row, which drops the spaces at its ends, so a run of text loses them, and a run of spaces alone draws nothing. A thin space of 3/18 of the size of the font stands between a run of text and a run of math, so that the two do not touch (docs/STYLE.md). A run of text measures with m, and a run of math lays out in the font of math of m at the size of the font. A run of math that does not lay out gives its error, and the line is nil.
type MathPath ¶ added in v0.7.5
MathPath is an outline of a formula and its color. An empty color is the color of the text around the formula.
type Piece ¶ added in v0.7.5
Piece is a run of a line of a label laid out. X is its offset from the start of the line, and W its width. A piece of math holds its formula, whose baseline is Baseline below the middle of the line.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package math gives STIX Two Math, a font of math under the SIL Open Font License 1.1, so that zuzu draws the math of KaTeX in a label of Mermaid (D36).
|
Package math gives STIX Two Math, a font of math under the SIL Open Font License 1.1, so that zuzu draws the math of KaTeX in a label of Mermaid (D36). |