aboutsummaryrefslogtreecommitdiff
path: root/cmd/bdf-sample/main.go
blob: 18501187c6f4c2ee408f7b2f955ab9e814f75151 (plain)
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
package main

import (
	"image"
	"image/draw"
	"image/png"
	"log"
	"os"

	"janouch.name/sklad/bdf"
)

func main() {
	fi, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatalln(err)
	}
	defer fi.Close()
	font, err := bdf.NewFromBDF(fi)
	if err != nil {
		log.Fatalln(err)
	}

	r, _ := font.BoundString(font.Name)
	super := r.Inset(-20)

	img := image.NewRGBA(super)
	draw.Draw(img, super, image.White, image.ZP, draw.Src)
	font.DrawString(img, image.ZP, font.Name)

	fo, err := os.Create("out.png")
	if err != nil {
		log.Fatalln(err)
	}
	if err := png.Encode(fo, img); err != nil {
		fo.Close()
		log.Fatal(err)
	}
	if err := fo.Close(); err != nil {
		log.Fatal(err)
	}
}