@@ -10,18 +10,18 @@ import (
10
10
11
11
const FontPath = "sources"
12
12
13
- type Source struct {
13
+ type Font struct {
14
14
fs embed.FS
15
15
}
16
16
17
- func NewSource (fs embed.FS ) * Source {
18
- return & Source {fs : fs }
17
+ func NewFont (fs embed.FS ) * Font {
18
+ return & Font {fs : fs }
19
19
}
20
20
21
21
// LoadFont load font from file.
22
- func (s * Source ) LoadFont (name string ) * truetype.Font {
22
+ func (f * Font ) LoadFont (name string ) * truetype.Font {
23
23
fontPath := strings .Trim (FontPath , "/" )
24
- fontBytes , err := s .fs .ReadFile (fontPath + "/" + name )
24
+ fontBytes , err := f .fs .ReadFile (fontPath + "/" + name )
25
25
if err != nil {
26
26
panic (err .Error ())
27
27
}
@@ -35,21 +35,20 @@ func (s *Source) LoadFont(name string) *truetype.Font {
35
35
36
36
// LoadFonts load fonts from dir.
37
37
// make the simple-font(RitaSmith.ttf) the first font of trueTypeFonts.
38
- func (s * Source ) LoadFonts (names []string ) []* truetype.Font {
38
+ func (f * Font ) LoadFonts (names []string ) []* truetype.Font {
39
39
if len (names ) == 0 {
40
40
return nil
41
41
}
42
42
fonts := make ([]* truetype.Font , 0 )
43
43
for _ , name := range names {
44
- f := s .LoadFont (name )
45
- fonts = append (fonts , f )
44
+ fonts = append (fonts , f .LoadFont (name ))
46
45
}
47
46
return fonts
48
47
}
49
48
50
49
// LoadAll load all fonts.
51
- func (s * Source ) LoadAll () []* truetype.Font {
52
- return s .LoadFonts ([]string {
50
+ func (f * Font ) LoadAll () []* truetype.Font {
51
+ return f .LoadFonts ([]string {
53
52
"3Dumb.ttf" ,
54
53
"ApothecaryFont.ttf" ,
55
54
"Comismsh.ttf" ,
@@ -64,6 +63,6 @@ func (s *Source) LoadAll() []*truetype.Font {
64
63
}
65
64
66
65
// LoadChinese load Chinese font.
67
- func (s * Source ) LoadChinese () * truetype.Font {
68
- return s .LoadFont ("wqy-microhei.ttc" )
66
+ func (f * Font ) LoadChinese () * truetype.Font {
67
+ return f .LoadFont ("wqy-microhei.ttc" )
69
68
}
0 commit comments