font

package
v0.0.0-...-2114137 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package font provides high-quality font rendering with texture atlas

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorToRGBA

func ColorToRGBA(c math.Color) color.RGBA

ColorToRGBA converts Color to color.RGBA

func EmbeddedFontData

func EmbeddedFontData() []byte

EmbeddedFontData returns the embedded default font data (Noto Sans CJK Regular). It covers Latin, CJK Unified Ideographs (Chinese, Japanese, Korean), Kana, and Hangul. Returns nil if the font file was not embedded at build time.

func FontCoverageScore

func FontCoverageScore(ttfData []byte, probes []rune) (int, error)

FontCoverageScore counts how many probe runes a font contains.

func ValidateFontData

func ValidateFontData(ttfData []byte) error

ValidateFontData verifies that font data is supported by the opentype parser.

Types

type Font

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

Font represents a font with texture atlas

func NewFont

func NewFont(ttfData []byte, fontSize float64) (*Font, error)

NewFont creates a new font from TTF data

func NewFontStyled

func NewFontStyled(ttfData []byte, style FontStyle) (*Font, error)

NewFontStyled creates a new font with style options (bold/italic). It supports TTF, OTF, TTC, and OTC font formats.

func (*Font) Ascent

func (f *Font) Ascent() float32

Ascent returns the ascent

func (*Font) Delete

func (f *Font) Delete()

Delete deletes the font texture

func (*Font) Descent

func (f *Font) Descent() float32

Descent returns the descent (positive value indicating pixels below baseline).

func (*Font) Fallbacks

func (f *Font) Fallbacks() []*Font

Fallbacks returns a snapshot of configured fallback fonts.

func (*Font) ForEachGlyph

func (f *Font) ForEachGlyph(fn func(r rune, g *GlyphInfo))

ForEachGlyph calls fn for each cached glyph while holding the read lock. Prefer this over Glyphs() for non-debug iteration (no map copy).

func (*Font) GetGlyph

func (f *Font) GetGlyph(r rune) (*GlyphInfo, bool)

GetGlyph returns glyph info for a rune

func (*Font) Glyphs

func (f *Font) Glyphs() map[rune]*GlyphInfo

Glyphs returns a copy of the glyph map (for debugging only). For production iteration use ForEachGlyph instead.

func (*Font) HasRune

func (f *Font) HasRune(r rune) bool

HasRune reports whether this font directly contains the rune.

func (*Font) LetterSpacing

func (f *Font) LetterSpacing() float32

LetterSpacing returns the extra spacing inserted after each glyph.

func (*Font) LineHeight

func (f *Font) LineHeight() float32

LineHeight returns the line height

func (*Font) MeasureText

func (f *Font) MeasureText(text string) (float32, float32)

MeasureText returns width and height of text

func (*Font) ResolveGlyph

func (f *Font) ResolveGlyph(r rune) (*Font, *GlyphInfo, bool)

ResolveGlyph returns the font atlas and glyph used to draw a rune, including fallbacks.

func (*Font) RuneAdvance

func (f *Font) RuneAdvance(r rune) float32

RuneAdvance returns a rune's advance including configured letter spacing.

func (*Font) SetFallbacks

func (f *Font) SetFallbacks(fallbacks ...*Font)

SetFallbacks replaces the fallback fonts used when a rune is missing.

func (*Font) SyncGPU

func (f *Font) SyncGPU()

SyncGPU ensures the GPU texture is up to date with the CPU atlas. Must be called with a current GL context (e.g. inside Render/BeginFrame).

func (*Font) TextWidth

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

TextWidth calculates the width of a string

func (*Font) Texture

func (f *Font) Texture() uint32

Texture returns the font texture

type FontStyle

type FontStyle struct {
	Size    float64
	Bold    bool
	Italic  bool
	DPI     float64
	Hinting xfont.Hinting
	// LetterSpacing adds extra pixels between glyph advances.
	LetterSpacing float32
}

FontStyle describes font style options.

type GlyphInfo

type GlyphInfo struct {
	// UV coordinates (0-1)
	U0, V0, U1, V1 float32
	// Metrics
	Advance  float32
	Width    float32
	Height   float32
	BearingX float32
	BearingY float32
}

GlyphInfo stores glyph metrics and atlas position

Jump to

Keyboard shortcuts

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