-
Notifications
You must be signed in to change notification settings - Fork 0
/
bdf-explorer.go
65 lines (56 loc) · 1.38 KB
/
bdf-explorer.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
package main
import (
"flag"
"fmt"
"github.com/ByteSizedMarius/bdf-explorer/bdf"
"os"
"path/filepath"
"strings"
)
func main() {
// Define command-line flags
fontFile := flag.String("font", "", "Path to the font file")
exportAll := flag.Bool("export", false, "Export all characters to individual images")
flag.Parse()
// Check if font file is provided
if *fontFile == "" {
fmt.Println("Please provide a font file")
os.Exit(1)
}
// Load the font
font, err := bdf.FromFile(*fontFile)
if err != nil {
fmt.Println("Error loading font:", err)
os.Exit(1)
}
fontName := filepath.Base(*fontFile)
fontName = strings.TrimSuffix(fontName, filepath.Ext(fontName))
fmt.Println("Font loaded:", fontName)
// Render the file
imgP := fontName + ".png"
err = font.RenderFontImage(imgP, 5)
if err != nil {
fmt.Println("Error rendering font:", err)
os.Exit(1)
}
fmt.Println("Font image saved to", imgP)
if !*exportAll {
return
}
// Create a directory for the single imgs
err = os.Mkdir(fontName, 0755)
if err != nil {
fmt.Println("Error creating directory:", err)
os.Exit(1)
}
// Render each character
for i, char := range font.Characters {
err = char.RenderCharacterImage(fontName)
if err != nil {
fmt.Println("Error rendering character:", err)
os.Exit(1)
}
fmt.Printf("\rRendering character %d of %d", i+1, len(font.Characters))
}
fmt.Println("\nDone")
}