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.PdfDictionary;
031: import it.stefanochizzolini.clown.objects.PdfDirectObject;
032: import it.stefanochizzolini.clown.objects.PdfInteger;
033: import it.stefanochizzolini.clown.objects.PdfName;
034: import it.stefanochizzolini.clown.objects.PdfStream;
035: import it.stefanochizzolini.clown.util.NotImplementedException;
036:
037: import java.awt.Dimension;
038: import java.awt.geom.Dimension2D;
039:
040: /**
041: Image external object [PDF:1.6:4.8.4].
042: @version 0.0.5
043: */
044: public class ImageXObject extends XObject {
045: // <class>
046: // <dynamic>
047: // <constructors>
048: public ImageXObject(Document context, PdfStream baseDataObject) {
049: /*
050: NOTE: It's caller responsability to adequately populate the stream
051: header and body in order to instantiate a valid object; header entries like
052: 'Width', 'Height', 'ColorSpace', 'BitsPerComponent' MUST be defined
053: appropriately.
054: */
055:
056: super (context, baseDataObject);
057:
058: baseDataObject.getHeader().put(PdfName.Subtype, PdfName.Image);
059: }
060:
061: /**
062: <h3>Remarks</h3>
063: <p>For internal use only.</p>
064: */
065: public ImageXObject(PdfDirectObject baseObject) {
066: super (baseObject);
067: }
068:
069: // </constructors>
070:
071: // <interface>
072: // <public>
073: /**
074: Gets the number of bits per color component.
075: */
076: public int getBitsPerComponent() {
077: return ((PdfInteger) getBaseDataObject().getHeader().get(
078: PdfName.BitsPerComponent)).getValue();
079: }
080:
081: @Override
082: public ImageXObject clone(Document context) {
083: throw new NotImplementedException();
084: }
085:
086: /**
087: Gets the color space in which samples are specified.
088: */
089: public String getColorSpace() {
090: return ((PdfName) getBaseDataObject().getHeader().get(
091: PdfName.ColorSpace)).getValue();
092: }
093:
094: /**
095: @version 0.0.5
096: @since 0.0.5
097: */
098: @Override
099: public double[] getMatrix() {
100: Dimension2D size = getSize();
101:
102: /*
103: NOTE: Image-space-to-user-space matrix is [1/w 0 0 1/h 0 0],
104: where w and h are the width and height of the image in samples [PDF:1.6:4.8.3].
105: */
106: return new double[] { 1 / size.getWidth(), // a.
107: 0, // b.
108: 0, // c.
109: 1 / size.getHeight(), // d.
110: 0, // e.
111: 0 // f.
112: };
113: }
114:
115: /**
116: Gets the size of the image (in samples).
117: @version 0.0.5
118: @since 0.0.5
119: */
120: @Override
121: public Dimension2D getSize() {
122: PdfDictionary header = getBaseDataObject().getHeader();
123:
124: return new Dimension(((PdfInteger) header.get(PdfName.Width))
125: .getValue(), ((PdfInteger) header.get(PdfName.Height))
126: .getValue());
127: }
128:
129: /**
130: @version 0.0.5
131: @since 0.0.5
132: */
133: @Override
134: public void setSize(Dimension2D value) {
135: throw new UnsupportedOperationException();
136: }
137: // </public>
138: // </interface>
139: // </dynamic>
140: // </class>
141: }
|