diff options
author | Kurt <kurt.w.jung@gmail.com> | 2019-09-07 09:17:24 -0400 |
---|---|---|
committer | Kurt <kurt.w.jung@gmail.com> | 2019-09-07 09:17:24 -0400 |
commit | fac5b8ac092fabeb667ca3e16212b5cc2fc0c4f1 (patch) | |
tree | 08ec04cb4469d1685189545b70ee3749ba420e76 /fpdf.go | |
parent | ced1e15bca902f15732b6380aaa4bdc419d87eac (diff) | |
parent | 29a8ebcc82176b98972f23e915f2afdf8a192bac (diff) |
Merge branch 'joewestcott-template-init'
Diffstat (limited to 'fpdf.go')
-rw-r--r-- | fpdf.go | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -4215,6 +4215,7 @@ func implode(sep string, arr []int) string { return s.String() } +// arrayCountValues counts the occurrences of each item in the $mp array. func arrayCountValues(mp []int) map[int]int { answer := make(map[int]int) for _, v := range mp { @@ -4243,11 +4244,31 @@ func (f *Fpdf) putimages() { for key = range f.images { keyList = append(keyList, key) } + + // Sort the keyList []string by the corresponding image's width. if f.catalogSort { sort.SliceStable(keyList, func(i, j int) bool { return f.images[keyList[i]].w < f.images[keyList[j]].w }) } + + // Maintain a list of inserted image SHA-1 hashes, with their + // corresponding object ID number. + insertedImages := map[string]int{} + for _, key = range keyList { - f.putimage(f.images[key]) + image := f.images[key] + + // Check if this image has already been inserted using it's SHA-1 hash. + insertedImageObjN, isFound := insertedImages[image.i] + + // If found, skip inserting the image as a new object, and + // use the object ID from the insertedImages map. + // If not, insert the image into the PDF and store the object ID. + if isFound { + image.n = insertedImageObjN + } else { + f.putimage(image) + insertedImages[image.i] = image.n + } } } |