This commit is contained in:
Alexander Wang 2023-08-02 19:44:36 -07:00
parent 83aad90f64
commit a5b867ba5b
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE

View file

@ -9,6 +9,7 @@ import (
"encoding/base64"
"fmt"
"strings"
"sync"
"oss.terrastruct.com/d2/lib/font"
fontlib "oss.terrastruct.com/d2/lib/font"
@ -41,6 +42,8 @@ func (f Font) GetEncodedSubset(corpus string) string {
}
}
FontFamiliesMu.Lock()
defer FontFamiliesMu.Unlock()
fontBuf := make([]byte, len(FontFaces[f]))
copy(fontBuf, FontFaces[f])
fontBuf = font.UTF8CutFont(fontBuf, uniqueChars)
@ -96,6 +99,8 @@ var FontFamilies = []FontFamily{
HandDrawn,
}
var FontFamiliesMu sync.Mutex
//go:embed encoded/SourceSansPro-Regular.txt
var sourceSansProRegularBase64 string
@ -309,6 +314,8 @@ func AddFontStyle(font Font, style FontStyle, ttf []byte) error {
}
func AddFontFamily(name string, regularTTF, italicTTF, boldTTF, semiboldTTF []byte) (*FontFamily, error) {
FontFamiliesMu.Lock()
defer FontFamiliesMu.Unlock()
customFontFamily := FontFamily(name)
regularFont := Font{