001: /*
002: Copyright © 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
003:
004: Contributors:
005: * Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it):
006: contributed code is Copyright © 2006 by Stefano Chizzolini.
007:
008: This file should be part of the source code distribution of "PDF Clown library"
009: (the Program): see the accompanying README files for more info.
010:
011: This Program is free software; you can redistribute it and/or modify it under
012: the terms of the GNU General Public License as published by the Free Software
013: Foundation; either version 2 of the License, or (at your option) any later version.
014:
015: This Program is distributed in the hope that it will be useful, but WITHOUT ANY
016: WARRANTY, either expressed or implied; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
018:
019: You should have received a copy of the GNU General Public License along with this
020: Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
021:
022: Redistribution and use, with or without modification, are permitted provided that such
023: redistributions retain the above copyright notice, license and disclaimer, along with
024: this list of conditions.
025: */
026:
027: package it.stefanochizzolini.clown.documents.interaction;
028:
029: import it.stefanochizzolini.clown.documents.Document;
030: import it.stefanochizzolini.clown.documents.Page;
031: import it.stefanochizzolini.clown.objects.PdfArray;
032: import it.stefanochizzolini.clown.objects.PdfDirectObject;
033: import it.stefanochizzolini.clown.objects.PdfIndirectObject;
034: import it.stefanochizzolini.clown.objects.PdfName;
035: import it.stefanochizzolini.clown.objects.PdfObjectWrapper;
036: import it.stefanochizzolini.clown.objects.PdfReal;
037: import it.stefanochizzolini.clown.util.NotImplementedException;
038:
039: /**
040: [PDF:1.6:8.2.1] Interaction target, that is a particular view of a document,
041: consisting of the following items:
042: <ul>
043: <li>the page of the document to be displayed;</li>
044: <li>the location of the document window on that page;</li>
045: <li>the magnification (zoom) factor to use when displaying the page.</li>
046: </ul>
047: */
048: public class Destination extends PdfObjectWrapper<PdfArray> {
049: // <class>
050: // <dynamic>
051: // <constructors>
052: public Destination(Page page, DestinationModeEnum mode,
053: double[] viewParams) {
054: super (page.getFile(), new PdfArray());
055:
056: PdfArray destinationObject = getBaseDataObject();
057:
058: destinationObject.add(page.getBaseObject());
059:
060: switch (mode) {
061: case Fit:
062: destinationObject.add(PdfName.Fit);
063: break;
064: case FitBoundingBox:
065: destinationObject.add(PdfName.FitB);
066: break;
067: case FitBoundingBoxHorizontal:
068: destinationObject.add(PdfName.FitBH);
069: destinationObject.add(new PdfReal(viewParams[0]));
070: break;
071: case FitBoundingBoxVertical:
072: destinationObject.add(PdfName.FitBV);
073: destinationObject.add(new PdfReal(viewParams[0]));
074: break;
075: case FitHorizontal:
076: destinationObject.add(PdfName.FitH);
077: destinationObject.add(new PdfReal(viewParams[0]));
078: break;
079: case FitRectangle:
080: destinationObject.add(PdfName.FitR);
081: destinationObject.add(new PdfReal(viewParams[0]));
082: destinationObject.add(new PdfReal(viewParams[1]));
083: destinationObject.add(new PdfReal(viewParams[2]));
084: destinationObject.add(new PdfReal(viewParams[3]));
085: break;
086: case FitVertical:
087: destinationObject.add(PdfName.FitV);
088: destinationObject.add(new PdfReal(viewParams[0]));
089: break;
090: case XYZ:
091: destinationObject.add(PdfName.XYZ);
092: destinationObject.add(new PdfReal(viewParams[0]));
093: destinationObject.add(new PdfReal(viewParams[1]));
094: destinationObject.add(new PdfReal(viewParams[2]));
095: break;
096: }
097: }
098:
099: /**
100: <h3>Remarks</h3>
101: <p>For internal use only.</p>
102: */
103: public Destination(PdfDirectObject baseObject,
104: PdfIndirectObject container) {
105: super (baseObject, container);
106: }
107:
108: // </constructors>
109:
110: // <interface>
111: // <public>
112: @Override
113: public Destination clone(Document context) {
114: throw new NotImplementedException();
115: }
116:
117: public DestinationModeEnum getDestinationMode() {
118: PdfName value = (PdfName) getBaseDataObject().get(1);
119:
120: if (value.equals(PdfName.FitB))
121: return DestinationModeEnum.FitBoundingBox;
122: else if (value.equals(PdfName.FitBH))
123: return DestinationModeEnum.FitBoundingBoxHorizontal;
124: else if (value.equals(PdfName.FitBV))
125: return DestinationModeEnum.FitBoundingBoxVertical;
126: else if (value.equals(PdfName.FitH))
127: return DestinationModeEnum.FitHorizontal;
128: else if (value.equals(PdfName.FitR))
129: return DestinationModeEnum.FitRectangle;
130: else if (value.equals(PdfName.FitV))
131: return DestinationModeEnum.FitVertical;
132: else if (value.equals(PdfName.XYZ))
133: return DestinationModeEnum.XYZ;
134: else
135: return DestinationModeEnum.Fit;
136: }
137:
138: public Page getPage() {
139: return new Page(getBaseDataObject().get(0));
140: }
141: // </public>
142: // </interface>
143: // </dynamic>
144: // </class>
145: }
|