Skip to content

Commit

Permalink
rename to Lookup and Get
Browse files Browse the repository at this point in the history
  • Loading branch information
gavin-ts committed Oct 30, 2023
1 parent fdbde73 commit c38f157
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions d2renderers/d2fonts/d2fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ 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)

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))
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion d2renderers/d2fonts/d2fonts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions d2renderers/d2svg/appendix/appendix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.MustGet(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_REGULAR)))
]]></style>`, d2fonts.FontEncodings.Get(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_REGULAR)))
}
if !strings.Contains(svg, `font-family: "font-bold"`) {
appendix += fmt.Sprintf(`<style type="text/css"><![CDATA[
Expand All @@ -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.MustGet(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_BOLD)))
]]></style>`, d2fonts.FontEncodings.Get(d2fonts.SourceSansPro.Font(0, d2fonts.FONT_STYLE_BOLD)))
}

closingIndex := strings.LastIndex(svg, "</svg></svg>")
Expand Down
4 changes: 2 additions & 2 deletions lib/pdf/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/syncmap/syncmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ 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
}
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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/textmeasure/textmeasure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c38f157

Please sign in to comment.