forked from adrg/sysfont
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
72 lines (61 loc) · 1.32 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package sysfont_test
import (
"fmt"
"github.com/adrg/sysfont"
)
func ExampleNewFinder() {
// Create a new font finder using the default options.
finder := sysfont.NewFinder(nil)
// Create a new finder which only searches for TTF files.
finder = sysfont.NewFinder(&sysfont.FinderOpts{
Extensions: []string{".ttf"},
})
// List detected fonts.
for _, font := range finder.List() {
fmt.Println(font.Family, font.Name, font.Filename)
}
}
func ExampleFinder_List() {
finder := sysfont.NewFinder(nil)
for _, font := range finder.List() {
fmt.Println(font.Family, font.Name, font.Filename)
}
}
func ExampleFinder_Match() {
finder := sysfont.NewFinder(nil)
terms := []string{
"AmericanTypewriter",
"AmericanTypewriter-Bold",
"Andale",
"Arial",
"Arial Bold",
"Arial-BoldItalicMT",
"ArialMT",
"Baskerville",
"Candara",
"Corbel",
"Gill Sans",
"Hoefler Text Bold",
"Impact",
"Palatino",
"Symbol",
"Tahoma",
"Times",
"Times Bold",
"Times BoldItalic",
"Times Italic Bold",
"Times Roman",
"Verdana",
"Verdana-Italic",
"Webdings",
"ZapfDingbats",
}
for _, term := range terms {
font := finder.Match(term)
if font == nil {
// Match should always return a font. However, it is safer to check.
continue
}
fmt.Printf("%-30s -> %-30s (%s)\n", term, font.Name, font.Filename)
}
}