summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/fonttobytes/main.go47
-rw-r--r--cmd/pdfbook/main.go5
2 files changed, 51 insertions, 1 deletions
diff --git a/cmd/fonttobytes/main.go b/cmd/fonttobytes/main.go
new file mode 100644
index 0000000..011baa1
--- /dev/null
+++ b/cmd/fonttobytes/main.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "bytes"
+ "compress/zlib"
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "log"
+)
+
+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
+ }
+
+ font, err := ioutil.ReadFile(flag.Arg(0))
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ // compress with zlib
+ var buf bytes.Buffer
+ w := zlib.NewWriter(&buf)
+ w.Write(font)
+ w.Close()
+
+ // this could be done more simply with %+v, but that takes up
+ // significantly more space due to printing each byte in hex
+ // rather than dec format.
+
+ fmt.Printf("[]byte{")
+ for i, b := range buf.Bytes() {
+ if i > 0 {
+ fmt.Printf(", ")
+ }
+ fmt.Printf("%d", b)
+ }
+ fmt.Printf("}\n")
+}
diff --git a/cmd/pdfbook/main.go b/cmd/pdfbook/main.go
index bdb486d..79db353 100644
--- a/cmd/pdfbook/main.go
+++ b/cmd/pdfbook/main.go
@@ -112,7 +112,10 @@ func main() {
}
pdf := new(bookpipeline.Fpdf)
- pdf.Setup()
+ err = pdf.Setup()
+ if err != nil {
+ log.Fatalln("Failed to set up PDF", err)
+ }
if os.IsNotExist(err) {
err = filepath.Walk(flag.Arg(0), walker(pdf, *colour))