From 488ae5c11cf7be4a8f35f6f82e19dda22663bcbf Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 1 Nov 2019 15:53:08 +0000 Subject: Compress the font with zlib, and include it in repo --- cmd/fonttobytes/main.go | 29 ++++++++++++++++++++++------- cmd/pdfbook/main.go | 5 ++++- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'cmd') diff --git a/cmd/fonttobytes/main.go b/cmd/fonttobytes/main.go index 9db47e4..011baa1 100644 --- a/cmd/fonttobytes/main.go +++ b/cmd/fonttobytes/main.go @@ -1,11 +1,12 @@ package main import ( + "bytes" + "compress/zlib" "flag" "fmt" "io/ioutil" "log" - "strings" ) func main() { @@ -20,13 +21,27 @@ func main() { return } - b, err := ioutil.ReadFile(flag.Arg(0)) + font, err := ioutil.ReadFile(flag.Arg(0)) if err != nil { log.Fatalln(err) } - s := fmt.Sprintf("%v", b) - s1 := strings.Replace(s, "[", "{", -1) - s2 := strings.Replace(s1, "]", "}", -1) - s3 := strings.Replace(s2, " ", ", ", -1) - fmt.Printf("[]byte%s\n", s3) + + // 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)) -- cgit v1.2.1-24-ge1ad