001: /*
002: * $Id: PdfDestination.java 1733 2005-05-04 14:33:54Z blowagie $
003: * $Name$
004: *
005: * Copyright 1999, 2000, 2001, 2002 Bruno Lowagie
006: *
007: * The contents of this file are subject to the Mozilla Public License Version 1.1
008: * (the "License"); you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the License.
014: *
015: * The Original Code is 'iText, a free JAVA-PDF library'.
016: *
017: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
018: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
019: * All Rights Reserved.
020: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
021: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
022: *
023: * Contributor(s): all the names of the contributors are added in the source code
024: * where applicable.
025: *
026: * Alternatively, the contents of this file may be used under the terms of the
027: * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
028: * provisions of LGPL are applicable instead of those above. If you wish to
029: * allow use of your version of this file only under the terms of the LGPL
030: * License and not to allow others to use your version of this file under
031: * the MPL, indicate your decision by deleting the provisions above and
032: * replace them with the notice and other provisions required by the LGPL.
033: * If you do not delete the provisions above, a recipient may use your version
034: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
035: *
036: * This library is free software; you can redistribute it and/or modify it
037: * under the terms of the MPL as stated above or under the terms of the GNU
038: * Library General Public License as published by the Free Software Foundation;
039: * either version 2 of the License, or any later version.
040: *
041: * This library is distributed in the hope that it will be useful, but WITHOUT
042: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
043: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
044: * details.
045: *
046: * If you didn't download this code from the following link, you should check if
047: * you aren't using an obsolete version:
048: * http://www.lowagie.com/iText/
049: */
050:
051: package com.lowagie.text.pdf;
052:
053: /**
054: * A <CODE>PdfColor</CODE> defines a Color (it's a <CODE>PdfArray</CODE> containing 3 values).
055: *
056: * @see PdfDictionary
057: */
058:
059: public class PdfDestination extends PdfArray {
060:
061: // public static final member-variables
062:
063: /** This is a possible destination type */
064: public static final int XYZ = 0;
065:
066: /** This is a possible destination type */
067: public static final int FIT = 1;
068:
069: /** This is a possible destination type */
070: public static final int FITH = 2;
071:
072: /** This is a possible destination type */
073: public static final int FITV = 3;
074:
075: /** This is a possible destination type */
076: public static final int FITR = 4;
077:
078: /** This is a possible destination type */
079: public static final int FITB = 5;
080:
081: /** This is a possible destination type */
082: public static final int FITBH = 6;
083:
084: /** This is a possible destination type */
085: public static final int FITBV = 7;
086:
087: // member variables
088:
089: /** Is the indirect reference to a page already added? */
090: private boolean status = false;
091:
092: // constructors
093:
094: /**
095: * Constructs a new <CODE>PdfDestination</CODE>.
096: * <P>
097: * If <VAR>type</VAR> equals <VAR>FITB</VAR>, the bounding box of a page
098: * will fit the window of the Reader. Otherwise the type will be set to
099: * <VAR>FIT</VAR> so that the entire page will fit to the window.
100: *
101: * @param type The destination type
102: */
103:
104: public PdfDestination(int type) {
105: super ();
106: if (type == FITB) {
107: add(PdfName.FITB);
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,
187: float right, float top) {
188: super (PdfName.FITR);
189: add(new PdfNumber(left));
190: add(new PdfNumber(bottom));
191: add(new PdfNumber(right));
192: add(new PdfNumber(top));
193: }
194:
195: // methods
196:
197: /**
198: * Checks if an indirect reference to a page has been added.
199: *
200: * @return <CODE>true</CODE> or <CODE>false</CODE>
201: */
202:
203: public boolean hasPage() {
204: return status;
205: }
206:
207: /** Adds the indirect reference of the destination page.
208: *
209: * @param page an indirect reference
210: * @return true if the page reference was added
211: */
212:
213: public boolean addPage(PdfIndirectReference page) {
214: if (!status) {
215: addFirst(page);
216: status = true;
217: return true;
218: }
219: return false;
220: }
221: }
|