int width = Math.round(unitConv.mpt2units(posInt.width));
int height = Math.round(unitConv.mpt2units(posInt.height));
dataStream.createIncludePageSegment(name, coords[X], coords[Y], width, height);
} else {
ImageManager manager = userAgent.getFactory().getImageManager();
ImageInfo info = null;
try {
ImageSessionContext sessionContext = userAgent
.getImageSessionContext();
info = manager.getImageInfo(uri, sessionContext);
// Only now fully load/prepare the image
Map hints = ImageUtil.getDefaultHints(sessionContext);
boolean nativeImagesSupported = paintingState.isNativeImagesSupported();
ImageFlavor[] flavors = nativeImagesSupported ? NATIVE_FLAVORS : FLAVORS;
// Load image
org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
info, flavors, hints, sessionContext);
// Handle image
AFPImageHandler imageHandler
= (AFPImageHandler)imageHandlerRegistry.getHandler(img);
if (imageHandler != null) {
RendererContext rendererContext = createRendererContext(
x, y, posInt.width, posInt.height, foreignAttributes);
AFPRendererImageInfo rendererImageInfo = new AFPRendererImageInfo(
uri, pos, origin, info, img, rendererContext, foreignAttributes);
AFPDataObjectInfo dataObjectInfo = null;
try {
dataObjectInfo = imageHandler.generateDataObjectInfo(rendererImageInfo);
// Create image
if (dataObjectInfo != null) {
resourceManager.createObject(dataObjectInfo);
}
} catch (IOException ioe) {
ResourceEventProducer eventProducer
= ResourceEventProducer.Provider.get(userAgent.getEventBroadcaster());
eventProducer.imageWritingError(this, ioe);
throw ioe;
}
} else {
throw new UnsupportedOperationException(
"No AFPImageHandler available for image: "
+ info + " (" + img.getClass().getName() + ")");
}
} catch (ImageException ie) {
ResourceEventProducer eventProducer = ResourceEventProducer.Provider
.get(userAgent.getEventBroadcaster());
eventProducer.imageError(this, (info != null ? info.toString()
: uri), ie, null);
} catch (FileNotFoundException fe) {
ResourceEventProducer eventProducer = ResourceEventProducer.Provider
.get(userAgent.getEventBroadcaster());
eventProducer.imageNotFound(this, (info != null ? info.toString()
: uri), fe, null);
} catch (IOException ioe) {
ResourceEventProducer eventProducer = ResourceEventProducer.Provider
.get(userAgent.getEventBroadcaster());
eventProducer.imageIOError(this, (info != null ? info.toString()
: uri), ioe, null);
}
}
}