nasin/internal/faces/fallback/face.go

36 lines
907 B
Go
Raw Normal View History

2024-08-10 20:12:31 -06:00
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
}
}