public FillPrepareResult prepare(int availableHeight)
{
FillPrepareResult result = null;
JRComponentElement element = fillContext.getComponentElement();
if (template == null) {
template = new JRTemplateGenericElement(
fillContext.getElementOrigin(),
fillContext.getDefaultStyleProvider(),
HTML_COMPONENT_PRINT_TYPE);
template.setMode(htmlComponent.getContext().getComponentElement().getModeValue());
template.setBackcolor(htmlComponent.getContext().getComponentElement().getBackcolor());
template.setForecolor(htmlComponent.getContext().getComponentElement().getForecolor());
}
printElement = new JRTemplateGenericPrintElement(template);
printElement.setX(element.getX());
printElement.setWidth(element.getWidth());
printElement.setHeight(element.getHeight());
if (isEvaluateNow())
{
copy(printElement);
}
else
{
fillContext.registerDelayedEvaluation(printElement,
htmlComponent.getEvaluationTime(), null);
}
Dimension realSize = computeSizeOfPrintElement(printElement);
int realHeight = realSize.height;
int realWidth = realSize.width;
int imageWidth = realWidth;
int imageHeight = realHeight;
if (htmlComponent.getScaleType() == ScaleImageEnum.REAL_SIZE || htmlComponent.getScaleType() == ScaleImageEnum.REAL_HEIGHT) {
if (realWidth > element.getWidth()) {
double wRatio = ((double) element.getWidth()) / realWidth;
imageHeight = (int) (wRatio * realHeight);
imageWidth = element.getWidth();
}
int printElementHeight = Math.max(imageHeight, element.getHeight());
if (imageHeight <= availableHeight) {
result = FillPrepareResult.printStretch(printElementHeight, false);
} else {
result = FillPrepareResult.noPrintOverflow(printElementHeight);
}
if (htmlComponent.getScaleType() == ScaleImageEnum.REAL_SIZE) {
printElement.setWidth(imageWidth);
} else {
printElement.setWidth(element.getWidth());
}
printElement.setHeight(printElementHeight);
} else {
result = FillPrepareResult.PRINT_NO_STRETCH;