fonts

package
v1.0.31-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collection

func Collection() []font.FontFace

Collection returns the registered font collection, in the order the shaper loaded it.

func DefaultFont

func DefaultFont() string

DefaultFont returns the family SetDefaultFont set.

func ForText

func ForText(f font.Font, s string) font.Font

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 Primary

func Primary(f font.Font) string

Primary returns the first family of f's family list: the one Resolve was asked for.

func Refresh

func Refresh(limit int) bool

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 Register

func Register(faces []font.FontFace)

Register replaces the font collection used to shape text.

func RegisterFont

func RegisterFont(files ...File) error

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

func Resolve(f font.Font) font.Font

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.

func Shaper

func Shaper() *text.Shaper

Shaper returns the text shaper. With no fonts registered it loads the Go fonts, so text shows without any setup.

func UseGofont

func UseGofont()

UseGofont uses the Go fonts, embedded in the binary, for text. They're the default; call it to go back to them after Register.

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").

Jump to

Keyboard shortcuts

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