Find and load any font

This commit is contained in:
2022-11-11 15:01:36 -05:00
parent ed5c6829d4
commit cc498fa89c
4 changed files with 45 additions and 21 deletions

View File

@@ -1,11 +1,11 @@
package x
// import "os"
import "os"
import "image"
import "image/draw"
import "golang.org/x/image/font"
import "golang.org/x/image/math/fixed"
// import "golang.org/x/image/font/opentype"
import "golang.org/x/image/font/opentype"
import "golang.org/x/image/font/basicfont"
import "github.com/jezek/xgb"
@@ -18,7 +18,7 @@ import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/sashakoshka/stone"
// import "github.com/flopp/go-findfont"
import "github.com/flopp/go-findfont"
type Backend struct {
application *stone.Application
@@ -336,18 +336,18 @@ func factory (application *stone.Application) (output stone.Backend, err error)
}
func findAndLoadFont (name string, size float64) (face font.Face) {
// fontPath, err := findfont.Find(name)
// if err != nil { return }
// fontFile, err := os.Open(fontPath)
// if err != nil { return }
// fontObject, err := opentype.ParseReaderAt(fontFile)
// if err != nil { return }
// face, err = opentype.NewFace (fontObject, &opentype.FaceOptions {
// Size: size,
// DPI: 96,
// Hinting: font.HintingFull,
// })
// if err != nil { face = nil }
fontPath, err := findfont.Find(name)
if err != nil { return }
fontFile, err := os.Open(fontPath)
if err != nil { return }
fontObject, err := opentype.ParseReaderAt(fontFile)
if err != nil { return }
face, err = opentype.NewFace (fontObject, &opentype.FaceOptions {
Size: size,
DPI: 96,
Hinting: font.HintingFull,
})
if err != nil { face = nil }
return
}