From f9ddde9937c7b2c043599459877e5a695d667f0e Mon Sep 17 00:00:00 2001 From: Joe Westcott Date: Wed, 4 Sep 2019 15:33:02 +0100 Subject: Initialize derived template with parent images --- template.go | 11 +++++++++++ template_impl.go | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/template.go b/template.go index 31204c2..c0d3933 100644 --- a/template.go +++ b/template.go @@ -84,7 +84,18 @@ func (f *Fpdf) UseTemplateScaled(t Template, corner PointType, size SizeType) { for _, tt := range t.Templates() { f.templates[tt.ID()] = tt } + + // Create a list of existing image SHA-1 hashes. + existingImages := map[string]bool{} + for _, image := range f.images { + existingImages[image.i] = true + } + + // Add each template image to $f, unless already present. for name, ti := range t.Images() { + if _, found := existingImages[ti.i]; found { + continue + } name = sprintf("t%s-%s", t.ID(), name) f.images[name] = ti } diff --git a/template_impl.go b/template_impl.go index c5d7be8..c1e2dff 100644 --- a/template_impl.go +++ b/template_impl.go @@ -296,4 +296,8 @@ func (t *Tpl) loadParamsFromFpdf(f *Fpdf) { t.Fpdf.fontSizePt = f.fontSizePt t.Fpdf.fontStyle = f.fontStyle t.Fpdf.ws = f.ws + + for key, value := range f.images { + t.Fpdf.images[key] = value + } } -- cgit v1.2.1-24-ge1ad