PDPage page = getCurrentPage();
int imageWidth = image.getWidth();
int imageHeight = image.getHeight();
double pageHeight = page.getMediaBox().getHeight();
Matrix ctmNew = getGraphicsState().getCurrentTransformationMatrix();
float yScaling = ctmNew.getYScale();
float angle = (float) Math.acos(ctmNew.getValue(0, 0) / ctmNew.getXScale());
if (ctmNew.getValue(0, 1) < 0 && ctmNew.getValue(1, 0) > 0) {
angle = (-1) * angle;
}
ctmNew.setValue(2, 1, (float) (pageHeight - ctmNew.getYPosition() - Math.cos(angle) * yScaling));
ctmNew.setValue(2, 0, (float) (ctmNew.getXPosition() - Math.sin(angle) * yScaling));
// because of the moved 0,0-reference, we have to shear in the opposite direction
ctmNew.setValue(0, 1, (-1) * ctmNew.getValue(0, 1));
ctmNew.setValue(1, 0, (-1) * ctmNew.getValue(1, 0));
AffineTransform ctmAT = ctmNew.createAffineTransform();
ctmAT.scale(1f / imageWidth, 1f / imageHeight);
Image entry = new Image();
entry.x = ctmNew.getXPosition();
entry.image = image;
entry.name = objectName.getName();
images.put(page, ctmNew.getYPosition(), entry);
} else if (xobject instanceof PDXObjectForm) {
// save the graphics state
getGraphicsStack().push((PDGraphicsState) getGraphicsState().clone());
PDPage page = getCurrentPage();
PDXObjectForm form = (PDXObjectForm) xobject;
COSStream invoke = (COSStream) form.getCOSObject();
PDResources pdResources = form.getResources();
if (pdResources == null) {
pdResources = page.findResources();
}
// if there is an optional form matrix, we have to
// map the form space to the user space
Matrix matrix = form.getMatrix();
if (matrix != null) {
Matrix xobjectCTM = matrix.multiply(getGraphicsState().getCurrentTransformationMatrix());
getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
}
processSubStream(page, pdResources, invoke);
// restore the graphics state