Files
gio-patched/font/font.go
T
Elias Naur 40822ef26b font: add a central font registry
Package font holds a singleton text.Shaper for general use. Subpackages
call Register to add fonts to the registry.

The intention is that programs can add a typeface by importing a package:

import _ "gioui.org/font/gofont"

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-13 18:23:30 +02:00

37 lines
662 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.Shaper)
)
// Default returns a singleton *text.Shaper that contains
// the registered fonts.
func Default() *text.Shaper {
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)
}