PdfContents.java

1
/*
2
 * $Id: PdfContents.java 3634 2008-12-23 18:44:04Z xlv $
3
 *
4
 * Copyright 1999, 2000, 2001, 2002 Bruno Lowagie
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * (the "License"); you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the License.
13
 *
14
 * The Original Code is 'iText, a free JAVA-PDF library'.
15
 *
16
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
17
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
18
 * All Rights Reserved.
19
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
20
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
21
 *
22
 * Contributor(s): all the names of the contributors are added in the source code
23
 * where applicable.
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of the
26
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
27
 * provisions of LGPL are applicable instead of those above.  If you wish to
28
 * allow use of your version of this file only under the terms of the LGPL
29
 * License and not to allow others to use your version of this file under
30
 * the MPL, indicate your decision by deleting the provisions above and
31
 * replace them with the notice and other provisions required by the LGPL.
32
 * If you do not delete the provisions above, a recipient may use your version
33
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
34
 *
35
 * This library is free software; you can redistribute it and/or modify it
36
 * under the terms of the MPL as stated above or under the terms of the GNU
37
 * Library General Public License as published by the Free Software Foundation;
38
 * either version 2 of the License, or any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful, but WITHOUT
41
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
42
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
43
 * details.
44
 *
45
 * If you didn't download this code from the following link, you should check if
46
 * you aren't using an obsolete version:
47
 * http://www.lowagie.com/iText/
48
 */
49
50
package com.lowagie.text.pdf;
51
52
import java.io.ByteArrayOutputStream;
53
import java.io.OutputStream;
54
import java.util.zip.Deflater;
55
import java.util.zip.DeflaterOutputStream;
56
57
import com.lowagie.text.DocWriter;
58
import com.lowagie.text.Document;
59
import com.lowagie.text.Rectangle;
60
61
/**
62
 * <CODE>PdfContents</CODE> is a <CODE>PdfStream</CODE> containing the contents (text + graphics) of a <CODE>PdfPage</CODE>.
63
 */
64
65
class PdfContents extends PdfStream {
66
67
    static final byte[] SAVESTATE = DocWriter.getISOBytes("q\n");
68
    static final byte[] RESTORESTATE = DocWriter.getISOBytes("Q\n");
69
    static final byte[] ROTATE90 = DocWriter.getISOBytes("0 1 -1 0 ");
70
    static final byte[] ROTATE180 = DocWriter.getISOBytes("-1 0 0 -1 ");
71
    static final byte[] ROTATE270 = DocWriter.getISOBytes("0 -1 1 0 ");
72
    static final byte[] ROTATEFINAL = DocWriter.getISOBytes(" cm\n");
73
    // constructor
74
    
75
/**
76
 * Constructs a <CODE>PdfContents</CODE>-object, containing text and general graphics.
77
 *
78
 * @param under the direct content that is under all others
79
 * @param content the graphics in a page
80
 * @param text the text in a page
81
 * @param secondContent the direct content that is over all others
82
 * @throws BadPdfFormatException on error
83
 */
84
    
85
    PdfContents(PdfContentByte under, PdfContentByte content, PdfContentByte text, PdfContentByte secondContent, Rectangle page) throws BadPdfFormatException {
86
        super();
87
        try {
88
            OutputStream out = null;
89
            Deflater deflater = null;
90
            streamBytes = new ByteArrayOutputStream();
91 1 1. : negated conditional → NO_COVERAGE
            if (Document.compress)
92
            {
93
                compressed = true;
94
                compressionLevel = text.getPdfWriter().getCompressionLevel();
95
                deflater = new Deflater(compressionLevel);
96
                out = new DeflaterOutputStream(streamBytes, deflater);
97
            }
98
            else
99
                out = streamBytes;
100
            int rotation = page.getRotation();
101
            switch (rotation) {
102
                case 90:
103 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(ROTATE90);
104 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.getTop())));
105 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(' ');
106 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write('0');
107 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(ROTATEFINAL);
108
                    break;
109
                case 180:
110 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(ROTATE180);
111 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.getRight())));
112 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(' ');
113 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.getTop())));
114 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(ROTATEFINAL);
115
                    break;
116
                case 270:
