diff --git a/internal/faces/fallback/face.go b/internal/faces/fallback/face.go new file mode 100644 index 0000000..5962b54 --- /dev/null +++ b/internal/faces/fallback/face.go @@ -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 + } +}