font

package
v0.0.0-...-b81969c Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Font

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

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

func NewDefault

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

NewDefault returns a TTF renderer backed by gofont/goregular.

func NewFromFile

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

NewFromFile loads and parses a TTF file from disk.

func NewFromTTF

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

NewFromTTF parses a TTF payload and returns a renderable face.

func (*Font) Ascent

func (f *Font) Ascent() int

Ascent returns the ascent in pixels.

func (*Font) Close

func (f *Font) Close() error

Close releases face resources when applicable.

func (*Font) Descent

func (f *Font) Descent() int

Descent returns the descent in pixels.

func (*Font) DrawGlyph

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 (*Font) DrawText

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 (*Font) LineHeight

func (f *Font) LineHeight() int

LineHeight returns the configured line height in pixels.

func (*Font) Measure

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

Measure returns text width and height in pixels.

func (*Font) ShapeLine

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

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

type Options

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

Options controls TTF face creation.

type ShapedGlyph

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

ShapedGlyph stores positioning data for a shaped glyph run.

Jump to

Keyboard shortcuts

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