Documentation
¶
Overview ¶
Package fonts holds the text shaper shared by all Giode elements.
Text uses the Go fonts unless the app registers its own (Register, RegisterFont); characters a font lacks fall back to the system's fonts where the platform has them.
Index ¶
- func Collection() []font.FontFace
- func DefaultFont() string
- func ForText(f font.Font, s string) font.Font
- func Primary(f font.Font) string
- func Refresh(limit int) bool
- func Register(faces []font.FontFace)
- func RegisterFont(files ...File) error
- func Resolve(f font.Font) font.Font
- func SetDefaultFont(family string)
- func Shaped(n int)
- func Shaper() *text.Shaper
- func UseGofont()
- type File
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collection ¶
Collection returns the registered font collection, in the order the shaper loaded it.
func ForText ¶
ForText resolves f (as Resolve) for text s. System fonts that text in another script falls back to often come in regular and bold only, and Gio finds none of them for the weights between - medium, semibold - drawing the text as empty boxes. While text uses the Go fonts, whose Latin, Greek and Cyrillic don't need a fallback, text with characters past them gets the nearest of regular and bold.
func Refresh ¶
Refresh replaces the shaper with a fresh one over the same fonts once more than limit bytes of text were shaped with it, and reports whether it did. Gio's shaper keeps the last thousand paragraphs it laid out, however long - in a long chat, a hundred megabytes and more, kept after the chat is gone - and Giode keeps its own cache of laid out text, so letting Gio's go costs little: a new shaper over loaded fonts takes well under a millisecond. Call it between frames: text laid out from then on uses the new shaper.
func RegisterFont ¶
RegisterFont adds font files to the fonts used to shape text, beside any registered before, or beside the default Go fonts, which text in families you don't register falls back to:
//go:embed fonts/Inter-Regular.ttf
var interRegular []byte
//go:embed fonts/Inter-Bold.ttf
var interBold []byte
fonts.RegisterFont(
fonts.File{Family: "Inter", Data: interRegular},
fonts.File{Family: "Inter", Weight: "bold", Data: interBold},
)
Text styled FontFamily: "Inter" then uses them, with the closest registered weight and style. The family, weight and style given here are what Styles select a file by, whatever the file itself says. A collection (TTC) registers all its faces.
func Resolve ¶
Resolve maps f, as text styles ask for it, to a face registered with RegisterFont under that family: the one with the same style and the closest weight (the heavier on a tie). No family means the default (SetDefaultFont). A family registered no other way is returned as is, for the shaper to match.
func SetDefaultFont ¶
func SetDefaultFont(family string)
SetDefaultFont makes family the font of all text that doesn't set a FontFamily - Giode's own components included (title bars, buttons, text fields, menus, toasts) - in place of the Go fonts. Register the family's files first (RegisterFont); "" goes back to the Go fonts. Call it before the window opens: text laid out from then on uses it.
func Shaped ¶
func Shaped(n int)
Shaped records that n bytes of text were laid out with the shaper, for Refresh.
Types ¶
type File ¶
type File struct {
Family string
// Weight is a CSS weight name or number ("bold", "600"); empty
// is normal.
Weight properties.FontWeight
Italic bool
Data []byte
}
File is a font file to register with RegisterFont: the TTF, OTF or TTC data, and the family, weight and style Styles select it by (FontFamily, FontWeight, FontStyle "italic").