Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.interactive.annotation » [javadoc | source]

    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.annotation;
   18   
   19   import org.apache.pdfbox.cos.COSArray;
   20   import org.apache.pdfbox.cos.COSBase;
   21   import org.apache.pdfbox.cos.COSDictionary;
   22   import org.apache.pdfbox.cos.COSName;
   23   import org.apache.pdfbox.cos.COSStream;
   24   
   25   import org.apache.pdfbox.pdmodel.common.PDRectangle;
   26   import org.apache.pdfbox.pdmodel.common.COSObjectable;
   27   
   28   import org.apache.pdfbox.pdmodel.PDResources;
   29   
   30   
   31   /**
   32    * This class represents an appearance for an annotation.
   33    *
   34    * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
   35    * @version $Revision: 1.4 $
   36    */
   37   public class PDAppearanceStream implements COSObjectable
   38   {
   39       private COSStream stream = null;
   40   
   41   
   42       /**
   43        * Constructor.
   44        *
   45        * @param s The cos stream for this appearance.
   46        */
   47       public PDAppearanceStream( COSStream s )
   48       {
   49           stream = s;
   50       }
   51   
   52       /**
   53        * This will return the underlying stream.
   54        *
   55        * @return The wrapped stream.
   56        */
   57       public COSStream getStream()
   58       {
   59           return stream;
   60       }
   61   
   62       /**
   63        * {@inheritDoc}
   64        */
   65       public COSBase getCOSObject()
   66       {
   67           return stream;
   68       }
   69   
   70       /**
   71        * Get the bounding box for this appearance.  This may return null in which
   72        * case the Rectangle from the annotation should be used.
   73        *
   74        * @return The bounding box for this appearance.
   75        */
   76       public PDRectangle getBoundingBox()
   77       {
   78           PDRectangle box = null;
   79           COSArray bbox = (COSArray)stream.getDictionaryObject( COSName.getPDFName( "BBox" ) );
   80           if( bbox != null )
   81           {
   82               box = new PDRectangle( bbox );
   83           }
   84           return box;
   85       }
   86   
   87       /**
   88        * This will set the bounding box for this appearance stream.
   89        *
   90        * @param rectangle The new bounding box.
   91        */
   92       public void setBoundingBox( PDRectangle rectangle )
   93       {
   94           COSArray array = null;
   95           if( rectangle != null )
   96           {
   97               array = rectangle.getCOSArray();
   98           }
   99           stream.setItem( COSName.getPDFName( "BBox" ), array );
  100       }
  101   
  102       /**
  103        * This will get the resources for this appearance stream.
  104        *
  105        * @return The appearance stream resources.
  106        */
  107       public PDResources getResources()
  108       {
  109           PDResources retval = null;
  110           COSDictionary dict = (COSDictionary)stream.getDictionaryObject( COSName.RESOURCES );
  111           if( dict != null )
  112           {
  113               retval = new PDResources( dict );
  114           }
  115           return retval;
  116       }
  117   
  118       /**
  119        * This will set the new resources.
  120        *
  121        * @param resources The new resources.
  122        */
  123       public void setResources( PDResources resources )
  124       {
  125           COSDictionary dict = null;
  126           if( resources != null )
  127           {
  128               dict = resources.getCOSDictionary();
  129           }
  130           stream.setItem( COSName.RESOURCES, dict );
  131       }
  132   }

Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.interactive.annotation » [javadoc | source]