Skip to content

Commit 3f20c03

Browse files
committed
优化加载字体
1 parent b5548fe commit 3f20c03

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

shadow.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ func DrawShadowedRectangle(canvas *gg.Context, x, y, w, h, r, sigma float64, ox,
2525
}
2626

2727
// DrawShadowedString 绘制带阴影的文字
28-
func DrawShadowedString(canvas *gg.Context, s, fontfile string, x, y, point, sigma float64, ox, oy int, stringcolor, shadowcolor color.Color) (err error) {
28+
func DrawShadowedString(canvas *gg.Context, s string, fontdata []byte, x, y, point, sigma float64, ox, oy int, stringcolor, shadowcolor color.Color) (err error) {
2929
one := gg.NewContext(canvas.W(), canvas.H())
30-
err = one.LoadFontFace(fontfile, point)
30+
err = one.ParseFontFace(fontdata, point)
3131
if err != nil {
3232
return
3333
}
3434
one.SetColor(shadowcolor)
3535
one.DrawString(s, x, y)
3636
canvas.DrawImage(imaging.Blur(one.Image(), sigma), ox, oy)
37-
err = canvas.LoadFontFace(fontfile, point)
37+
err = canvas.ParseFontFace(fontdata, point)
3838
if err != nil {
3939
return
4040
}
@@ -44,16 +44,16 @@ func DrawShadowedString(canvas *gg.Context, s, fontfile string, x, y, point, sig
4444
}
4545

4646
// DrawShadowedStringAnchored 在锚点上绘制带阴影的文字
47-
func DrawShadowedStringAnchored(canvas *gg.Context, s, fontfile string, x, y, point, sigma float64, ox, oy int, stringcolor, shadowcolor color.Color, ax, ay float64) (err error) {
47+
func DrawShadowedStringAnchored(canvas *gg.Context, s string, fontdata []byte, x, y, point, sigma float64, ox, oy int, stringcolor, shadowcolor color.Color, ax, ay float64) (err error) {
4848
one := gg.NewContext(canvas.W(), canvas.H())
49-
err = one.LoadFontFace(fontfile, point)
49+
err = one.ParseFontFace(fontdata, point)
5050
if err != nil {
5151
return
5252
}
5353
one.SetColor(shadowcolor)
5454
one.DrawStringAnchored(s, x, y, ax, ay)
5555
canvas.DrawImage(imaging.Blur(one.Image(), sigma), ox, oy)
56-
err = canvas.LoadFontFace(fontfile, point)
56+
err = canvas.ParseFontFace(fontdata, point)
5757
if err != nil {
5858
return
5959
}

utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func Transparency(dst image.Image, magnification float64) image.Image {
4343
}
4444

4545
// Truncate 截断文字
46-
func Truncate(fontfile string, texts []string, maxW, fontsize float64) (newtexts []string, err error) {
46+
func Truncate(fontdata []byte, texts []string, maxW, fontsize float64) (newtexts []string, err error) {
4747
one := gg.NewContext(1, 1)
48-
err = one.LoadFontFace(fontfile, fontsize)
48+
err = one.ParseFontFace(fontdata, fontsize)
4949
if err != nil {
5050
return
5151
}

0 commit comments

Comments
 (0)