* @param arguments List
* @throws IOException If there is an error invoking the sub object.
*/
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
{
PageDrawer drawer = (PageDrawer)context;
PDPage page = drawer.getPage();
COSName objectName = (COSName)arguments.get( 0 );
Map xobjects = drawer.getResources().getXObjects();
PDXObject xobject = (PDXObject)xobjects.get( objectName.getName() );
if( xobject instanceof PDXObjectImage )
{
PDXObjectImage image = (PDXObjectImage)xobject;
try
{
image.setGraphicsState(drawer.getGraphicsState());
BufferedImage awtImage = image.getRGBImage();
if (awtImage == null)
{
log.warn("getRGBImage returned NULL");
return;//TODO PKOCH
}
int imageWidth = awtImage.getWidth();
int imageHeight = awtImage.getHeight();
double pageHeight = drawer.getPageSize().getHeight();
log.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
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 );
}
catch( Exception e )
{
e.printStackTrace();
log.error(e, e);