afpContext.getResourceManager(),
resourceInfo,
afpContext.getFontInfo());
g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
AFPPaintingState paintingState = g2d.getPaintingState();
paintingState.setImageUri(image.getInfo().getOriginalURI());
// Create an AFPBridgeContext
BridgeContext bridgeContext = AFPSVGHandler.createBridgeContext(userAgent, g2d);
// Cloning SVG DOM as Batik attaches non-thread-safe facilities (like the CSS engine)
// to it.
Document clonedDoc = BatikUtil.cloneSVGDocument(imageSVG.getDocument());
// Build the SVG DOM and provide the painter with it
GraphicsNode root;
try {
GVTBuilder builder = new GVTBuilder();
root = builder.build(bridgeContext, clonedDoc);
} catch (Exception e) {
SVGEventProducer eventProducer = SVGEventProducer.Provider.get(
context.getUserAgent().getEventBroadcaster());
eventProducer.svgNotBuilt(this, e, image.getInfo().getOriginalURI());
return;
}
// Image positioning
AFPObjectAreaInfo objectAreaInfo = AFPImageHandler.createObjectAreaInfo(paintingState, pos);
graphicsObjectInfo.setObjectAreaInfo(objectAreaInfo);
paintingState.save(); // save
AffineTransform placement = new AffineTransform();
placement.translate(pos.x, pos.y);
paintingState.concatenate(placement);
//Set up painter and target
graphicsObjectInfo.setGraphics2D(g2d);
// Create Graphics2DImagePainter
Dimension imageSize = image.getSize().getDimensionMpt();
Graphics2DImagePainter painter = new Graphics2DImagePainterImpl(
root, bridgeContext, imageSize);
graphicsObjectInfo.setPainter(painter);
// Create the GOCA GraphicsObject in the DataStream
AFPResourceManager resourceManager = afpContext.getResourceManager();
resourceManager.createObject(graphicsObjectInfo);
paintingState.restore(); // resume
}