mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
font/gofont: allow loading just the regular Go font
This commit introduces a special mechanism to load only the regular version of the Go font. This is useful for Gio to load a font for drawing window decorations without forcing applications to load every Go font. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
+21
-1
@@ -29,13 +29,33 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
regOnce sync.Once
|
||||
reg []font.FontFace
|
||||
once sync.Once
|
||||
collection []font.FontFace
|
||||
)
|
||||
|
||||
func loadRegular() {
|
||||
regOnce.Do(func() {
|
||||
face, err := opentype.Parse(goregular.TTF)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to parse font: %v", err))
|
||||
}
|
||||
reg = []font.FontFace{{Font: font.Font{Typeface: "Go"}, Face: face}}
|
||||
collection = append(collection, reg[0])
|
||||
})
|
||||
}
|
||||
|
||||
// Regular returns a collection of only the Go regular font face.
|
||||
func Regular() []font.FontFace {
|
||||
loadRegular()
|
||||
return reg
|
||||
}
|
||||
|
||||
// Regular returns a collection of all available Go font faces.
|
||||
func Collection() []font.FontFace {
|
||||
loadRegular()
|
||||
once.Do(func() {
|
||||
register(font.Font{}, goregular.TTF)
|
||||
register(font.Font{Style: font.Italic}, goitalic.TTF)
|
||||
register(font.Font{Weight: font.Bold}, gobold.TTF)
|
||||
register(font.Font{Style: font.Italic, Weight: font.Bold}, gobolditalic.TTF)
|
||||
|
||||
Reference in New Issue
Block a user