Documentation
¶
Overview ¶
Package glyphs rasterizes a monospace font family into per-character coverage masks, for Gio views that compose text into images on the CPU instead of drawing Gio text paths.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrFontNotFound = errors.New("font family not found")
ErrFontNotFound is what New fails with, where fontconfig is not installed, when no font directory holds the family it was asked for.
var ErrNoFontconfig = errors.New("fontconfig not found: fc-match is not on PATH")
ErrNoFontconfig is what fcMatch fails with when fontconfig's fc-match is not installed.
Functions ¶
func Width ¶
Width is the cells r takes in a monospace grid, as a terminal lays it out: 2 for East Asian Wide and Fullwidth characters and for emoji shown as emoji by default (Emoji_Presentation), 1 for everything else. Zero-width characters (combining marks, joiners, variation selectors) take 1 too. The table is Unicode 18.0.0's; mkwidth.go regenerates it.
Types ¶
type Mask ¶
Mask is a glyph's coverage, placed relative to its cell's top-left. Img is nil for a glyph that draws nothing.
type Rasterizer ¶
type Rasterizer struct {
// contains filtered or unexported fields
}
Rasterizer turns characters into coverage masks on the CPU, once each, for the renderers that keep glyphs as images instead of Gio text paths. Built by New, it also owns the fallback Gio lacks: a character the family does not cover is drawn from whichever installed font covers it. A character nothing covers, or whose lookup fails, is drawn as a box (tofu).
func New ¶
func New(family string) (*Rasterizer, error)
New loads the four styles of family. Where fontconfig is installed it resolves family as fc-match does; elsewhere family must be the name of an installed font (or "monospace") in the platform's font directories. Call SetSize before Mask or Cell. It fails with ErrFontNotFound when no font directory holds family.
func NewFromData ¶
func NewFromData(styles [4][]byte) (*Rasterizer, error)
NewFromData loads the four styles from font files' contents, in styleIndex order (regular, bold, italic, bold italic). It never looks a fallback up: a character the fonts do not cover is drawn as tofu.
func (*Rasterizer) CellH ¶
func (r *Rasterizer) CellH() int
CellH is the height of one line in pixels at the current size.
func (*Rasterizer) CellW ¶
func (r *Rasterizer) CellW() int
CellW is the width of one monospace cell in pixels at the current size.
func (*Rasterizer) Mask ¶
func (r *Rasterizer) Mask(k Key) *Mask
Mask returns k's coverage, rasterizing it on first use.
func (*Rasterizer) SetSize ¶
func (r *Rasterizer) SetSize(px float64) error
SetSize re-creates every face at px pixels per em, which drops every cached mask. Setting the size it already has does nothing.
func (*Rasterizer) Strikethrough ¶ added in v0.2.0
func (r *Rasterizer) Strikethrough() Rule
Strikethrough is where a line-through is drawn at the current size.
func (*Rasterizer) Underline ¶ added in v0.2.0
func (r *Rasterizer) Underline() Rule
Underline is where an underline is drawn at the current size.