Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiang-Red committed Jan 11, 2023
1 parent 7a6b8e1 commit 56b6cb7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Binary file modified .github/DrawCard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/DrawTitleWithText.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ go 1.19
require (
github.com/Coloured-glaze/gg v1.3.4
github.com/FloatTech/zbputils v1.6.2-0.20230111073858-4d59c5450bfb
github.com/disintegration/imaging v1.6.2
github.com/stretchr/testify v1.8.1
)

require (
github.com/FloatTech/floatbox v0.0.0-20230111053652-a03d6334fadf // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect
github.com/fumiama/cron v1.3.0 // indirect
github.com/fumiama/go-base16384 v1.6.4 // indirect
Expand Down
16 changes: 11 additions & 5 deletions title.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (t *Title) DrawTitleWithText(info []string) (imgs image.Image, err error) {

// 加载size为108的字体
fontsize1, fontsize2 := 108.0, 54.0
err = canvas.LoadFontFace(t.TitleFont, fontsize1)
err = canvas.LoadFontFace(t.TextFont, fontsize1)
if err != nil {
return
}
Expand All @@ -102,8 +102,9 @@ func (t *Title) DrawTitleWithText(info []string) (imgs image.Image, err error) {
// 绘制标题
stringwight, _ := canvas.MeasureString(t.LeftTitle)
canvas.DrawStringAnchored(t.LeftTitle, 25+stringwight/2+t.OffsetX, 25+fontsize1*72/96*0.5+t.OffsetY, 0.5, 0.5)

// 加载size为54的字体
err = canvas.LoadFontFace(t.TextFont, fontsize2)
err = canvas.LoadFontFace(t.TitleFont, fontsize2)
if err != nil {
return
}
Expand All @@ -112,7 +113,7 @@ func (t *Title) DrawTitleWithText(info []string) (imgs image.Image, err error) {
stringwight, _ = canvas.MeasureString(t.LeftSubtitle)
canvas.DrawStringAnchored(t.LeftSubtitle, 25+3+stringwight/2+t.OffsetX, 25+fontsize1*72/96+25+fontsize2*72/96*0.5+t.OffsetY, 0.5, 0.5)

canvas.DrawRectangle(25+3+t.OffsetX, 25+fontsize1*72/96+25+fontsize2*72/96+5+t.OffsetY, stringwight, 6)
canvas.DrawRectangle(25+3+t.OffsetX, 25+fontsize1*72/96+25+fontsize2*72/96+7+t.OffsetY, stringwight, 6)
// 绘制插件开启状态
if t.IsEnabled {
canvas.SetRGBA255(35, 235, 35, 255)
Expand All @@ -122,6 +123,11 @@ func (t *Title) DrawTitleWithText(info []string) (imgs image.Image, err error) {
canvas.Fill()
canvas.SetRGBA255(15, 15, 15, 255)

err = canvas.LoadFontFace(t.TextFont, fontsize2)
if err != nil {
return
}

stringwight, _ = canvas.MeasureString(t.RightTitle)
canvas.DrawStringAnchored(t.RightTitle, DefaultWidth-40-stringwight/2+t.OffsetX, 40+fontsize2*72/96*0.5+t.OffsetY, 0.5, 0.5)
stringwight, _ = canvas.MeasureString(t.RightSubtitle)
Expand Down Expand Up @@ -167,14 +173,14 @@ func (t *Title) DrawCard() (imgs image.Image, err error) {
// 绘制插件信息
canvas.SetRGBA255(240, 240, 240, 255)
fontsize1, fontsize2 := 64.0, 32.0
err = canvas.LoadFontFace(t.TitleFont, fontsize1)
err = canvas.LoadFontFace(t.TextFont, fontsize1)
if err != nil {
return
}
stringwight, _ := canvas.MeasureString(t.LeftTitle)
canvas.DrawStringAnchored(t.LeftTitle, stringwight/2+(rech-rech*0.54-(fontsize1+fontsize2)*72/96)*0.33+t.OffsetX, rech*0.54+(rech-rech*0.54-(fontsize1+fontsize2)*72/96)*0.33+fontsize1*72/96*0.5+t.OffsetY, 0.5, 0.5)

err = canvas.LoadFontFace(t.TextFont, fontsize2)
err = canvas.LoadFontFace(t.TitleFont, fontsize2)
if err != nil {
return
}
Expand Down
12 changes: 6 additions & 6 deletions title_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestDrawTitleWithText(t *testing.T) {
img, err := (&Title{
Line: 0,
IsEnabled: true,
LeftTitle: "服务名",
LeftSubtitle: "instruction",
LeftTitle: "ServiceName",
LeftSubtitle: "简介",
RightTitle: "FloatTech",
RightSubtitle: "ZeroBot-Plugin",
TitleFont: "GlowSansSC-Normal-ExtraBold.ttf",
Expand All @@ -60,15 +60,15 @@ func TestDrawTitleWithText(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "3f18e919e69e38b2302d8b2fc31c4cb2", hex.EncodeToString(h.Sum(nil)))
assert.Equal(t, "bf5ce310c0a565477fa83904a506c08d", hex.EncodeToString(h.Sum(nil)))
}

func TestDrawCard(t *testing.T) {
img, err := (&Title{
Line: 0,
IsEnabled: true,
LeftTitle: "服务名",
LeftSubtitle: "instruction",
LeftTitle: "ServiceName",
LeftSubtitle: "简介",
TitleFont: "GlowSansSC-Normal-ExtraBold.ttf",
TextFont: "Impact.ttf",
ImagePath: ".github/warma.png",
Expand All @@ -85,5 +85,5 @@ func TestDrawCard(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "596186f97c3a4126a9d3a7b30b959810", hex.EncodeToString(h.Sum(nil)))
assert.Equal(t, "c7669d5cc76599abbd8d22b507d2102a", hex.EncodeToString(h.Sum(nil)))
}

0 comments on commit 56b6cb7

Please sign in to comment.