aboutsummaryrefslogtreecommitdiff
path: root/bdf-sample
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2019-04-06 21:31:11 +0200
committerPřemysl Janouch <p@janouch.name>2019-04-07 23:08:27 +0200
commitab253ce768c410f6c996fd3df98292df0554c2f3 (patch)
tree7b09a24e60689308620f00ff3d32bcdd40e92a83 /bdf-sample
downloadsklad-ab253ce768c410f6c996fd3df98292df0554c2f3.tar.gz
sklad-ab253ce768c410f6c996fd3df98292df0554c2f3.tar.xz
sklad-ab253ce768c410f6c996fd3df98292df0554c2f3.zip
Initial commit
Diffstat (limited to 'bdf-sample')
-rw-r--r--bdf-sample/main.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/bdf-sample/main.go b/bdf-sample/main.go
new file mode 100644
index 0000000..ae9072f
--- /dev/null
+++ b/bdf-sample/main.go
@@ -0,0 +1,41 @@
+package main
+
+import (
+ "image"
+ "image/draw"
+ "image/png"
+ "janouch.name/sklad/bdf"
+ "log"
+ "os"
+)
+
+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)
+ }
+}