001: /*
002: Copyright © 2006,2007 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.contents.xObjects;
028:
029: import it.stefanochizzolini.clown.documents.Document;
030: import it.stefanochizzolini.clown.objects.PdfDirectObject;
031: import it.stefanochizzolini.clown.objects.PdfName;
032: import it.stefanochizzolini.clown.objects.PdfObjectWrapper;
033: import it.stefanochizzolini.clown.objects.PdfReference;
034: import it.stefanochizzolini.clown.objects.PdfStream;
035:
036: import java.awt.geom.Dimension2D;
037:
038: /**
039: Abstract external object [PDF:1.6:4.7].
040: @version 0.0.5
041: */
042: public abstract class XObject extends PdfObjectWrapper<PdfStream> {
043: // <class>
044: // <static>
045: // <interface>
046: // <public>
047: /**
048: Wraps an external object reference into an external object.
049: @param reference Reference to an external object.
050: @return External object associated to the reference.
051: */
052: public static XObject wrap(PdfReference reference) {
053: /*
054: NOTE: This is a factory method for any xobject-derived object.
055: */
056: if (reference == null)
057: return null;
058:
059: PdfName subtype = (PdfName) ((PdfStream) reference
060: .getDataObject()).getHeader().get(PdfName.Subtype);
061: if (subtype.equals(PdfName.Form))
062: return new FormXObject(reference);
063: else if (subtype.equals(PdfName.Image))
064: return new ImageXObject(reference);
065: else
066: return null;
067: }
068:
069: // </public>
070: // </interface>
071: // </static>
072:
073: // <dynamic>
074: // <constructors>
075: /**
076: Creates a new external object inside the document.
077: */
078: protected XObject(Document context) {
079: this (context, new PdfStream());
080: }
081:
082: /**
083: Creates a new external object inside the document.
084: */
085: protected XObject(Document context, PdfStream baseDataObject) {
086: super (context.getFile(), baseDataObject);
087:
088: baseDataObject.getHeader().put(PdfName.Type, PdfName.XObject);
089: }
090:
091: /**
092: Instantiates an existing external object.
093: */
094: protected XObject(PdfDirectObject baseObject) {
095: super (baseObject, null // NO container (baseObject is (by definition) a PDF stream, so it MUST be an indirect object [PDF:1.6:3.2.7]).
096: );
097: }
098:
099: // </constructors>
100:
101: // <interface>
102: // <public>
103: /**
104: Gets the mapping from external-object space to user space.
105: @version 0.0.5
106: @since 0.0.5
107: */
108: public abstract double[] getMatrix();
109:
110: /**
111: Gets the external object size.
112: @version 0.0.5
113: @since 0.0.5
114: */
115: public abstract Dimension2D getSize();
116:
117: /**
118: Sets the external object size.
119: @version 0.0.5
120: @since 0.0.5
121: */
122: public abstract void setSize(Dimension2D value);
123: // </public>
124: // </interface>
125: // </dynamic>
126: // </class>
127: }
|