1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination; 18 19 import org.apache.pdfbox.cos.COSArray; 20 import org.apache.pdfbox.cos.COSBase; 21 22 /** 23 * This represents a destination to a page at a y location and the width is magnified 24 * to just fit on the screen. 25 * 26 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 27 * @version $Revision: 1.2 $ 28 */ 29 public class PDPageFitWidthDestination extends PDPageDestination 30 { 31 32 /** 33 * The type of this destination. 34 */ 35 protected static final String TYPE = "FitH"; 36 /** 37 * The type of this destination. 38 */ 39 protected static final String TYPE_BOUNDED = "FitBH"; 40 41 /** 42 * Default constructor. 43 * 44 */ 45 public PDPageFitWidthDestination() 46 { 47 super(); 48 array.growToSize(3); 49 array.setName( 1, TYPE ); 50 51 } 52 53 /** 54 * Constructor from an existing destination array. 55 * 56 * @param arr The destination array. 57 */ 58 public PDPageFitWidthDestination( COSArray arr ) 59 { 60 super( arr ); 61 } 62 63 64 /** 65 * Get the top y coordinate. A return value of -1 implies that the current y-coordinate 66 * will be used. 67 * 68 * @return The top y coordinate. 69 */ 70 public int getTop() 71 { 72 return array.getInt( 2 ); 73 } 74 75 /** 76 * Set the top y-coordinate, a value of -1 implies that the current y-coordinate 77 * will be used. 78 * @param y The top ycoordinate. 79 */ 80 public void setTop( int y ) 81 { 82 array.growToSize( 3 ); 83 if( y == -1 ) 84 { 85 array.set( 2, (COSBase)null ); 86 } 87 else 88 { 89 array.setInt( 2, y ); 90 } 91 } 92 93 /** 94 * A flag indicating if this page destination should just fit bounding box of the PDF. 95 * 96 * @return true If the destination should fit just the bounding box. 97 */ 98 public boolean fitBoundingBox() 99 { 100 return TYPE_BOUNDED.equals( array.getName( 1 ) ); 101 } 102 103 /** 104 * Set if this page destination should just fit the bounding box. The default is false. 105 * 106 * @param fitBoundingBox A flag indicating if this should fit the bounding box. 107 */ 108 public void setFitBoundingBox( boolean fitBoundingBox ) 109 { 110 array.growToSize( 2 ); 111 if( fitBoundingBox ) 112 { 113 array.setName( 1, TYPE_BOUNDED ); 114 } 115 else 116 { 117 array.setName( 1, TYPE ); 118 } 119 } 120 }