font/gofont: [API] use new opentype impl for Collection()

This commit switches gofont.Collection from returning
a collection of fonts using the old text shaper to
using the new harfbuzz-based shaper. The underlying type
of gofont.Collection() has changed, which may break users
who dug into the font data.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2022-03-16 16:01:40 -04:00
committed by Elias Naur
parent 9576b659d7
commit e14bbee252
2 changed files with 11 additions and 43 deletions
+2 -34
View File
@@ -29,10 +29,8 @@ import (
)
var (
once sync.Once
collection []text.FontFace
onceHB sync.Once
collectionHB []text.FontFace
once sync.Once
collection []text.FontFace
)
func Collection() []text.FontFace {
@@ -56,36 +54,6 @@ func Collection() []text.FontFace {
return collection
}
func CollectionHB() []text.FontFace {
onceHB.Do(func() {
registerHB(text.Font{}, goregular.TTF)
registerHB(text.Font{Style: text.Italic}, goitalic.TTF)
registerHB(text.Font{Weight: text.Bold}, gobold.TTF)
registerHB(text.Font{Style: text.Italic, Weight: text.Bold}, gobolditalic.TTF)
registerHB(text.Font{Weight: text.Medium}, gomedium.TTF)
registerHB(text.Font{Weight: text.Medium, Style: text.Italic}, gomediumitalic.TTF)
registerHB(text.Font{Variant: "Mono"}, gomono.TTF)
registerHB(text.Font{Variant: "Mono", Weight: text.Bold}, gomonobold.TTF)
registerHB(text.Font{Variant: "Mono", Weight: text.Bold, Style: text.Italic}, gomonobolditalic.TTF)
registerHB(text.Font{Variant: "Mono", Style: text.Italic}, gomonoitalic.TTF)
registerHB(text.Font{Variant: "Smallcaps"}, gosmallcaps.TTF)
registerHB(text.Font{Variant: "Smallcaps", Style: text.Italic}, gosmallcapsitalic.TTF)
// Ensure that any outside appends will not reuse the backing store.
n := len(collectionHB)
collectionHB = collectionHB[:n:n]
})
return collectionHB
}
func registerHB(fnt text.Font, ttf []byte) {
face, err := opentype.Parse(ttf)
if err != nil {
panic(fmt.Errorf("failed to parse font: %v", err))
}
fnt.Typeface = "Go"
collectionHB = append(collectionHB, text.FontFace{Font: fnt, Face: face})
}
func register(fnt text.Font, ttf []byte) {
face, err := opentype.Parse(ttf)
if err != nil {