From 4a6557905020ad1a27470b79223dae94bb502822 Mon Sep 17 00:00:00 2001 From: Jay Bryant Date: Wed, 11 Apr 2007 02:59:55 +0000 Subject: [PATCH] Added sorting of the list of named destinations (necessary to have more than one destination in a document, unless you get lucky and have them in the proper order by coincidence) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@527380 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/pdf/PDFDocument.java | 30 +++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/java/org/apache/fop/pdf/PDFDocument.java b/src/java/org/apache/fop/pdf/PDFDocument.java index 09e1eccff..29cb88731 100644 --- a/src/java/org/apache/fop/pdf/PDFDocument.java +++ b/src/java/org/apache/fop/pdf/PDFDocument.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,7 +19,7 @@ package org.apache.fop.pdf; -// Java +/// Java import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -33,10 +33,13 @@ import java.util.List; import java.util.Map; import java.util.Iterator; import java.util.ArrayList; +import java.util.Collections; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.pdf.DestinationComparator; + /* image support modified from work of BoBoGi */ /* font support based on work by Takayuki Takeuchi */ @@ -64,13 +67,13 @@ import org.apache.commons.logging.LogFactory; public class PDFDocument { private static final Integer LOCATION_PLACEHOLDER = new Integer(0); - + /** Integer constant to represent PDF 1.3 */ public static final int PDF_VERSION_1_3 = 3; /** Integer constant to represent PDF 1.4 */ public static final int PDF_VERSION_1_4 = 4; - + /** * the encoding to use when converting strings to PDF commandos. */ @@ -108,12 +111,12 @@ public class PDFDocument { /** Indicates what PDF version is active */ protected int pdfVersion = PDF_VERSION_1_4; - + /** * Indicates which PDF profiles are active (PDF/A, PDF/X etc.) */ protected PDFProfile pdfProfile = new PDFProfile(this); - + /** * the /Root object */ @@ -280,7 +283,7 @@ public class PDFDocument { public int getPDFVersion() { return this.pdfVersion; } - + /** @return the String representing the active PDF version */ public String getPDFVersionString() { switch (getPDFVersion()) { @@ -297,7 +300,7 @@ public class PDFDocument { public PDFProfile getProfile() { return this.pdfProfile; } - + /** * Returns the factory for PDF objects. * @return PDFFactory the factory @@ -340,7 +343,7 @@ public class PDFDocument { /** * Set the creation date of the document. - * + * * @param date Date to be stored as creation date in the PDF. */ public void setCreationDate(Date date) { @@ -930,7 +933,7 @@ public class PDFDocument { this.position = 0; getProfile().verifyPDFVersion(); - + byte[] pdf = ("%PDF-" + getPDFVersionString() + "\n").getBytes(); stream.write(pdf); this.position += pdf.length; @@ -967,7 +970,7 @@ public class PDFDocument { } } } - + /** * write the trailer * @@ -976,6 +979,7 @@ public class PDFDocument { */ public void outputTrailer(OutputStream stream) throws IOException { if (hasDestinations) { + Collections.sort((ArrayList)destinations, new DestinationComparator()); limits = getFactory().makeLimits((ArrayList)destinations); dests = getFactory().makeDests(limits.referencePDF()); this.root.setNames(dests.referencePDF()); @@ -1057,4 +1061,4 @@ public class PDFDocument { return pdfBytes.length; } -} +} \ No newline at end of file -- 2.39.5