rename to Get and MustGet
This commit is contained in:
parent
1cfa2b9f81
commit
fdbde73605
6 changed files with 19 additions and 19 deletions
|
|
@ -45,7 +45,7 @@ func (f Font) GetEncodedSubset(corpus string) string {
|
|||
|
||||
FontFamiliesMu.Lock()
|
||||
defer FontFamiliesMu.Unlock()
|
||||
face := FontFaces.Get(f)
|
||||
face := FontFaces.MustGet(f)
|
||||
fontBuf := make([]byte, len(face))
|
||||
copy(fontBuf, face)
|
||||
fontBuf = font.UTF8CutFont(fontBuf, uniqueChars)
|
||||
|
|
@ -53,7 +53,7 @@ func (f Font) GetEncodedSubset(corpus string) string {
|
|||
fontBuf, err := fontlib.Sfnt2Woff(fontBuf)
|
||||
if err != nil {
|
||||
// If subset fails, return full encoding
|
||||
return FontEncodings.Get(f)
|
||||
return FontEncodings.MustGet(f)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("data:application/font-woff;base64,%v", base64.StdEncoding.EncodeToString(fontBuf))
|
||||
|
|
@ -366,8 +366,8 @@ func AddFontFamily(name string, regularTTF, italicTTF, boldTTF, semiboldTTF []by
|
|||
Family: SourceSansPro,
|
||||
Style: FONT_STYLE_REGULAR,
|
||||
}
|
||||
FontFaces.Set(regularFont, FontFaces.Get(fallbackFont))
|
||||
FontEncodings.Set(regularFont, FontEncodings.Get(fallbackFont))
|
||||
FontFaces.Set(regularFont, FontFaces.MustGet(fallbackFont))
|
||||
FontEncodings.Set(regularFont, FontEncodings.MustGet(fallbackFont))
|
||||
}
|
||||
|
||||
italicFont := Font{
|
||||
|
|
@ -384,8 +384,8 @@ func AddFontFamily(name string, regularTTF, italicTTF, boldTTF, semiboldTTF []by
|
|||
Family: SourceSansPro,
|
||||
Style: FONT_STYLE_ITALIC,
|
||||
}
|
||||
FontFaces.Set(italicFont, FontFaces.Get(fallbackFont))
|
||||
FontEncodings.Set(italicFont, FontEncodings.Get(fallbackFont))
|
||||
FontFaces.Set(italicFont, FontFaces.MustGet(fallbackFont))
|
||||
FontEncodings.Set(italicFont, FontEncodings.MustGet(fallbackFont))
|
||||
}
|
||||
|
||||
boldFont := Font{
|
||||
|
|
@ -402,8 +402,8 @@ func AddFontFamily(name string, regularTTF, italicTTF, boldTTF, semiboldTTF []by
|
|||
Family: SourceSansPro,
|
||||
Style: FONT_STYLE_BOLD,
|
||||
}
|
||||
FontFaces.Set(boldFont, FontFaces.Get(fallbackFont))
|
||||
FontEncodings.Set(boldFont, FontEncodings.Get(fallbackFont))
|
||||
FontFaces.Set(boldFont, FontFaces.MustGet(fallbackFont))
|
||||
FontEncodings.Set(boldFont, FontEncodings.MustGet(fallbackFont))
|
||||
}
|
||||
|
||||
semiboldFont := Font{
|
||||
|
|
@ -420,8 +420,8 @@ func AddFontFamily(name string, regularTTF, italicTTF, boldTTF, semiboldTTF []by
|
|||
Family: SourceSansPro,
|
||||
Style: FONT_STYLE_SEMIBOLD,
|
||||
}
|
||||
FontFaces.Set(semiboldFont, FontFaces.Get(fallbackFont))
|
||||
FontEncodings.Set(semiboldFont, FontEncodings.Get(fallbackFont))
|
||||
FontFaces.Set(semiboldFont, FontFaces.MustGet(fallbackFont))
|
||||
FontEncodings.Set(semiboldFont, FontEncodings.MustGet(fallbackFont))
|
||||
}
|
||||
|
||||
FontFamilies = append(FontFamilies, customFontFamily)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func TestCutFont(t *testing.T) {
|
|||
Family: SourceCodePro,
|
||||
Style: FONT_STYLE_BOLD,
|
||||
}
|
||||
face := FontFaces.Get(f)
|
||||
face := FontFaces.MustGet(f)
|
||||
fontBuf := make([]byte, len(face))
|
||||
copy(fontBuf, face)
|
||||
fontBuf = font.UTF8CutFont(fontBuf, " 1")
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ func Append(diagram *d2target.Diagram, ruler *textmeasure.Ruler, in []byte) []by
|
|||
font-family: font-regular;
|
||||
src: url("%s");
|
||||
}
|
||||
]]></style>`, d2fonts.FontEncodings.Get(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_REGULAR)))
|
||||
]]></style>`, d2fonts.FontEncodings.MustGet(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_REGULAR)))
|
||||
}
|
||||
if !strings.Contains(svg, `font-family: "font-bold"`) {
|
||||
appendix += fmt.Sprintf(`<style type="text/css"><![CDATA[
|
||||
|
|
@ -140,7 +140,7 @@ func Append(diagram *d2target.Diagram, ruler *textmeasure.Ruler, in []byte) []by
|
|||
font-family: font-bold;
|
||||
src: url("%s");
|
||||
}
|
||||
]]></style>`, d2fonts.FontEncodings.Get(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_BOLD)))
|
||||
]]></style>`, d2fonts.FontEncodings.MustGet(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_BOLD)))
|
||||
}
|
||||
|
||||
closingIndex := strings.LastIndex(svg, "</svg></svg>")
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ func Init() *GoFPDF {
|
|||
UnitStr: "pt",
|
||||
})
|
||||
|
||||
newGofPDF.AddUTF8FontFromBytes("source", "", d2fonts.FontFaces.Get(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_REGULAR)))
|
||||
newGofPDF.AddUTF8FontFromBytes("source", "B", d2fonts.FontFaces.Get(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_BOLD)))
|
||||
newGofPDF.AddUTF8FontFromBytes("source", "", d2fonts.FontFaces.MustGet(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_REGULAR)))
|
||||
newGofPDF.AddUTF8FontFromBytes("source", "B", d2fonts.FontFaces.MustGet(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_BOLD)))
|
||||
newGofPDF.SetAutoPageBreak(false, 0)
|
||||
newGofPDF.SetLineWidth(2)
|
||||
newGofPDF.SetMargins(0, 0, 0)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ func (sm SyncMap[K, V]) Set(key K, value V) {
|
|||
sm._map.Store(key, value)
|
||||
}
|
||||
|
||||
func (sm SyncMap[K, V]) GetWithStatus(key K) (value V, ok bool) {
|
||||
func (sm SyncMap[K, V]) Get(key K) (value V, ok bool) {
|
||||
v, has := sm._map.Load(key)
|
||||
if !has {
|
||||
return value, false
|
||||
|
|
@ -24,8 +24,8 @@ func (sm SyncMap[K, V]) GetWithStatus(key K) (value V, ok bool) {
|
|||
return v.(V), true
|
||||
}
|
||||
|
||||
func (sm SyncMap[K, V]) Get(key K) (value V) {
|
||||
v, _ := sm.GetWithStatus(key)
|
||||
func (sm SyncMap[K, V]) MustGet(key K) (value V) {
|
||||
v, _ := sm.Get(key)
|
||||
return v
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ func NewRuler() (*Ruler, error) {
|
|||
Style: fontStyle,
|
||||
}
|
||||
// Note: FontFaces lookup is size-agnostic
|
||||
face, has := d2fonts.FontFaces.GetWithStatus(font)
|
||||
face, has := d2fonts.FontFaces.Get(font)
|
||||
if !has {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue