fix race
This commit is contained in:
parent
83aad90f64
commit
a5b867ba5b
1 changed files with 7 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/font"
|
"oss.terrastruct.com/d2/lib/font"
|
||||||
fontlib "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]))
|
fontBuf := make([]byte, len(FontFaces[f]))
|
||||||
copy(fontBuf, FontFaces[f])
|
copy(fontBuf, FontFaces[f])
|
||||||
fontBuf = font.UTF8CutFont(fontBuf, uniqueChars)
|
fontBuf = font.UTF8CutFont(fontBuf, uniqueChars)
|
||||||
|
|
@ -96,6 +99,8 @@ var FontFamilies = []FontFamily{
|
||||||
HandDrawn,
|
HandDrawn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var FontFamiliesMu sync.Mutex
|
||||||
|
|
||||||
//go:embed encoded/SourceSansPro-Regular.txt
|
//go:embed encoded/SourceSansPro-Regular.txt
|
||||||
var sourceSansProRegularBase64 string
|
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) {
|
func AddFontFamily(name string, regularTTF, italicTTF, boldTTF, semiboldTTF []byte) (*FontFamily, error) {
|
||||||
|
FontFamiliesMu.Lock()
|
||||||
|
defer FontFamiliesMu.Unlock()
|
||||||
customFontFamily := FontFamily(name)
|
customFontFamily := FontFamily(name)
|
||||||
|
|
||||||
regularFont := Font{
|
regularFont := Font{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue