From 67dbdc6f213695af48d5fce5ffcfeb14d0b685bf Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 12 Jun 2017 10:42:40 -0400 Subject: Trigger an error when attempting to render text if font has not been set --- fpdf.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'fpdf.go') diff --git a/fpdf.go b/fpdf.go index 78a7c65..c862364 100644 --- a/fpdf.go +++ b/fpdf.go @@ -1793,6 +1793,9 @@ func (f *Fpdf) SetAcceptPageBreakFunc(fnc func() bool) { // current position moves to the right or to the next line. It is possible to // put a link on the text. // +// An error will be returned if a call to SetFont() has not already taken +// place before this method is called. +// // If automatic page breaking is enabled and the cell goes beyond the limit, a // page break is done before outputting. // @@ -1823,11 +1826,18 @@ func (f *Fpdf) SetAcceptPageBreakFunc(fnc func() bool) { // // linkStr is a target URL or empty for no external link. A non--zero value for // link takes precedence over linkStr. -func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int, alignStr string, fill bool, link int, linkStr string) { +func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int, + alignStr string, fill bool, link int, linkStr string) { // dbg("CellFormat. h = %.2f, borderStr = %s", h, borderStr) if f.err != nil { return } + + if f.currentFont.Name == "" { + f.err = fmt.Errorf("font has not been set; unable to render text") + return + } + borderStr = strings.ToUpper(borderStr) k := f.k if f.y+h > f.pageBreakTrigger && !f.inHeader && !f.inFooter && f.acceptPageBreak() { -- cgit v1.2.1-24-ge1ad