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