int x = currentIPPosition + (int)Math.round(pos.getX());
int y = currentBPPosition + (int)Math.round(pos.getY());
uri = URISpecification.getURL(uri);
ImageManager manager = getUserAgent().getFactory().getImageManager();
ImageInfo info = null;
try {
ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
info = manager.getImageInfo(uri, sessionContext);
final ImageFlavor[] flavors = new ImageFlavor[]
{ImageFlavor.GRAPHICS2D,
ImageFlavor.BUFFERED_IMAGE,
ImageFlavor.RENDERED_IMAGE,
ImageFlavor.XML_DOM};
Map hints = ImageUtil.getDefaultHints(sessionContext);
org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
info, flavors, hints, sessionContext);
if (img instanceof ImageGraphics2D) {
ImageGraphics2D imageG2D = (ImageGraphics2D)img;
int width = (int)pos.getWidth();
int height = (int)pos.getHeight();
RendererContext context = createRendererContext(
x, y, width, height, foreignAttributes);
getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(),
context, x, y, width, height);
} else if (img instanceof ImageRendered) {
ImageRendered imgRend = (ImageRendered)img;
AffineTransform at = new AffineTransform();
at.translate(x / 1000f, y / 1000f);
double sx = pos.getWidth() / info.getSize().getWidthMpt();
double sy = pos.getHeight() / info.getSize().getHeightMpt();
sx *= userAgent.getSourceResolution() / info.getSize().getDpiHorizontal();
sy *= userAgent.getSourceResolution() / info.getSize().getDpiVertical();
at.scale(sx, sy);
state.getGraph().drawRenderedImage(imgRend.getRenderedImage(), at);
} else if (img instanceof ImageXMLDOM) {
ImageXMLDOM imgXML = (ImageXMLDOM)img;
renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(),
pos, foreignAttributes);
}
} catch (ImageException ie) {
log.error("Error while processing image: "
+ (info != null ? info.toString() : uri), ie);
} catch (FileNotFoundException fnfe) {
log.error(fnfe.getMessage());
} catch (IOException ioe) {
log.error("I/O error while processing image: "
+ (info != null ? info.toString() : uri), ioe);
}
}