avyos.dev/pkg/graphics/font

package font

Package Overview

No package-level documentation is provided.

Export GroupCount
Constants0
Variables0
Functions0
Types3

Types

Font

type Font struct {
	// contains filtered or unexported fields
}

Font is a pure-Go anti-aliased TTF renderer.

Functions

func NewDefault(opts *Options) (*Font, error)

NewDefault returns a TTF renderer backed by gofont/goregular.

func NewFromFile(path string, opts *Options) (*Font, error)

NewFromFile loads and parses a TTF file from disk.

func NewFromTTF(ttf []byte, opts *Options) (*Font, error)

NewFromTTF parses a TTF payload and returns a renderable face.

Methods

func (f *Font) Ascent() int

Ascent returns the ascent in pixels.

func (f *Font) Close() error

Close releases face resources when applicable.

func (f *Font) Descent() int

Descent returns the descent in pixels.

func (f *Font) DrawGlyph(dst draw.Image, r rune, x, y int, fg, bg color.Color)

DrawGlyph draws one rune at (x, y), where y is the top of the glyph box.

func (f *Font) DrawText(dst draw.Image, text string, x, y int, fg, bg color.Color)

DrawText draws anti-aliased text at (x, y), where y is the top of the text box.

func (f *Font) LineHeight() int

LineHeight returns the configured line height in pixels.

func (f *Font) Measure(text string) (int, int)

Measure returns text width and height in pixels.

func (f *Font) ShapeLine(line string) []ShapedGlyph

ShapeLine applies kerning-aware shaping to a single text line.

Options

type Options struct {
	Size    float64
	DPI     float64
	Hinting xfont.Hinting
	// HintingSet allows selecting HintingNone explicitly.
	HintingSet bool
}

Options controls TTF face creation.

ShapedGlyph

type ShapedGlyph struct {
	Rune    rune
	X       fixed.Int26_6
	Advance fixed.Int26_6
}

ShapedGlyph stores positioning data for a shaped glyph run.