final long internalImageHeight = StrictGeomUtility.toInternalValue(scaleFactor * imageHeight);
final long cellWidth = cellBounds.getWidth();
final long cellHeight = cellBounds.getHeight();
final StrictBounds cb;
final int pictureId;
try
{
if (shouldScale)
{
final double scaleX;
final double scaleY;
final boolean keepAspectRatio = layoutContext.getBooleanStyleProperty(ElementStyleKeys.KEEP_ASPECT_RATIO);
if (keepAspectRatio)
{
final double imgScaleFactor = Math.min(cellWidth / (double) internalImageWidth,
cellHeight / (double) internalImageHeight);
scaleX = imgScaleFactor;
scaleY = imgScaleFactor;
}
else
{
scaleX = cellWidth / (double) internalImageWidth;
scaleY = cellHeight / (double) internalImageHeight;
}
final long clipWidth = (long) (scaleX * internalImageWidth);
final long clipHeight = (long) (scaleY * internalImageHeight);
final long alignmentX = RenderUtility.computeHorizontalAlignment(horizontalAlignment, cellWidth, clipWidth);
final long alignmentY = RenderUtility.computeVerticalAlignment(verticalAlignment, cellHeight, clipHeight);
cb = new StrictBounds(cellBounds.getX() + alignmentX,
cellBounds.getY() + alignmentY,
Math.min(clipWidth, cellWidth),
Math.min(clipHeight, cellHeight));
// Recompute the cells that this image will cover (now that it has been resized)
rectangle = currentLayout.getTableBounds(cb, rectangle);
pictureId = loadImage(image);
if (printerBase.isUseXlsxFormat())
{
if (pictureId < 0)
{
return;
}
}
else if (pictureId <= 0)
{
return;
}
}
else
{
// unscaled ..
if (internalImageWidth <= cellWidth &&
internalImageHeight <= cellHeight)
{
// No clipping needed.
final long alignmentX = RenderUtility.computeHorizontalAlignment
(horizontalAlignment, cellBounds.getWidth(), internalImageWidth);
final long alignmentY = RenderUtility.computeVerticalAlignment
(verticalAlignment, cellBounds.getHeight(), internalImageHeight);
cb = new StrictBounds(cellBounds.getX() + alignmentX,
cellBounds.getY() + alignmentY,
internalImageWidth,
internalImageHeight);
// Recompute the cells that this image will cover (now that it has been resized)
rectangle = currentLayout.getTableBounds(cb, rectangle);
pictureId = loadImage(image);
if (printerBase.isUseXlsxFormat())
{
if (pictureId < 0)
{
return;
}
}
else if (pictureId <= 0)
{
return;
}
}
else
{
// at least somewhere there is clipping needed.
final long clipWidth = Math.min(cellWidth, internalImageWidth);
final long clipHeight = Math.min(cellHeight, internalImageHeight);
final long alignmentX = RenderUtility.computeHorizontalAlignment
(horizontalAlignment, cellBounds.getWidth(), clipWidth);
final long alignmentY = RenderUtility.computeVerticalAlignment
(verticalAlignment, cellBounds.getHeight(), clipHeight);
cb = new StrictBounds(cellBounds.getX() + alignmentX,
cellBounds.getY() + alignmentY,
clipWidth,
clipHeight);
// Recompute the cells that this image will cover (now that it has been resized)