Documentation
¶
Overview ¶
Package text is a minimal pure-Go text-rendering layer for wlui apps.
It rasterizes TrueType/OpenType fonts (via golang.org/x/image/font/opentype) and draws anti-aliased strings into an *image.RGBA — the same buffer a wlui.Handler paints each frame. No cgo, no fontconfig, no FreeType C library; the embedded Go fonts mean an app needs no font files on disk to render text.
face := text.DefaultMono(14) face.Draw(buf, 8, 8+face.Ascent(), "hello, world", color.Black)
Index ¶
Constants ¶
const DPI = 72
DPI is the rendering resolution used to convert point sizes to pixels. 72 dpi makes one point equal one pixel, which is convenient for laying out UIs in pixel units.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Face ¶
type Face struct {
// contains filtered or unexported fields
}
Face is a font rasterized at a specific size, with cached line metrics.
func DefaultMono ¶
DefaultMono returns a monospace Face (Go Mono) at the given point size — ideal for editors, terminals and code/log viewers.
func NewFace ¶
NewFace parses TrueType/OpenType font bytes and returns a Face at the given point size.
func (*Face) Advance ¶
Advance returns the horizontal advance width of s in pixels — the x distance the pen moves after drawing it.
func (*Face) Ascent ¶
Ascent is the distance from the baseline to the top of the line, in pixels. Add it to a line's top y to get the baseline to pass to Draw.
func (*Face) Covers ¶
Covers reports whether the face has a glyph for r. Callers can use it to drop or substitute unrenderable runes (e.g. emoji, which the Go fonts lack) rather than draw .notdef "tofu" boxes.
func (*Face) Descent ¶
Descent is the distance from the baseline to the bottom of the line, in pixels.