001: /**
002: * Copyright (c) 2003-2006, 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.annotation;
031:
032: import org.pdfbox.cos.COSArray;
033: import org.pdfbox.cos.COSBase;
034: import org.pdfbox.cos.COSDictionary;
035: import org.pdfbox.cos.COSName;
036: import org.pdfbox.cos.COSStream;
037:
038: import org.pdfbox.pdmodel.common.PDRectangle;
039: import org.pdfbox.pdmodel.common.COSObjectable;
040:
041: import org.pdfbox.pdmodel.PDResources;
042:
043: /**
044: * This class represents an appearance for an annotation.
045: *
046: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
047: * @version $Revision: 1.4 $
048: */
049: public class PDAppearanceStream implements COSObjectable {
050: private COSStream stream = null;
051:
052: /**
053: * Constructor.
054: *
055: * @param s The cos stream for this appearance.
056: */
057: public PDAppearanceStream(COSStream s) {
058: stream = s;
059: }
060:
061: /**
062: * This will return the underlying stream.
063: *
064: * @return The wrapped stream.
065: */
066: public COSStream getStream() {
067: return stream;
068: }
069:
070: /**
071: * {@inheritDoc}
072: */
073: public COSBase getCOSObject() {
074: return stream;
075: }
076:
077: /**
078: * Get the bounding box for this appearance. This may return null in which
079: * case the Rectangle from the annotation should be used.
080: *
081: * @return The bounding box for this appearance.
082: */
083: public PDRectangle getBoundingBox() {
084: PDRectangle box = null;
085: COSArray bbox = (COSArray) stream.getDictionaryObject(COSName
086: .getPDFName("BBox"));
087: if (bbox != null) {
088: box = new PDRectangle(bbox);
089: }
090: return box;
091: }
092:
093: /**
094: * This will set the bounding box for this appearance stream.
095: *
096: * @param rectangle The new bounding box.
097: */
098: public void setBoundingBox(PDRectangle rectangle) {
099: COSArray array = null;
100: if (rectangle != null) {
101: array = rectangle.getCOSArray();
102: }
103: stream.setItem(COSName.getPDFName("BBox"), array);
104: }
105:
106: /**
107: * This will get the resources for this appearance stream.
108: *
109: * @return The appearance stream resources.
110: */
111: public PDResources getResources() {
112: PDResources retval = null;
113: COSDictionary dict = (COSDictionary) stream
114: .getDictionaryObject(COSName.RESOURCES);
115: if (dict != null) {
116: retval = new PDResources(dict);
117: }
118: return retval;
119: }
120:
121: /**
122: * This will set the new resources.
123: *
124: * @param resources The new resources.
125: */
126: public void setResources(PDResources resources) {
127: COSDictionary dict = null;
128: if (resources != null) {
129: dict = resources.getCOSDictionary();
130: }
131: stream.setItem(COSName.RESOURCES, dict);
132: }
133: }
|