}
int normalWidth = availableImageWidth;
int normalHeight = availableImageHeight;
Dimension2D dimension = renderer.getDimension();
if (dimension != null)
{
normalWidth = (int)dimension.getWidth();
normalHeight = (int)dimension.getHeight();
}
xoffset = (int)(xalignFactor * (availableImageWidth - normalWidth));
yoffset = (int)(yalignFactor * (availableImageHeight - normalHeight));
int minWidth = Math.min(normalWidth, availableImageWidth);
int minHeight = Math.min(normalHeight, availableImageHeight);
BufferedImage bi =
new BufferedImage(minWidth, minHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
if (printImage.getModeValue() == ModeEnum.OPAQUE)
{
g.setColor(printImage.getBackcolor());
g.fillRect(0, 0, minWidth, minHeight);
}
renderer.render(
g,
new java.awt.Rectangle(
(xoffset > 0 ? 0 : xoffset),
(yoffset > 0 ? 0 : yoffset),
normalWidth,
normalHeight
)
);
g.dispose();
xoffset = (xoffset < 0 ? 0 : xoffset);
yoffset = (yoffset < 0 ? 0 : yoffset);
//awtImage = bi.getSubimage(0, 0, minWidth, minHeight);
//image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor());
image = com.lowagie.text.Image.getInstance(bi, null);
break;
}
case FILL_FRAME :
{
if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer))
{
image = (com.lowagie.text.Image)loadedImagesMap.get(renderer);
}
else
{
try
{
image = com.lowagie.text.Image.getInstance(renderer.getImageData());
imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
}
catch(Exception e)
{
JRImageRenderer tmpRenderer =
JRImageRenderer.getOnErrorRendererForImage(
JRImageRenderer.getInstance(renderer.getImageData()),
printImage.getOnErrorTypeValue()
);
if (tmpRenderer == null)
{
break;
}
java.awt.Image awtImage = tmpRenderer.getImage();
image = com.lowagie.text.Image.getInstance(awtImage, null);
}
if (printImage.isUsingCache())
{
loadedImagesMap.put(renderer, image);
}
}
image.scaleAbsolute(availableImageWidth, availableImageHeight);
break;
}
case RETAIN_SHAPE :
default :
{
if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer))
{
image = (com.lowagie.text.Image)loadedImagesMap.get(renderer);
}
else
{
try
{
image = com.lowagie.text.Image.getInstance(renderer.getImageData());
imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
}
catch(Exception e)
{
JRImageRenderer tmpRenderer =
JRImageRenderer.getOnErrorRendererForImage(
JRImageRenderer.getInstance(renderer.getImageData()),
printImage.getOnErrorTypeValue()
);
if (tmpRenderer == null)
{
break;
}
java.awt.Image awtImage = tmpRenderer.getImage();
image = com.lowagie.text.Image.getInstance(awtImage, null);
}
if (printImage.isUsingCache())
{
loadedImagesMap.put(renderer, image);
}
}
image.scaleToFit(availableImageWidth, availableImageHeight);
xoffset = (int)(xalignFactor * (availableImageWidth - image.getPlainWidth()));
yoffset = (int)(yalignFactor * (availableImageHeight - image.getPlainHeight()));
xoffset = (xoffset < 0 ? 0 : xoffset);
yoffset = (yoffset < 0 ? 0 : yoffset);
break;
}
}
if (image != null)
{
chunk = new Chunk(image, 0, 0);
scaledWidth = image.getScaledWidth();
scaledHeight = image.getScaledHeight();
}
}
else
{
double normalWidth = availableImageWidth;
double normalHeight = availableImageHeight;
double displayWidth = availableImageWidth;
double displayHeight = availableImageHeight;
double ratioX = 1f;
double ratioY = 1f;
Rectangle2D clip = null;
Dimension2D dimension = renderer.getDimension();
if (dimension != null)
{
normalWidth = dimension.getWidth();
normalHeight = dimension.getHeight();
displayWidth = normalWidth;
displayHeight = normalHeight;
float xalignFactor = getXAlignFactor(printImage);
float yalignFactor = getYAlignFactor(printImage);