glyphs

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func Width(r rune) int

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 Key

type Key struct {
	R            rune
	Bold, Italic bool
}

Key names one glyph: a character in one of the family's four styles.

type Mask

type Mask struct {
	Img *image.Alpha
	Off image.Point
}

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.

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.

type Rule added in v0.2.0

type Rule struct {
	Y, Thickness int
}

Rule is a line across a cell, as text decorations draw it: Y is its top in pixels from the cell's top.

Jump to

Keyboard shortcuts

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