* @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<String, PDXObject> xobjects = drawer.getResources().getXObjects();
PDXObject xobject = (PDXObject)xobjects.get( objectName.getName() );
if ( xobject == null )
{
LOG.warn("Can't find the XObject for '"+objectName.getName()+"'");
}
else if( xobject instanceof PDXObjectImage )
{
PDXObjectImage image = (PDXObjectImage)xobject;
try
{
if (image.getImageMask())
{
// set the current non stroking colorstate, so that it can
// be used to create a stencil masked image
image.setStencilColor(drawer.getGraphicsState().getNonStrokingColor());
}
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();
float yScaling = ctm.getYScale();
float angle = (float)Math.acos(ctm.getValue(0, 0)/ctm.getXScale());
if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0)
{
angle = (-1)*angle;
}
ctm.setValue(2, 1, (float)(pageHeight - ctm.getYPosition() - Math.cos(angle)*yScaling));
ctm.setValue(2, 0, (float)(ctm.getXPosition() - Math.sin(angle)*yScaling));
// because of the moved 0,0-reference, we have to shear in the opposite direction
ctm.setValue(0, 1, (-1)*ctm.getValue(0, 1));
ctm.setValue(1, 0, (-1)*ctm.getValue(1, 0));
AffineTransform ctmAT = ctm.createAffineTransform();
ctmAT.scale(1f/imageWidth, 1f/imageHeight);
drawer.drawImage( awtImage, ctmAT );
}
catch( Exception e )
{
e.printStackTrace();
LOG.error(e, e);