View | Details | Raw Unified | Return to bug 50852
Collapse All | Expand All

(-)a/src/java/org/apache/fop/pdf/PDFClearable.java (+34 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
/* $Id: PDFWritable.java 679326 2008-07-24 09:35:34Z vhennebert $ */
19
20
package org.apache.fop.pdf;
21
22
/**
23
 * This interface is implemented by classes that can be serialized to a PDF file either by
24
 * serializing the object or by writing a indirect reference to the actual object.
25
 * The object supports clearing the content after writing.
26
 */
27
public interface PDFClearable extends PDFWritable {
28
29
    /**
30
     * Clear object content
31
     */
32
    void clear();
33
34
}
(-)a/src/java/org/apache/fop/pdf/PDFDocument.java (-2 / +50 lines)
Lines 98-103 public class PDFDocument { Link Here
98
    /** the objects themselves */
98
    /** the objects themselves */
99
    private List objects = new LinkedList();
99
    private List objects = new LinkedList();
100
100
101
    /** the objects themselves (to be cleared after writing) */
102
    private List clearobjects = new LinkedList();
103
101
    /** Indicates what PDF version is active */
104
    /** Indicates what PDF version is active */
102
    private int pdfVersion = PDF_VERSION_1_4;
105
    private int pdfVersion = PDF_VERSION_1_4;
103
106
Lines 378-383 public class PDFDocument { Link Here
378
    }
381
    }
379
382
380
    /**
383
    /**
384
     * Registers a {@link PDFObject} in this PDF document.
385
     * The object is assigned a new object number.
386
     *
387
     * @param obj {@link PDFObject} to add
388
     * @param clear object after writing
389
     * @return the added {@link PDFObject} added (with its object number set)
390
     */
391
    public PDFObject registerObject(PDFObject obj, boolean clear) {
392
        assignObjectNumber(obj);
393
        addObject(obj, clear);
394
        return obj;
395
    }
396
397
    /**
381
     * Assigns the {@link PDFObject} an object number,
398
     * Assigns the {@link PDFObject} an object number,
382
     * and sets the parent of the {@link PDFObject} to this document.
399
     * and sets the parent of the {@link PDFObject} to this document.
383
     *
400
     *
Lines 413-418 public class PDFDocument { Link Here
413
     * @param obj {@link PDFObject} to add
430
     * @param obj {@link PDFObject} to add
414
     */
431
     */
415
    public void addObject(PDFObject obj) {
432
    public void addObject(PDFObject obj) {
433
        addObject(obj, false);
434
    }
435
436
    /**
437
     * Adds a {@link PDFObject} to this document.
438
     * The object <em>MUST</em> have an object number assigned.
439
     *
440
     * @param obj {@link PDFObject} to add
441
     * @param clear Clear object after writing (if possible)
442
     */
443
    public void addObject(PDFObject obj, boolean clear) {
416
        if (obj == null) {
444
        if (obj == null) {
417
            throw new NullPointerException("obj must not be null");
445
            throw new NullPointerException("obj must not be null");
418
        }
446
        }
Lines 423-429 public class PDFDocument { Link Here
423
        }
451
        }
424
452
425
        //Add object to list
453
        //Add object to list
426
        this.objects.add(obj);
454
        if (clear)
455
            this.clearobjects.add(obj);
456
        else
457
            this.objects.add(obj);
427
458
428
        //Add object to special lists where necessary
459
        //Add object to special lists where necessary
429
        if (obj instanceof PDFFunction) {
460
        if (obj instanceof PDFFunction) {
Lines 927-932 public class PDFDocument { Link Here
927
            this.position += object.output(stream);
958
            this.position += object.output(stream);
928
        }
959
        }
929
960
961
        while (this.clearobjects.size() > 0) {
962
            /* Retrieve first */
963
            PDFObject object = (PDFObject)this.clearobjects.remove(0);
964
            /*
965
             * add the position of this object to the list of object
966
             * locations
967
             */
968
            setLocation(object.getObjectNumber() - 1, this.position);
969
970
            /*
971
             * output the object and increment the character position
972
             * by the object's length
973
             */
974
            this.position += object.output(stream);
975
            if (object instanceof PDFClearable)
976
                ((PDFClearable)object).clear();
977
        }
978
930
        //Clear all objects written to the file
979
        //Clear all objects written to the file
931
        //this.objects.clear();
980
        //this.objects.clear();
932
    }
981
    }
933
- 

Return to bug 50852