Documentation
¶
Overview ¶
Package fonts provides a cross-platform, pure-Go typography subsystem.
This package handles OS-level font discovery, logical SFNT metadata extraction, query matching, regressional regression caching, and font fallback routines. It is intended as a low-level registry for downstream plotting mechanics.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrFontNotFound = errors.New("font not found")
ErrFontNotFound is returned when no suitable font or fallback can be matched.
var ErrInvalidFontData = errors.New("invalid font data")
ErrInvalidFontData is returned when a font file cannot be parsed.
Functions ¶
func DefaultDirs ¶
func DefaultDirs() []string
DefaultDirs provides the universal logical starting OS-specific standard hierarchies.
Types ¶
type Extents ¶
type Extents struct {
Width float64
Height float64
Ascent float64
Descent float64
LineHeight float64
}
Extents describes the geometric bounding layout for a specific rendered string returning drawing metrics mappings generically.
type FaceCache ¶
type FaceCache struct {
// contains filtered or unexported fields
}
FaceCache specifically memoizes concrete renderer facing bounds ensuring concurrent drawing maps over exact DPI/Size bounds.
func (*FaceCache) Get ¶
func (c *FaceCache) Get(r FaceRequest) (*FaceHandle, bool)
Get handles sizing array lookups executing native thread mapping.
func (*FaceCache) Set ¶
func (c *FaceCache) Set(r FaceRequest, f *FaceHandle)
Set locks mapping array metrics executing size bounds.
type FaceHandle ¶
type FaceHandle struct {
Font *Font
Size float64
DPI float64
// contains filtered or unexported fields
}
FaceHandle acts as the renderer-agnostic mapping pointer exposing pure file physical physics bounded to mapped exact sizes.
func (*FaceHandle) FontSource ¶ added in v0.0.5
func (h *FaceHandle) FontSource() *text.FontSource
FontSource returns the underlying text.FontSource for this handle, enabling callers to create faces with custom options (e.g., OpenType features). Returns nil if the font cannot be loaded.
func (*FaceHandle) MeasureExtents ¶
func (h *FaceHandle) MeasureExtents(s string) (Extents, error)
MeasureExtents calculates exact plotting dimensions converting abstract handles onto scaled layout math algorithms.
func (*FaceHandle) TextFace ¶
func (h *FaceHandle) TextFace() text.Face
TextFace returns the mapped graphics explicit bounding context allowing external Ebiten / GG layers structural drawing commands globally mapping.
type FaceRequest ¶
type FaceRequest struct {
Family string
Weight Weight
Style Style
PreferMonospace bool
AllowFallback bool
Size float64 // Represents requested structural point sizing.
DPI float64 // Scales the mapped size metrics mapping precisely.
}
FaceRequest defines sized layout dependencies external graphing engines pass directly matching native configurations.
type FallbackConfig ¶
type FallbackConfig struct {
// Aliases maps specific query families to nearest approximations BEFORE cascading generic overrides.
Aliases map[string][]string
// Core platform agnostic fallback trees mapping general generic categories arrays.
SansSerif []string
Serif []string
Monospace []string
Emoji []string
}
FallbackConfig defines explicit string map overrides generating strict deterministic cascade trees.
func DefaultFallbackConfig ¶
func DefaultFallbackConfig() FallbackConfig
DefaultFallbackConfig returns sane universal fallbacks spanning Linux, Windows, and macOS mappings.
type Font ¶
type Font struct {
Path string
Index int
Family string
Subfamily string
FullName string
Weight Weight
Style Style
Stretch string // "condensed", "expanded", "normal"
IsMonospace bool
IsSymbol bool
}
Font represents a resolvable physical font file face location.
func DiscoverFonts ¶
DiscoverFonts iteratively paths recursively searching for supported binary format schemas parsing.
type FontCache ¶
type FontCache struct {
// contains filtered or unexported fields
}
FontCache provides thread-safe heuristic memoization for resolved system fonts.
type Query ¶
type Query struct {
Family string
Weight Weight
Style Style
PreferMonospace bool
AllowFallback bool
}
Query defines the desired typographic traits requested.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry indexes system fonts discovered by scanning standard OS font directories. Each entry records the font's file path, family name, weight, and style.
func NewRegistry ¶
NewRegistry discovers and indexes all fonts in the standard OS font directories. On Linux this scans /usr/share/fonts; on macOS /Library/Fonts; on Windows C:\Windows\Fonts.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver maps font requests to loaded font faces, applying a CSS-like cascade: exact match → family alias → weight fallback → system default.
func NewResolver ¶
func NewResolver(registry *Registry, config FallbackConfig) *Resolver
NewResolver creates a Resolver backed by the given font registry and fallback configuration.
func (*Resolver) LoadFace ¶
func (r *Resolver) LoadFace(req FaceRequest) (*FaceHandle, error)
LoadFace returns a font.Face for the given family, size, weight, and style. Results are cached; concurrent calls for the same parameters share one Face.
type SourceCache ¶
type SourceCache struct {
// contains filtered or unexported fields
}
SourceCache specifically memoizes parsed physical bytes mapping resolving massive TTF files.
func (*SourceCache) Get ¶
func (c *SourceCache) Get(path string) (*text.FontSource, bool)
Get handles string lookup loads ensuring physical limits match threaded arrays.
func (*SourceCache) Set ¶
func (c *SourceCache) Set(path string, f *text.FontSource)
Set commits caching heavy physical file blocks executing directly over map arrays.