117 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(ROTATE270);
118 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write('0');
119 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(' ');
120 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(DocWriter.getISOBytes(ByteBuffer.formatDouble(page.getRight())));
121 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                    out.write(ROTATEFINAL);
122
                    break;
123
            }
124 2 1. : changed conditional boundary → NO_COVERAGE
2. : negated conditional → NO_COVERAGE
            if (under.size() > 0) {
125 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                out.write(SAVESTATE);
126 1 1. : removed call to com/lowagie/text/pdf/ByteBuffer::writeTo → NO_COVERAGE
                under.getInternalBuffer().writeTo(out);
127 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                out.write(RESTORESTATE);
128
            }
129 2 1. : changed conditional boundary → NO_COVERAGE
2. : negated conditional → NO_COVERAGE
            if (content.size() > 0) {
130 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                out.write(SAVESTATE);
131 1 1. : removed call to com/lowagie/text/pdf/ByteBuffer::writeTo → NO_COVERAGE
                content.getInternalBuffer().writeTo(out);
132 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                out.write(RESTORESTATE);
133
            }
134 1 1. : negated conditional → NO_COVERAGE
            if (text != null) {
135 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                out.write(SAVESTATE);
136 1 1. : removed call to com/lowagie/text/pdf/ByteBuffer::writeTo → NO_COVERAGE
                text.getInternalBuffer().writeTo(out);
137 1 1. : removed call to java/io/OutputStream::write → NO_COVERAGE
                out.write(RESTORESTATE);
138
            }
139 2 1. : changed conditional boundary → NO_COVERAGE
2. : negated conditional → NO_COVERAGE
            if (secondContent.size() > 0) {
140 1 1. : removed call to com/lowagie/text/pdf/ByteBuffer::writeTo → NO_COVERAGE
                secondContent.getInternalBuffer().writeTo(out);
141
            }
142 1 1. : removed call to java/io/OutputStream::close → NO_COVERAGE
            out.close();
143 1 1. : negated conditional → NO_COVERAGE
            if (deflater != null) {
144 1 1. : removed call to java/util/zip/Deflater::end → NO_COVERAGE
                deflater.end();
145
            }
146
        }
147
        catch (Exception e) {
148
            throw new BadPdfFormatException(e.getMessage());
149
        }
150 1 1. : removed call to com/lowagie/text/pdf/PdfContents::put → NO_COVERAGE
        put(PdfName.LENGTH, new PdfNumber(streamBytes.size()));
151 1 1. : negated conditional → NO_COVERAGE
        if (compressed)
152 1 1. : removed call to com/lowagie/text/pdf/PdfContents::put → NO_COVERAGE
            put(PdfName.FILTER, PdfName.FLATEDECODE);
153
    }
154
}

Mutations

91

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

103

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

104

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

105

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

106

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

107

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

110

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

111

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

112

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

113

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

114

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

117

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

118

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

119

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

120

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

121

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

124

1.1
Location :
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location :
Killed by : none
negated conditional → NO_COVERAGE

125

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

126

1.1
Location :
Killed by : none
removed call to com/lowagie/text/pdf/ByteBuffer::writeTo → NO_COVERAGE

127

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

129

1.1
Location :
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location :
Killed by : none
negated conditional → NO_COVERAGE

130

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

131

1.1
Location :
Killed by : none
removed call to com/lowagie/text/pdf/ByteBuffer::writeTo → NO_COVERAGE

132

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

134

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

135

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

136

1.1
Location :
Killed by : none
removed call to com/lowagie/text/pdf/ByteBuffer::writeTo → NO_COVERAGE

137

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::write → NO_COVERAGE

139

1.1
Location :
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location :
Killed by : none
negated conditional → NO_COVERAGE

140

1.1
Location :
Killed by : none
removed call to com/lowagie/text/pdf/ByteBuffer::writeTo → NO_COVERAGE

142

1.1
Location :
Killed by : none
removed call to java/io/OutputStream::close → NO_COVERAGE

143

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

144

1.1
Location :
Killed by : none
removed call to java/util/zip/Deflater::end → NO_COVERAGE

150

1.1
Location :
Killed by : none
removed call to com/lowagie/text/pdf/PdfContents::put → NO_COVERAGE

151

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

152

1.1
Location :
Killed by : none
removed call to com/lowagie/text/pdf/PdfContents::put → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2