diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2020-09-06 04:38:41 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2020-09-06 05:16:40 +0200 |
commit | af6a9370336a94147c5f93eef0978c34ab504482 (patch) | |
tree | 079bdba090f7f793ea0f804b7bfb9ec2d4953522 | |
parent | 8913f8ba9cf6a8fbc6c0f96cd3cd967b2161f0f7 (diff) | |
download | pdf-simple-sign-af6a9370336a94147c5f93eef0978c34ab504482.tar.gz pdf-simple-sign-af6a9370336a94147c5f93eef0978c34ab504482.tar.xz pdf-simple-sign-af6a9370336a94147c5f93eef0978c34ab504482.zip |
Go: avoid non-deterministic output
The code has even turned out simpler.
-rw-r--r-- | pdf/pdf.go | 36 |
1 files changed, 16 insertions, 20 deletions
@@ -853,30 +853,19 @@ func (u *Updater) FlushUpdates() { return updated[i] < updated[j] }) - groups := make(map[uint]uint) - for i := 0; i < len(updated); { - start, count := updated[i], uint(1) - for i++; i != len(updated) && updated[i] == start+count; i++ { - count++ - } - groups[start] = count - } - - // Taking literally "Each cross-reference section begins with a line - // containing the keyword xref. Following this line are one or more - // cross-reference subsections." from 3.4.3 in PDF Reference. - if len(groups) == 0 { - groups[0] = 0 - } - buf := bytes.NewBuffer(u.Document) startXref := buf.Len() + 1 buf.WriteString("\nxref\n") - for start, count := range groups { - fmt.Fprintf(buf, "%d %d\n", start, count) - for i := uint(0); i < count; i++ { - ref := u.xref[start+uint(i)] + for i := 0; i < len(updated); { + start, stop := updated[i], updated[i]+1 + for i++; i < len(updated) && updated[i] == stop; i++ { + stop++ + } + + fmt.Fprintf(buf, "%d %d\n", start, stop-start) + for ; start < stop; start++ { + ref := u.xref[start] if ref.nonfree { fmt.Fprintf(buf, "%010d %05d n \n", ref.offset, ref.generation) } else { @@ -885,6 +874,13 @@ func (u *Updater) FlushUpdates() { } } + // Taking literally "Each cross-reference section begins with a line + // containing the keyword xref. Following this line are one or more + // cross-reference subsections." from 3.4.3 in PDF Reference. + if len(updated) == 0 { + fmt.Fprintf(buf, "%d %d\n", 0, 0) + } + u.Trailer["Size"] = NewNumeric(float64(u.xrefSize)) trailer := NewDict(u.Trailer) |