Skip to content

Commit 0c7d1c4

Browse files
committed
FOP-3122 Copy bookmarks
1 parent 207ed8e commit 0c7d1c4

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.security.MessageDigest;
2828
import java.security.NoSuchAlgorithmException;
2929
import java.util.ArrayList;
30-
import java.util.Collection;
3130
import java.util.Collections;
3231
import java.util.Date;
3332
import java.util.HashMap;
@@ -1043,26 +1042,30 @@ public PDFReference resolveExtensionReference(String id) {
10431042
* @throws IOException if there is an exception writing to the output stream
10441043
*/
10451044
public void output(OutputStream stream) throws IOException {
1045+
output(stream, objects);
1046+
}
1047+
1048+
private void output(OutputStream stream, List<? extends PDFObject> objs) throws IOException {
10461049
outputStarted = true;
10471050
//Write out objects until the list is empty. This approach (used with a
10481051
//LinkedList) allows for output() methods to create and register objects
10491052
//on the fly even during serialization.
10501053

10511054
if (objectStreamsEnabled) {
1052-
List<PDFObject> indirectObjects = new ArrayList<>();
1053-
while (objects.size() > 0) {
1054-
PDFObject object = objects.remove(0);
1055+
List indirectObjects = new ArrayList<>();
1056+
while (!objs.isEmpty()) {
1057+
PDFObject object = objs.remove(0);
10551058
if (object.supportsObjectStream()) {
10561059
addToObjectStream(object);
10571060
} else {
10581061
indirectObjects.add(object);
10591062
}
10601063
}
1061-
objects.addAll(indirectObjects);
1064+
objs.addAll(indirectObjects);
10621065
}
10631066

1064-
while (objects.size() > 0) {
1065-
PDFObject object = objects.remove(0);
1067+
while (!objs.isEmpty()) {
1068+
PDFObject object = objs.remove(0);
10661069
streamIndirectObject(object, stream);
10671070
}
10681071
}
@@ -1099,13 +1102,6 @@ protected int streamIndirectObject(PDFObject o, OutputStream stream) throws IOEx
10991102
return len;
11001103
}
11011104

1102-
private void streamIndirectObjects(Collection<? extends PDFObject> objects, OutputStream stream)
1103-
throws IOException {
1104-
for (PDFObject o : objects) {
1105-
streamIndirectObject(o, stream);
1106-
}
1107-
}
1108-
11091105
private void recordObjectOffset(PDFObject object) {
11101106
int index = object.getObjectNumber().getNumber() - 1;
11111107
while (indirectObjectOffsets.size() <= index) {
@@ -1174,6 +1170,7 @@ public void outputHeader(OutputStream stream) throws IOException {
11741170
public void outputTrailer(OutputStream stream) throws IOException {
11751171
createDestinations();
11761172
output(stream);
1173+
objects = trailerObjects;
11771174
outputTrailerObjectsAndXref(stream);
11781175
}
11791176

@@ -1203,7 +1200,7 @@ private void outputTrailerObjectsAndXref(OutputStream stream) throws IOException
12031200
}
12041201
trailerOutputHelper.outputStructureTreeElements(stream);
12051202
}
1206-
streamIndirectObjects(trailerObjects, stream);
1203+
output(stream, trailerObjects);
12071204
TrailerDictionary trailerDictionary = createTrailerDictionary(true);
12081205
long startxref = trailerOutputHelper.outputCrossReferenceObject(stream, trailerDictionary, 0,
12091206
indirectObjectOffsets.size(), indirectObjectOffsets.size());
@@ -1267,7 +1264,7 @@ private class UncompressedTrailerOutputHelper implements TrailerOutputHelper {
12671264

12681265
public void outputStructureTreeElements(OutputStream stream)
12691266
throws IOException {
1270-
streamIndirectObjects(structureTreeElements, stream);
1267+
output(stream, structureTreeElements);
12711268
}
12721269

12731270
public long outputCrossReferenceObject(OutputStream stream,

fop-core/src/test/java/org/apache/fop/pdf/PDFObjectStreamTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ public class PDFObjectStreamTestCase {
3737
public void testObjectStreamsEnabled() throws IOException {
3838
PDFDocument doc = new PDFDocument("");
3939
String out = buildObjectStreamsPDF(doc);
40-
Assert.assertTrue(out, out.contains("<<\n /Type /ObjStm\n /N 3\n /First 15\n /Length 260\n>>\n"
41-
+ "stream\n8 0\n9 52\n4 121\n<<\n/Producer"));
40+
Assert.assertTrue(out, out.contains("<<\n /Type /ObjStm\n /N 6\n /First 33\n /Length 446\n>>\n"
41+
+ "stream\n4 0\n5 52\n6 121\n7 245\n8 287\n9 344\n<<\n/Producer"));
4242
}
4343

4444
@Test
4545
public void testObjectStreamsWithEncryption() throws IOException {
4646
PDFDocument doc = new PDFDocument("");
4747
doc.setEncryption(new PDFEncryptionParams());
4848
String out = buildObjectStreamsPDF(doc);
49-
Assert.assertTrue(out, out.contains("<<\n /Type /ObjStm\n /N 3\n /First 16\n /Length"));
49+
Assert.assertTrue(out, out.contains("<<\n /Type /ObjStm\n /N 5\n /First 28\n /Length"));
5050
}
5151

5252
private String buildObjectStreamsPDF(PDFDocument doc) throws IOException {

0 commit comments

Comments
 (0)