From 641cda87ac3cf98cf58400cb3ce7513b6cc74295 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 6 May 2019 21:22:13 -0400 Subject: Check for errors when loading UTF-8 font --- fpdf.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/fpdf.go b/fpdf.go index cd87ad9..0195cd3 100644 --- a/fpdf.go +++ b/fpdf.go @@ -1599,17 +1599,26 @@ func (f *Fpdf) addFont(familyStr, styleStr, fileStr string, isUTF8 bool) { if ok { return } - ttfStat, _ := os.Stat(fileStr) + var ttfStat os.FileInfo + var err error + ttfStat, err = os.Stat(fileStr) + if err != nil { + f.SetError(err) + return + } originalSize := ttfStat.Size() Type := "UTF8" - - utf8Bytes, _ := ioutil.ReadFile(fileStr) + var utf8Bytes []byte + utf8Bytes, err = ioutil.ReadFile(fileStr) + if err != nil { + f.SetError(err) + return + } reader := fileReader{readerPosition: 0, array: utf8Bytes} utf8File := newUTF8Font(&reader) - - err := utf8File.parseFile() + err = utf8File.parseFile() if err != nil { - fmt.Printf("get metrics Error: %e\n", err) + f.SetError(err) return } -- cgit v1.2.1-24-ge1ad