From c38f15712dc9e0bc078b56dccd04ebf1d8057c39 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Mon, 30 Oct 2023 15:02:20 -0700 Subject: [PATCH] rename to Lookup and Get --- d2renderers/d2fonts/d2fonts.go | 20 ++++++++++---------- d2renderers/d2fonts/d2fonts_test.go | 2 +- d2renderers/d2svg/appendix/appendix.go | 4 ++-- lib/pdf/pdf.go | 4 ++-- lib/syncmap/syncmap.go | 6 +++--- lib/textmeasure/textmeasure.go | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/d2renderers/d2fonts/d2fonts.go b/d2renderers/d2fonts/d2fonts.go index 717cdc8b21..a41d1bbfed 100644 --- a/d2renderers/d2fonts/d2fonts.go +++ b/d2renderers/d2fonts/d2fonts.go @@ -45,7 +45,7 @@ func (f Font) GetEncodedSubset(corpus string) string { FontFamiliesMu.Lock() defer FontFamiliesMu.Unlock() - face := FontFaces.MustGet(f) + face := FontFaces.Get(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.MustGet(f) + return FontEncodings.Get(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.MustGet(fallbackFont)) - FontEncodings.Set(regularFont, FontEncodings.MustGet(fallbackFont)) + FontFaces.Set(regularFont, FontFaces.Get(fallbackFont)) + FontEncodings.Set(regularFont, FontEncodings.Get(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.MustGet(fallbackFont)) - FontEncodings.Set(italicFont, FontEncodings.MustGet(fallbackFont)) + FontFaces.Set(italicFont, FontFaces.Get(fallbackFont)) + FontEncodings.Set(italicFont, FontEncodings.Get(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.MustGet(fallbackFont)) - FontEncodings.Set(boldFont, FontEncodings.MustGet(fallbackFont)) + FontFaces.Set(boldFont, FontFaces.Get(fallbackFont)) + FontEncodings.Set(boldFont, FontEncodings.Get(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.MustGet(fallbackFont)) - FontEncodings.Set(semiboldFont, FontEncodings.MustGet(fallbackFont)) + FontFaces.Set(semiboldFont, FontFaces.Get(fallbackFont)) + FontEncodings.Set(semiboldFont, FontEncodings.Get(fallbackFont)) } FontFamilies = append(FontFamilies, customFontFamily) diff --git a/d2renderers/d2fonts/d2fonts_test.go b/d2renderers/d2fonts/d2fonts_test.go index d86753f4d0..9c1cf4f004 100644 --- a/d2renderers/d2fonts/d2fonts_test.go +++ b/d2renderers/d2fonts/d2fonts_test.go @@ -14,7 +14,7 @@ func TestCutFont(t *testing.T) { Family: SourceCodePro, Style: FONT_STYLE_BOLD, } - face := FontFaces.MustGet(f) + face := FontFaces.Get(f) fontBuf := make([]byte, len(face)) copy(fontBuf, face) fontBuf = font.UTF8CutFont(fontBuf, " 1") diff --git a/d2renderers/d2svg/appendix/appendix.go b/d2renderers/d2svg/appendix/appendix.go index bcc8b46756..803651f355 100644 --- a/d2renderers/d2svg/appendix/appendix.go +++ b/d2renderers/d2svg/appendix/appendix.go @@ -129,7 +129,7 @@ func Append(diagram *d2target.Diagram, ruler *textmeasure.Ruler, in []byte) []by font-family: font-regular; src: url("%s"); } -]]>`, d2fonts.FontEncodings.MustGet(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_REGULAR))) +]]>`, d2fonts.FontEncodings.Get(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_REGULAR))) } if !strings.Contains(svg, `font-family: "font-bold"`) { appendix += fmt.Sprintf(``, d2fonts.FontEncodings.MustGet(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_BOLD))) +]]>`, d2fonts.FontEncodings.Get(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_BOLD))) } closingIndex := strings.LastIndex(svg, "") diff --git a/lib/pdf/pdf.go b/lib/pdf/pdf.go index acfe263708..85d6b79718 100644 --- a/lib/pdf/pdf.go +++ b/lib/pdf/pdf.go @@ -31,8 +31,8 @@ func Init() *GoFPDF { UnitStr: "pt", }) - 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.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.SetAutoPageBreak(false, 0) newGofPDF.SetLineWidth(2) newGofPDF.SetMargins(0, 0, 0) diff --git a/lib/syncmap/syncmap.go b/lib/syncmap/syncmap.go index 3ac1c13504..9836ecce33 100644 --- a/lib/syncmap/syncmap.go +++ b/lib/syncmap/syncmap.go @@ -16,7 +16,7 @@ func (sm SyncMap[K, V]) Set(key K, value V) { sm._map.Store(key, value) } -func (sm SyncMap[K, V]) Get(key K) (value V, ok bool) { +func (sm SyncMap[K, V]) Lookup(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]) Get(key K) (value V, ok bool) { return v.(V), true } -func (sm SyncMap[K, V]) MustGet(key K) (value V) { - v, _ := sm.Get(key) +func (sm SyncMap[K, V]) Get(key K) (value V) { + v, _ := sm.Lookup(key) return v } diff --git a/lib/textmeasure/textmeasure.go b/lib/textmeasure/textmeasure.go index eee20edd36..294987c057 100644 --- a/lib/textmeasure/textmeasure.go +++ b/lib/textmeasure/textmeasure.go @@ -126,7 +126,7 @@ func NewRuler() (*Ruler, error) { Style: fontStyle, } // Note: FontFaces lookup is size-agnostic - face, has := d2fonts.FontFaces.Get(font) + face, has := d2fonts.FontFaces.Lookup(font) if !has { continue }