summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Bakun <abakun@easypost.com>2018-02-03 09:30:12 +0000
committerAndy Bakun <abakun@easypost.com>2018-02-03 09:30:12 +0000
commit7dba5968392517e366ba4cfe4b3a44f9375849ba (patch)
tree7338a5f78613b7b018c2e962d5b56e8e95cd6709
parentdb5f2eb6b1ec30bc26c7454d8341249aeb8fbd36 (diff)
sort the objs in the output more consistently
When CatalogSort is enabled, the sort.Strings routine is used to order the "keys" used for the various objects being put into the PDF. Use sort.SliceStable instead, and specify a function Less function that, if possible, uses an attribute of the objs being sorted. This is more deterministic.
-rw-r--r--fpdf.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/fpdf.go b/fpdf.go
index ad29d18..b8875a5 100644
--- a/fpdf.go
+++ b/fpdf.go
@@ -3199,7 +3199,7 @@ func (f *Fpdf) putfonts() {
fileList = append(fileList, file)
}
if f.catalogSort {
- sort.Strings(fileList)
+ sort.SliceStable(fileList, func(i, j int) bool { return fileList[i] < fileList[j] })
}
for _, file = range fileList {
info = f.fontFiles[file]
@@ -3249,7 +3249,7 @@ func (f *Fpdf) putfonts() {
keyList = append(keyList, key)
}
if f.catalogSort {
- sort.Strings(keyList)
+ sort.SliceStable(keyList, func(i, j int) bool { return keyList[i] < keyList[j] })
}
for _, key = range keyList {
font = f.fonts[key]
@@ -3350,7 +3350,7 @@ func (f *Fpdf) putimages() {
keyList = append(keyList, key)
}
if f.catalogSort {
- sort.Strings(keyList)
+ sort.SliceStable(keyList, func(i, j int) bool { return f.images[keyList[i]].w < f.images[keyList[j]].w })
}
for _, key = range keyList {
f.putimage(f.images[key])
@@ -3430,7 +3430,7 @@ func (f *Fpdf) putxobjectdict() {
keyList = append(keyList, key)
}
if f.catalogSort {
- sort.Strings(keyList)
+ sort.SliceStable(keyList, func(i, j int) bool { return f.images[keyList[i]].i < f.images[keyList[j]].i })
}
for _, key = range keyList {
image = f.images[key]
@@ -3464,7 +3464,7 @@ func (f *Fpdf) putresourcedict() {
keyList = append(keyList, key)
}
if f.catalogSort {
- sort.Strings(keyList)
+ sort.SliceStable(keyList, func(i, j int) bool { return f.fonts[keyList[i]].I < f.fonts[keyList[j]].I })
}
for _, key = range keyList {
font = f.fonts[key]