Skip to content

Commit 70b4fd8

Browse files
author
Bernard Xie
committedMar 28, 2023
copy byte slice first
1 parent e5eeebe commit 70b4fd8

File tree

393 files changed

+679
-1550
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

393 files changed

+679
-1550
lines changed
 

‎d2renderers/d2fonts/d2fonts.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"fmt"
1111
"strings"
1212

13+
"github.com/jung-kurt/gofpdf"
14+
1315
fontlib "oss.terrastruct.com/d2/lib/font"
1416
)
1517

@@ -31,9 +33,10 @@ func (f FontFamily) Font(size int, style FontStyle) Font {
3133
}
3234

3335
func (f Font) GetEncodedSubset(cutset string) string {
36+
fontBuf := make([]byte, len(FontFaces[f]))
37+
copy(fontBuf, FontFaces[f])
3438
// gofpdf subset only accepts .ttf fonts
35-
fontBuf := FontFaces[f]
36-
fontBuf = fontlib.CutFont(fontBuf, cutset)
39+
fontBuf = gofpdf.UTF8CutFont(fontBuf, cutset)
3740

3841
fontBuf, err := fontlib.Sfnt2Woff(fontBuf)
3942
if err != nil {

‎d2renderers/d2fonts/d2fonts_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import (
44
"path/filepath"
55
"testing"
66

7-
"oss.terrastruct.com/d2/lib/font"
7+
"github.com/jung-kurt/gofpdf"
8+
89
"oss.terrastruct.com/util-go/assert"
910
"oss.terrastruct.com/util-go/diff"
1011
)
1112

1213
func TestCutFont(t *testing.T) {
1314
f := Font{
1415
Family: SourceCodePro,
15-
Style: FONT_STYLE_REGULAR,
16+
Style: FONT_STYLE_BOLD,
1617
}
17-
fontBuf := FontFaces[f]
18-
fontBuf = font.CutFont(fontBuf, "a")
18+
fontBuf := make([]byte, len(FontFaces[f]))
19+
copy(fontBuf, FontFaces[f])
20+
fontBuf = gofpdf.UTF8CutFont(fontBuf, " 1")
1921
err := diff.Testdata(filepath.Join("testdata", "d2fonts", "cut"), ".txt", fontBuf)
2022
assert.Success(t, err)
2123
}

0 commit comments

Comments
 (0)