* @param arguments List
* @throws IOException If there is an error displaying the inline image.
*/
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
{
PageDrawer drawer = (PageDrawer)context;
PDPage page = drawer.getPage();
//begin inline image object
ImageParameters params = operator.getImageParameters();
PDInlinedImage image = new PDInlinedImage();
image.setImageParameters( params );
image.setImageData( operator.getImageData() );
BufferedImage awtImage = image.createImage( context.getColorSpaces() );
if (awtImage == null)
{
log.warn("BeginInlineImage.process(): createImage returned NULL");
return;
}
int imageWidth = awtImage.getWidth();
int imageHeight = awtImage.getHeight();
double pageHeight = drawer.getPageSize().getHeight();
Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
int pageRotation = page.findRotation();
AffineTransform ctmAT = ctm.createAffineTransform();
ctmAT.scale(1f/imageWidth, 1f/imageHeight);
Matrix rotationMatrix = new Matrix();
rotationMatrix.setFromAffineTransform( ctmAT );
// calculate the inverse rotation angle
// scaleX = m00 = cos
// shearX = m01 = -sin
// tan = sin/cos
double angle = Math.atan(ctmAT.getShearX()/ctmAT.getScaleX());
Matrix translationMatrix = null;
if (pageRotation == 0 || pageRotation == 180)
{
translationMatrix = Matrix.getTranslatingInstance((float)(Math.sin(angle)*ctm.getXScale()), (float)(pageHeight-2*ctm.getYPosition()-Math.cos(angle)*ctm.getYScale()));
}
else if (pageRotation == 90 || pageRotation == 270)
{
translationMatrix = Matrix.getTranslatingInstance((float)(Math.sin(angle)*ctm.getYScale()), (float)(pageHeight-2*ctm.getYPosition()));
}
rotationMatrix = rotationMatrix.multiply(translationMatrix);
rotationMatrix.setValue(0, 1, (-1)*rotationMatrix.getValue(0, 1));
rotationMatrix.setValue(1, 0, (-1)*rotationMatrix.getValue(1, 0));
AffineTransform at = new AffineTransform(
rotationMatrix.getValue(0,0),rotationMatrix.getValue(0,1),
rotationMatrix.getValue(1,0), rotationMatrix.getValue( 1, 1),
rotationMatrix.getValue(2,0),rotationMatrix.getValue(2,1)
);
drawer.drawImage(awtImage, at);
}