001: /**
002: * Copyright (c) 2005, 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.util.operator.pagedrawer;
031:
032: import java.awt.Graphics2D;
033: import java.awt.geom.AffineTransform;
034: import java.awt.image.BufferedImage;
035: import java.io.IOException;
036: import java.util.List;
037:
038: import org.pdfbox.pdfviewer.PageDrawer;
039: import org.pdfbox.pdmodel.graphics.xobject.PDInlinedImage;
040: import org.pdfbox.util.ImageParameters;
041: import org.pdfbox.util.Matrix;
042: import org.pdfbox.util.PDFOperator;
043: import org.pdfbox.util.operator.OperatorProcessor;
044:
045: /**
046: * Implementation of content stream operator for page drawer.
047: *
048: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
049: * @version $Revision: 1.2 $
050: */
051: public class BeginInlineImage extends OperatorProcessor {
052:
053: /**
054: * process : BI : begin inline image.
055: * @param operator The operator that is being executed.
056: * @param arguments List
057: * @throws IOException If there is an error displaying the inline image.
058: */
059: public void process(PDFOperator operator, List arguments)
060: throws IOException {
061: PageDrawer drawer = (PageDrawer) context;
062: Graphics2D graphics = drawer.getGraphics();
063: //begin inline image object
064: ImageParameters params = operator.getImageParameters();
065: PDInlinedImage image = new PDInlinedImage();
066: image.setImageParameters(params);
067: image.setImageData(operator.getImageData());
068: BufferedImage awtImage = image.createImage();
069:
070: Matrix ctm = drawer.getGraphicsState()
071: .getCurrentTransformationMatrix();
072:
073: int width = awtImage.getWidth();
074: int height = awtImage.getHeight();
075:
076: AffineTransform at = new AffineTransform(ctm.getValue(0, 0)
077: / width, ctm.getValue(0, 1), ctm.getValue(1, 0), ctm
078: .getValue(1, 1)
079: / height, ctm.getValue(2, 0), ctm.getValue(2, 1));
080: //at.setToRotation((double)page.getRotation());
081:
082: // The transformation should be done
083: // 1 - Translation
084: // 2 - Rotation
085: // 3 - Scale or Skew
086: //AffineTransform at = new AffineTransform();
087:
088: // Translation
089: //at = new AffineTransform();
090: //at.setToTranslation((double)ctm.getValue(0,0),
091: // (double)ctm.getValue(0,1));
092:
093: // Rotation
094: //AffineTransform toAdd = new AffineTransform();
095: //toAdd.setToRotation(1.5705);
096: //toAdd.setToRotation(ctm.getValue(2,0)*(Math.PI/180));
097: //at.concatenate(toAdd);
098:
099: // Scale / Skew?
100: //toAdd.setToScale(width, height);
101: //at.concatenate(toAdd);
102: //at.setToScale( width, height );
103: graphics.drawImage(awtImage, at, null);
104: //graphics.drawImage( awtImage,0,0, width,height,null);
105: }
106: }
|