Skip to content

Commit

Permalink
load all fonts if there is not set any
Browse files Browse the repository at this point in the history
  • Loading branch information
EricZhou committed Apr 12, 2021
1 parent 4009b92 commit 5dfa8d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions faq_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package base64Captcha

import "testing"

func TestHandlerCaptchaGenerate(t *testing.T) {
s := DefaultMemStore

driver := &DriverString{
Height: 80,
Width: 240,
NoiseCount: 10,
ShowLineOptions: 10,
Length: 10,
Source: "axclajsdlfkjalskjdglasdg",
BgColor: nil,
Fonts: nil,
}

c := NewCaptcha(driver, s)

id, _, err := c.Generate()
if err != nil {
t.Fatalf("some error: %s", err)
}

t.Logf("id: %s", id)
}
6 changes: 6 additions & 0 deletions fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func loadFontsByNames(assetFontNames []string) []*truetype.Font {
//randFontFrom choose random font family.选择随机的字体
func randFontFrom(fonts []*truetype.Font) *truetype.Font {
fontCount := len(fonts)

if fontCount == 0 {
//loading default fonts
fonts = fontsAll
fontCount = len(fontsAll)
}
index := rand.Intn(fontCount)
return fonts[index]
}
Expand Down

0 comments on commit 5dfa8d3

Please sign in to comment.