PdfDestination.java

1
/*
2
 * $Id: PdfDestination.java 4094 2009-11-12 14:29:35Z blowagie $
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.util.StringTokenizer;
53
54
/**
55
 * A <CODE>PdfColor</CODE> defines a Color (it's a <CODE>PdfArray</CODE> containing 3 values).
56
 *
57
 * @see        PdfDictionary
58
 */
59
60
public class PdfDestination extends PdfArray {
61
    
62
    // public static final member-variables
63
    
64
/** This is a possible destination type */
65
    public static final int XYZ = 0;
66
    
67
/** This is a possible destination type */
68
    public static final int FIT = 1;
69
    
70
/** This is a possible destination type */
71
    public static final int FITH = 2;
72
    
73
/** This is a possible destination type */
74
    public static final int FITV = 3;
75
    
76
/** This is a possible destination type */
77
    public static final int FITR = 4;
78
    
79
/** This is a possible destination type */
80
    public static final int FITB = 5;
81
    
82
/** This is a possible destination type */
83
    public static final int FITBH = 6;
84
    
85
/** This is a possible destination type */
86
    public static final int FITBV = 7;
87
    
88
    // member variables
89
    
90
/** Is the indirect reference to a page already added? */
91
    private boolean status = false;
92
    
93
    // constructors
94
    
95
/**
96
 * Constructs a new <CODE>PdfDestination</CODE>.
97
 * <P>
98
 * If <VAR>type</VAR> equals <VAR>FITB</VAR>, the bounding box of a page
99
 * will fit the window of the Reader. Otherwise the type will be set to
100
 * <VAR>FIT</VAR> so that the entire page will fit to the window.
101
 *
102
 * @param        type        The destination type
103
 */
104
    
105
    public PdfDestination(int type) {
106
        super();
107 1 1. : negated conditional → NO_COVERAGE
        if (type == FITB) {
108
            add(PdfName.FITB);
109
        }
110
        else {
111
            add(PdfName.FIT);
112
        }
113
    }
114
    
115
/**
116
 * Constructs a new <CODE>PdfDestination</CODE>.
117
 * <P>
118
 * If <VAR>type</VAR> equals <VAR>FITBH</VAR> / <VAR>FITBV</VAR>,
119
 * the width / height of the bounding box of a page will fit the window
120
 * of the Reader. The parameter will specify the y / x coordinate of the
121
 * top / left edge of the window. If the <VAR>type</VAR> equals <VAR>FITH</VAR>
122
 * or <VAR>FITV</VAR> the width / height of the entire page will fit
123
 * the window and the parameter will specify the y / x coordinate of the
124
 * top / left edge. In all other cases the type will be set to <VAR>FITH</VAR>.
125
 *
126
 * @param        type        the destination type
127
 * @param        parameter    a parameter to combined with the destination type
128
 */
129
    
130
    public PdfDestination(int type, float parameter) {
131
        super(new PdfNumber(parameter));
132
        switch(type) {
133
            default:
134 1 1. : removed call to com/lowagie/text/pdf/PdfDestination::addFirst → NO_COVERAGE
                addFirst(PdfName.FITH);
135
                break;
136
            case FITV:
137 1 1. : removed call to com/lowagie/text/pdf/PdfDestination::addFirst → NO_COVERAGE
                addFirst(PdfName.FITV);
138
                break;
139
            case FITBH:
140 1 1. : removed call to com/lowagie/text/pdf/PdfDestination::addFirst → NO_COVERAGE
                addFirst(PdfName.FITBH);
141
                break;
142
            case FITBV:
143 1 1. : removed call to com/lowagie/text/pdf/PdfDestination::addFirst → NO_COVERAGE
                addFirst(PdfName.FITBV);
144
        }
145
    }
146
    
147
/** Constructs a new <CODE>PdfDestination</CODE>.
148
 * <P>
149
 * Display the page, with the coordinates (left, top) positioned
150
 * at the top-left corner of the window and the contents of the page magnified
151
 * by the factor zoom. A negative value for any of the parameters left or top, or a
152
 * zoom value of 0 specifies that the current value of that parameter is to be retained unchanged.
153
 * @param type must be a <VAR>PdfDestination.XYZ</VAR>
154
 * @param left the left value. Negative to place a null
155
 * @param top the top value. Negative to place a null
156
 * @param zoom The zoom factor. A value of 0 keeps the current value
157
 */
158
    
159
    public PdfDestination(int type, float left, float top, float zoom) {
160
        super(PdfName.XYZ);
161 2 1. : changed conditional boundary → NO_COVERAGE
2. : negated conditional → NO_COVERAGE
        if (left < 0)
162
            add(PdfNull.PDFNULL);
163
        else
164
            add(new PdfNumber(left));
165 2 1. : changed conditional boundary → NO_COVERAGE
2. : negated conditional → NO_COVERAGE
        if (top < 0)
166
            add(PdfNull.PDFNULL);
167
        else
168
            add(new PdfNumber(top));
169
        add(new PdfNumber(zoom));
170
    }
171
    
172
/** Constructs a new <CODE>PdfDestination</CODE>.
173
 * <P>
174
 * Display the page, with its contents magnified just enough
175
 * to fit the rectangle specified by the coordinates left, bottom, right, and top
176
 * entirely within the window both horizontally and vertically. If the required
177
 * horizontal and vertical magnification factors are different, use the smaller of
178
 * the two, centering the rectangle within the window in the other dimension.
179
 *
180
 * @param type must be PdfDestination.FITR
181
 * @param left a parameter
182
 * @param bottom a parameter
183
 * @param right a parameter
184
 * @param top a parameter
185
 * @since iText0.38
186
 */
187
    
188
    public PdfDestination(int type, float left, float bottom, float right, float top) {
189
        super(PdfName.FITR);
190
        add(new PdfNumber(left));
191
        add(new PdfNumber(bottom));
192
        add(new PdfNumber(right));
193
        add(new PdfNumber(top));
194
    }
195
    
196
    /**
197
     * Creates a PdfDestination based on a String.
198
     * Valid Strings are for instance the values returned by SimpleNamedDestination:
199
     * "Fit", "XYZ 36 806 0",...
200
     * @param    dest    a String notation of a destination.
201
     * @since    iText 5.0
202
     */
203
    public PdfDestination(String dest) {
204
        super();
205
        StringTokenizer tokens = new StringTokenizer(dest);
206 1 1. : negated conditional → NO_COVERAGE
        if (tokens.hasMoreTokens()) {
207
            add(new PdfName(tokens.nextToken()));
208
        }
209 1 1. : negated conditional → NO_COVERAGE
        while (tokens.hasMoreTokens()) {
210
            add(new PdfNumber(tokens.nextToken()));
211
        }
212
    }
213
    
214
    // methods
215
216
/**
217
 * Checks if an indirect reference to a page has been added.
218
 *
219
 * @return    <CODE>true</CODE> or <CODE>false</CODE>
220
 */
221
    
222
    public boolean hasPage() {
223
        return status;
224
    }
225
    
226
/** Adds the indirect reference of the destination page.
227
 *
228
 * @param page    an indirect reference
229
 * @return true if the page reference was added
230
 */
231
    
232
    public boolean addPage(PdfIndirectReference page) {
233 1 1. addPage : negated conditional → NO_COVERAGE
        if (!status) {
234 1 1. addPage : removed call to com/lowagie/text/pdf/PdfDestination::addFirst → NO_COVERAGE
            addFirst(page);
235
            status = true;
236 1 1. addPage : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return true;
237
        }
238 1 1. addPage : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return false;
239
    }
240
}

Mutations

107

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

134

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

137

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

140

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

143

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

161

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

2.2
Location :
Killed by : none
negated conditional → NO_COVERAGE

165

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

2.2
Location :
Killed by : none
negated conditional → NO_COVERAGE

206

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

209

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

233

1.1
Location : addPage
Killed by : none
negated conditional → NO_COVERAGE

234

1.1
Location : addPage
Killed by : none
removed call to com/lowagie/text/pdf/PdfDestination::addFirst → NO_COVERAGE

236

1.1
Location : addPage
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

238

1.1
Location : addPage
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2