font

package
v0.0.0-...-ba0b20d Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	UIFontParagraph  = "paragraph"
	UIFontSubheading = "subheading"
	UIFontHeading    = "heading"
	UIFontTitle      = "title"
)

Variables

View Source
var (
	ColorTransparent = core.ColorTransparent
	ColorWhite       = core.ColorWhite
	NewBuffer        = core.NewBuffer
)
View Source
var BitmapFont = &Font{
	Width:    8,
	Height:   16,
	FirstRun: 32,
	LastRun:  126,
	Glyphs:   defaultGlyphs,
}

BitmapFont is the built-in 8x16 bitmap font.

View Source
var DefaultFont = BitmapFont

DefaultFont is the active font used by graphics and UI.

Functions

func SetUIFont

func SetUIFont(role string, font *Font)

SetUIFont sets a font for a logical UI text role.

func SetUIFonts

func SetUIFonts(fonts map[string]*Font)

SetUIFonts sets multiple UI role fonts at once.

Types

type Buffer

type Buffer = core.Buffer

type Color

type Color = core.Color

type Face

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

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

func NewDefault

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

NewDefault returns a TTF renderer backed by gofont/goregular.

func NewFromFile

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

NewFromFile loads and parses a TTF file from disk.

func NewFromTTF

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

NewFromTTF parses a TTF payload and returns a renderable face.

func (*Face) Ascent

func (f *Face) Ascent() int

Ascent returns the ascent in pixels.

func (*Face) Close

func (f *Face) Close() error

Close releases face resources when applicable.

func (*Face) Descent

func (f *Face) Descent() int

Descent returns the descent in pixels.

func (*Face) DrawGlyph

func (f *Face) 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 (*Face) DrawText

func (f *Face) 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 (*Face) LineHeight

func (f *Face) LineHeight() int

LineHeight returns the configured line height in pixels.

func (*Face) Measure

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

Measure returns text width and height in pixels.

func (*Face) ShapeLine

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

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

type Font

type Font struct {
	Width    int
	Height   int
	Glyphs   map[rune][]byte
	FirstRun rune
	LastRun  rune
	// contains filtered or unexported fields
}

Font represents either a bitmap font or a vector TTF-backed font.

func LoadTTFFont

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

LoadTTFFont creates a gfxfont.Font from raw TTF bytes.

func LoadTTFFontFile

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

LoadTTFFontFile creates a gfxfont.Font from a TTF file path.

func NewDefaultTTFFont

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

NewDefaultTTFFont creates a gfxfont.Font using gofont/goregular.

func NewTTFFont

func NewTTFFont(face *Face) *Font

NewTTFFont wraps a shaped TTF face for the graphics renderer.

func UIFont

func UIFont(role string) *Font

UIFont returns the font for a UI role, falling back to the default font.

func (*Font) Close

func (f *Font) Close() error

Close releases font resources when supported by the backing renderer.

func (*Font) DrawGlyph

func (f *Font) DrawGlyph(buf *Buffer, r rune, x, y int, fg, bg Color)

DrawGlyph draws a single character glyph to a buffer.

func (*Font) DrawText

func (f *Font) DrawText(buf *Buffer, text string, x, y int, fg, bg Color)

DrawText draws text to a buffer at the given position.

func (*Font) TextHeight

func (f *Font) TextHeight(text string) int

TextHeight returns the height of text in pixels.

func (*Font) TextWidth

func (f *Font) TextWidth(text string) int

TextWidth returns the width of text in pixels.

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