Files
gio/font/font.go
T
Elias Naur e25b1639b9 text: make Shaper an interface
And rename out the caching implementation to FontRegistry.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-01-13 14:48:31 +01:00

37 lines
674 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
// Package font implements a central font registry.
package font
import (
"sync"
"gioui.org/text"
)
var (
mu sync.Mutex
initialized bool
shaper = new(text.FontRegistry)
)
// Default returns a singleton *text.Shaper that contains
// the registered fonts.
func Default() *text.FontRegistry {
mu.Lock()
defer mu.Unlock()
initialized = true
return shaper
}
// Register a face. Register panics if Default has been
// called.
func Register(font text.Font, face text.Face) {
mu.Lock()
defer mu.Unlock()
if initialized {
panic("Register must be called before Default")
}
shaper.Register(font, face)
}