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