diff options
author | Nick White <git@njw.name> | 2019-11-12 16:08:05 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2019-11-12 16:08:05 +0000 |
commit | 656e6a50ef50ad73b2039cb1193dc84ac1883541 (patch) | |
tree | f150c7151efbcc32565e55d1fe0d07275ba5b180 | |
parent | a46b217fd34f1bb3ee9f675fcb24cbc9a8cc2847 (diff) |
Add fonttobytes, to embed the font into pdf tools in due course
-rw-r--r-- | fonttobytes/main.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/fonttobytes/main.go b/fonttobytes/main.go new file mode 100644 index 0000000..ed0752c --- /dev/null +++ b/fonttobytes/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "bytes" + "compress/zlib" + "flag" + "fmt" + "io/ioutil" + "log" + "os" +) + +func main() { + flag.Usage = func() { + fmt.Fprintln(flag.CommandLine.Output(), "Usage: fonttobytes font.ttf") + flag.PrintDefaults() + } + flag.Parse() + + if flag.NArg() != 1 { + flag.Usage() + return + } + + f, err := os.Open(flag.Arg(0)) + if err != nil { + log.Fatalln("Failed to open file", flag.Arg(0), err) + } + fontbytes, err := ioutil.ReadAll(f) + if err != nil { + log.Fatalln("Failed to read file", flag.Arg(0), err) + } + + var compressed bytes.Buffer + w := zlib.NewWriter(&compressed) + w.Write(fontbytes) + w.Close() + + fmt.Printf("[]byte{") + first := true + for _, b := range compressed.Bytes() { + if first { + fmt.Printf("%d", b) + first = false + continue + } + fmt.Printf(", %d", b) + } + fmt.Printf("}\n") +} |