001: /**
002: * Copyright (c) 2005, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.interactive.documentnavigation.destination;
031:
032: import org.pdfbox.cos.COSArray;
033: import org.pdfbox.cos.COSBase;
034:
035: /**
036: * This represents a destination to a page at a y location and the width is magnified
037: * to just fit on the screen.
038: *
039: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
040: * @version $Revision: 1.2 $
041: */
042: public class PDPageFitWidthDestination extends PDPageDestination {
043:
044: /**
045: * The type of this destination.
046: */
047: protected static final String TYPE = "FitH";
048: /**
049: * The type of this destination.
050: */
051: protected static final String TYPE_BOUNDED = "FitBH";
052:
053: /**
054: * Default constructor.
055: *
056: */
057: public PDPageFitWidthDestination() {
058: super ();
059: array.growToSize(3);
060: array.setName(1, TYPE);
061:
062: }
063:
064: /**
065: * Constructor from an existing destination array.
066: *
067: * @param arr The destination array.
068: */
069: public PDPageFitWidthDestination(COSArray arr) {
070: super (arr);
071: }
072:
073: /**
074: * Get the top y coordinate. A return value of -1 implies that the current y-coordinate
075: * will be used.
076: *
077: * @return The top y coordinate.
078: */
079: public int getTop() {
080: return array.getInt(2);
081: }
082:
083: /**
084: * Set the top y-coordinate, a value of -1 implies that the current y-coordinate
085: * will be used.
086: * @param y The top ycoordinate.
087: */
088: public void setTop(int y) {
089: array.growToSize(3);
090: if (y == -1) {
091: array.set(2, (COSBase) null);
092: } else {
093: array.setInt(2, y);
094: }
095: }
096:
097: /**
098: * A flag indicating if this page destination should just fit bounding box of the PDF.
099: *
100: * @return true If the destination should fit just the bounding box.
101: */
102: public boolean fitBoundingBox() {
103: return TYPE_BOUNDED.equals(array.getName(1));
104: }
105:
106: /**
107: * Set if this page destination should just fit the bounding box. The default is false.
108: *
109: * @param fitBoundingBox A flag indicating if this should fit the bounding box.
110: */
111: public void setFitBoundingBox(boolean fitBoundingBox) {
112: array.growToSize(2);
113: if (fitBoundingBox) {
114: array.setName(1, TYPE_BOUNDED);
115: } else {
116: array.setName(1, TYPE);
117: }
118: }
119: }
|