final IRtfTextrunContainer c
= (IRtfTextrunContainer)builderContext.getContainer(
IRtfTextrunContainer.class, true, this);
final RtfExternalGraphic newGraphic = c.getTextrun().newImage();
//set URL
String url = eg.getURL();
newGraphic.setURL(url);
//set image data
ImageFactory fact = ImageFactory.getInstance();
FopImage fopimage = fact.getImage(url, eg.getUserAgent());
fopimage.load(FopImage.ORIGINAL_DATA);
newGraphic.setImageData(fopimage.getRessourceBytes());
//set scaling
if (eg.getScaling() == Constants.EN_UNIFORM) {
newGraphic.setScaling ("uniform");
}
//get width
int width = 0;
if (eg.getWidth().getEnum() == Constants.EN_AUTO) {
width = fopimage.getIntrinsicWidth();
} else {
width = eg.getWidth().getValue();
}
//get height
int height = 0;
if (eg.getWidth().getEnum() == Constants.EN_AUTO) {
height = fopimage.getIntrinsicHeight();
} else {
height = eg.getHeight().getValue();
}
//get content-width
int contentwidth = 0;
if (eg.getContentWidth().getEnum()
== Constants.EN_AUTO) {
contentwidth = fopimage.getIntrinsicWidth();
} else if (eg.getContentWidth().getEnum()
== Constants.EN_SCALE_TO_FIT) {
contentwidth = width;
} else {
//TODO: check, if the value is a percent value
contentwidth = eg.getContentWidth().getValue();
}
//get content-width
int contentheight = 0;
if (eg.getContentHeight().getEnum()
== Constants.EN_AUTO) {
contentheight = fopimage.getIntrinsicHeight();
} else if (eg.getContentHeight().getEnum()
== Constants.EN_SCALE_TO_FIT) {
contentheight = height;
} else {
//TODO: check, if the value is a percent value
contentheight = eg.getContentHeight().getValue();
}
//set width in rtf
newGraphic.setWidth((long) (contentwidth / 1000f) + "pt");
//set height in rtf
newGraphic.setHeight((long) (contentheight / 1000f) + "pt");
//TODO: make this configurable:
// int compression = m_context.m_options.getRtfExternalGraphicCompressionRate ();
int compression = 0;
if (compression != 0) {
if (!newGraphic.setCompressionRate(compression)) {
log.warn("The compression rate " + compression
+ " is invalid. The value has to be between 1 and 100 %.");
}
}
} catch (Exception e) {