final IRtfTextrunContainer c
= (IRtfTextrunContainer)builderContext.getContainer(
IRtfTextrunContainer.class, true, this);
final RtfExternalGraphic rtfGraphic = c.getTextrun().newImage();
//set URL
if (info.getOriginalURI() != null) {
rtfGraphic.setURL(info.getOriginalURI());
}
rtfGraphic.setImageData(rawData);
//set scaling
if (abstractGraphic.getScaling() == Constants.EN_UNIFORM) {
rtfGraphic.setScaling ("uniform");
}
//get width
int width = 0;
if (abstractGraphic.getWidth().getEnum() == Constants.EN_AUTO) {
width = info.getSize().getWidthMpt();
} else {
width = abstractGraphic.getWidth().getValue();
}
//get height
int height = 0;
if (abstractGraphic.getWidth().getEnum() == Constants.EN_AUTO) {
height = info.getSize().getHeightMpt();
} else {
height = abstractGraphic.getHeight().getValue();
}
//get content-width
int contentwidth = 0;
if (abstractGraphic.getContentWidth().getEnum()
== Constants.EN_AUTO) {
contentwidth = info.getSize().getWidthMpt();
} else if (abstractGraphic.getContentWidth().getEnum()
== Constants.EN_SCALE_TO_FIT) {
contentwidth = width;
} else {
//TODO: check, if the value is a percent value
contentwidth = abstractGraphic.getContentWidth().getValue();
}
//get content-width
int contentheight = 0;
if (abstractGraphic.getContentHeight().getEnum()
== Constants.EN_AUTO) {
contentheight = info.getSize().getHeightMpt();
} else if (abstractGraphic.getContentHeight().getEnum()
== Constants.EN_SCALE_TO_FIT) {
contentheight = height;
} else {
//TODO: check, if the value is a percent value
contentheight = abstractGraphic.getContentHeight().getValue();
}
//set width in rtf
//newGraphic.setWidth((long) (contentwidth / 1000f) + FixedLength.POINT);
rtfGraphic.setWidth((long) (contentwidth / 50f) + "twips");
//set height in rtf
//newGraphic.setHeight((long) (contentheight / 1000f) + FixedLength.POINT);
rtfGraphic.setHeight((long) (contentheight / 50f) + "twips");
//TODO: make this configurable:
// int compression = m_context.m_options.getRtfExternalGraphicCompressionRate ();
int compression = 0;
if (compression != 0) {
if (!rtfGraphic.setCompressionRate(compression)) {
log.warn("The compression rate " + compression
+ " is invalid. The value has to be between 1 and 100 %.");
}
}
}