diff --git a/.cspell.json b/.cspell.json index baf59df86..c94adfffd 100644 --- a/.cspell.json +++ b/.cspell.json @@ -145,6 +145,7 @@ "octocat", "openapi", "opensource", + "opentype", "Pacman", "picus", "Pinia", @@ -178,6 +179,7 @@ "secprofile", "selfhosted", "sess", + "sfnt", "shellescape", "sigstore", "Sonatype", diff --git a/go.mod b/go.mod index 930adaa00..576d61c62 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,6 @@ require ( github.com/go-sql-driver/mysql v1.9.3 github.com/go-viper/mapstructure/v2 v2.5.0 github.com/golang-jwt/jwt/v5 v5.3.1 - github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/google/go-github/v83 v83.0.0 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.7.0 diff --git a/go.sum b/go.sum index 6d01e4943..b35c024dd 100644 --- a/go.sum +++ b/go.sum @@ -227,8 +227,6 @@ github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0kt github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= diff --git a/server/badges/badges_test.go b/server/badges/badges_test.go index b837556a7..d2f6d1412 100644 --- a/server/badges/badges_test.go +++ b/server/badges/badges_test.go @@ -28,10 +28,10 @@ import ( var ( badgeNone = `pipelinepipelinenonenone` - badgeSuccess = `pipelinepipelinesuccesssuccess` - badgeFailure = `pipelinepipelinefailurefailure` - badgeError = `pipelinepipelineerrorerror` - badgeStarted = `pipelinepipelinestartedstarted` + badgeSuccess = `pipelinepipelinesuccesssuccess` + badgeFailure = `pipelinepipelinefailurefailure` + badgeError = `pipelinepipelineerrorerror` + badgeStarted = `pipelinepipelinestartedstarted` ) // Generate an SVG badge based on a pipeline. @@ -82,7 +82,7 @@ func TestBadgeDrawerRender(t *testing.T) { mutex: &sync.Mutex{}, } - output := "XXX,YYY,#c0c0c0,14,26,38,26,52" + output := "XXX,YYY,#c0c0c0,15.5,29,41,26,55" var buf bytes.Buffer assert.NoError(t, d.Render("XXX", "YYY", "#c0c0c0", &buf)) @@ -105,7 +105,7 @@ func TestBadgeDrawerRenderBytes(t *testing.T) { mutex: &sync.Mutex{}, } - output := "XXX,YYY,#c0c0c0,14,26,38,26,52" + output := "XXX,YYY,#c0c0c0,15.5,29,41,26,55" bytes, err := d.RenderBytes("XXX", "YYY", "#c0c0c0") diff --git a/server/badges/drawer.go b/server/badges/drawer.go index e4cef5b62..616a69cfa 100644 --- a/server/badges/drawer.go +++ b/server/badges/drawer.go @@ -11,8 +11,9 @@ import ( "io" "sync" - "github.com/golang/freetype/truetype" "golang.org/x/image/font" + "golang.org/x/image/font/opentype" + "golang.org/x/image/font/sfnt" "go.woodpecker-ci.org/woodpecker/v3/server/badges/fonts" ) @@ -116,15 +117,21 @@ func initDrawer() (*badgeDrawer, error) { } func mustNewFontDrawer(size, dpi float64) (*font.Drawer, error) { - ttf, err := truetype.Parse(fonts.DejaVuSans) + f, err := sfnt.Parse(fonts.DejaVuSans) if err != nil { return nil, err } + + face, err := opentype.NewFace(f, &opentype.FaceOptions{ + Size: size, + DPI: dpi, + Hinting: font.HintingFull, + }) + if err != nil { + return nil, err + } + return &font.Drawer{ - Face: truetype.NewFace(ttf, &truetype.Options{ - Size: size, - DPI: dpi, - Hinting: font.HintingFull, - }), + Face: face, }, nil }