Add a fallback face set

This commit is contained in:
Sasha Koshka 2024-08-10 22:12:31 -04:00
parent 961366b00a
commit b0672ec8ee

View File

@ -0,0 +1,35 @@
package fallbackFaces
import "golang.org/x/image/font"
import "git.tebibyte.media/tomo/tomo"
import "golang.org/x/image/font/basicfont"
import "git.tebibyte.media/tomo/backend/style"
type faceSet struct {
regular font.Face
bold font.Face
italic font.Face
boldItalic font.Face
}
// New creates a new fallback face set.
func New () style.FaceSet {
// TODO maybe pre-generate different variations of this face
return &faceSet {
regular: basicfont.Face7x13,
bold: basicfont.Face7x13,
italic: basicfont.Face7x13,
boldItalic: basicfont.Face7x13,
}
}
func (this *faceSet) Face (face tomo.Face) font.Face {
bold := face.Weight >= 500
italic := face.Italic >= 0.1 || face.Slant >= 0.1
switch {
case bold && italic: return this.boldItalic
case bold: return this.bold
case italic: return this.italic
default: return this.regular
}
}