Skip to content

Commit

Permalink
Initialize derived template with parent images
Browse files Browse the repository at this point in the history
  • Loading branch information
joewestcott committed Sep 4, 2019
1 parent f8eb4ab commit f9ddde9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions template_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit f9ddde9

Please sign in to comment.