From b0672ec8ee0e78ef52cc44b4df5d4402015a1320 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 10 Aug 2024 22:12:31 -0400 Subject: [PATCH] Add a fallback face set --- internal/faces/fallback/face.go | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 internal/faces/fallback/face.go 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 + } +}