From 6993fe6ea4223dca30d0cae9fa0bd9a3cdfdb12d Mon Sep 17 00:00:00 2001 From: Paul Montag Date: Mon, 5 Nov 2018 15:50:58 -0600 Subject: fixed pointer values when mutltiple templates are used --- template_impl.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'template_impl.go') diff --git a/template_impl.go b/template_impl.go index 9e5d496..b1b2382 100644 --- a/template_impl.go +++ b/template_impl.go @@ -3,6 +3,7 @@ package gofpdf import ( "bytes" "encoding/gob" + "reflect" ) /* @@ -136,9 +137,26 @@ func (t *FpdfTpl) GobDecode(buf []byte) error { } } + t.relinkPointers(t.images) + return err } +func (t *FpdfTpl) relinkPointers(images map[string]*ImageInfoType) { + for gKey, _ := range images { + for key, _ := range t.images { + if reflect.DeepEqual(t.images[key], images[gKey]) { + t.images[key] = images[gKey] + } + } + } + + for x := 0; x < len(t.templates); x++ { + innerT := t.templates[x].(*FpdfTpl) + innerT.relinkPointers(t.images) + } +} + // Tpl is an Fpdf used for writing a template. It has most of the facilities of // an Fpdf, but cannot add more pages. Tpl is used directly only during the // limited time a template is writable. -- cgit v1.2.1-24-ge1ad