text

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 8 Imported by: 0

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

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

func Fill

func Fill(dst *image.RGBA, col color.Color)

Fill paints the whole image a single colour — a convenience for clearing a frame to a background before drawing text.

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 Default

func Default(points float64) *Face

Default returns a proportional Face (Go Regular) at the given point size.

func DefaultMono

func DefaultMono(points float64) *Face

DefaultMono returns a monospace Face (Go Mono) at the given point size — ideal for editors, terminals and code/log viewers.

func NewFace

func NewFace(ttf []byte, points float64) (*Face, error)

NewFace parses TrueType/OpenType font bytes and returns a Face at the given point size.

func (*Face) Advance

func (f *Face) Advance(s string) int

Advance returns the horizontal advance width of s in pixels — the x distance the pen moves after drawing it.

func (*Face) Ascent

func (f *Face) Ascent() int

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) Close

func (f *Face) Close() error

Close releases the Face's resources. The Face must not be used afterwards.

func (*Face) Covers

func (f *Face) Covers(r rune) bool

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

func (f *Face) Descent() int

Descent is the distance from the baseline to the bottom of the line, in pixels.

func (*Face) Draw

func (f *Face) Draw(dst *image.RGBA, x, y int, s string, col color.Color) int

Draw renders s into dst with its baseline at (x, y) in colour col, and returns the x coordinate just past the drawn string (x + advance) so calls can be chained on a line.

func (*Face) Height

func (f *Face) Height() int

Height is the line height (ascent + descent) in pixels, a good default vertical step between lines of text.

Jump to

Keyboard shortcuts

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