avyos.dev/pkg/graphics/fonts
package font
Overview
No package-level documentation is provided.
| Export Group | Count |
|---|---|
| Constants | 1 |
| Variables | 3 |
| Functions | 3 |
| Types | 6 |
Constants
UIFontParagraph, UIFontSubheading, UIFontHeading, UIFontTitle
const (
UIFontParagraph = "paragraph"
UIFontSubheading = "subheading"
UIFontHeading = "heading"
UIFontTitle = "title"
)Variables
ColorTransparent, ColorWhite, NewBuffer
var (
ColorTransparent = core.ColorTransparent
ColorWhite = core.ColorWhite
NewBuffer = core.NewBuffer
)BitmapFont
var BitmapFont = &Font{
Width: 8,
Height: 16,
FirstRun: 32,
LastRun: 126,
Glyphs: defaultGlyphs,
}BitmapFont is the built-in 8x16 bitmap font.
DefaultFont
var DefaultFont = BitmapFontDefaultFont is the active font used by graphics and UI.
Functions
ApplyConfiguredDefaultFont
func ApplyConfiguredDefaultFont() errorApplyConfiguredDefaultFont loads config/fonts.ini and sets Default/UI fonts. It always applies bitmap fallback first so rendering remains functional.
SetUIFont
func SetUIFont(role string, font *Font)SetUIFont sets a font for a logical UI text role.
SetUIFonts
func SetUIFonts(fonts map[string]*Font)SetUIFonts sets multiple UI role fonts at once.
Types
Buffer
type Buffer = core.BufferColor
type Color = color.NRGBAFace
type Face struct {
// contains filtered or unexported fields
}Face is a pure-Go anti-aliased TTF renderer.
Functions
NewDefault
func NewDefault(opts *Options) (*Face, error)NewDefault returns a TTF renderer backed by gofont/goregular.
NewFromFile
func NewFromFile(path string, opts *Options) (*Face, error)NewFromFile loads and parses a TTF file from disk.
NewFromTTF
func NewFromTTF(ttf []byte, opts *Options) (*Face, error)NewFromTTF parses a TTF payload and returns a renderable face.
Methods
Ascent
func (f *Face) Ascent() intAscent returns the ascent in pixels.
Close
func (f *Face) Close() errorClose releases face resources when applicable.
Descent
func (f *Face) Descent() intDescent returns the descent in pixels.
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.
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.
LineHeight
func (f *Face) LineHeight() intLineHeight returns the configured line height in pixels.
Measure
func (f *Face) Measure(text string) (int, int)Measure returns text width and height in pixels.
ShapeLine
func (f *Face) ShapeLine(line string) []ShapedGlyphShapeLine applies kerning-aware shaping to a single text line.
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.
Functions
LoadTTFFont
func LoadTTFFont(ttf []byte, opts *Options) (*Font, error)LoadTTFFont creates a gfxfont.Font from raw TTF bytes.
LoadTTFFontFile
func LoadTTFFontFile(path string, opts *Options) (*Font, error)LoadTTFFontFile creates a gfxfont.Font from a TTF file path.
NewDefaultTTFFont
func NewDefaultTTFFont(opts *Options) (*Font, error)NewDefaultTTFFont creates a gfxfont.Font using gofont/goregular.
NewTTFFont
func NewTTFFont(face *Face) *FontNewTTFFont wraps a shaped TTF face for the graphics renderer.
UIFont
func UIFont(role string) *FontUIFont returns the font for a UI role, falling back to the default font.
Methods
Close
func (f *Font) Close() errorClose releases font resources when supported by the backing renderer.
DrawGlyph
func (f *Font) DrawGlyph(buf *Buffer, r rune, x, y int, fg, bg Color)DrawGlyph draws a single character glyph to a buffer.
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.
TextHeight
func (f *Font) TextHeight(text string) intTextHeight returns the height of text in pixels.
TextWidth
func (f *Font) TextWidth(text string) intTextWidth returns the width of text in pixels.
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.