mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
e25b1639b9
And rename out the caching implementation to FontRegistry. Signed-off-by: Elias Naur <mail@eliasnaur.com>
37 lines
674 B
Go
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)
|
|
}
|