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 ErrNoFontconfig = errors.New("fontconfig not found: fc-match is not on PATH")
ErrNoFontconfig is what New 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 fontconfig says 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 fontconfig resolves for family. Call SetSize before Mask or Cell. It fails with ErrNoFontconfig when fc-match is not installed.
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.