/** {@inheritDoc} */
public void handleImage(RenderingContext context, Image image, Rectangle pos)
throws IOException {
PDFRenderingContext pdfContext = (PDFRenderingContext)context;
PDFContentGenerator generator = pdfContext.getGenerator();
ImageGraphics2D imageG2D = (ImageGraphics2D)image;
float fwidth = pos.width / 1000f;
float fheight = pos.height / 1000f;
float fx = pos.x / 1000f;
float fy = pos.y / 1000f;
// get the 'width' and 'height' attributes of the SVG document
Dimension dim = image.getInfo().getSize().getDimensionMpt();
float imw = (float)dim.getWidth() / 1000f;
float imh = (float)dim.getHeight() / 1000f;
float sx = fwidth / (float)imw;
float sy = fheight / (float)imh;
generator.comment("G2D start");
boolean accessibilityEnabled = context.getUserAgent().isAccessibilityEnabled();
if (accessibilityEnabled) {
MarkedContentInfo mci = pdfContext.getMarkedContentInfo();
generator.saveGraphicsState(mci.tag, mci.mcid);
} else {
generator.saveGraphicsState();
}
generator.updateColor(Color.black, false, null);
generator.updateColor(Color.black, true, null);
//TODO Clip to the image area.
// transform so that the coordinates (0,0) is from the top left
// and positive is down and to the right. (0,0) is where the
// viewBox puts it.
generator.add(sx + " 0 0 " + sy + " " + fx + " " + fy + " cm\n");
final boolean textAsShapes = false;
PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes,
pdfContext.getFontInfo(), generator.getDocument(),
generator.getResourceContext(), pdfContext.getPage().referencePDF(),
"", 0.0f);
graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
AffineTransform transform = new AffineTransform();
transform.translate(fx, fy);
generator.getState().concatenate(transform);
graphics.setPaintingState(generator.getState());
graphics.setOutputStream(generator.getOutputStream());
Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
imageG2D.getGraphics2DImagePainter().paint(graphics, area);
generator.add(graphics.getString());
if (accessibilityEnabled) {
generator.restoreGraphicsStateAccess();
} else {