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);
switch (printImage.getScaleImageValue())
{
case CLIP:
{
xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth));
yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight));
clip =
new Rectangle2D.Double(
- xoffset,
- yoffset,
availableImageWidth,
availableImageHeight
);
break;
}
case FILL_FRAME:
{
ratioX = availableImageWidth / normalWidth;
ratioY = availableImageHeight / normalHeight;
normalWidth *= ratioX;
normalHeight *= ratioY;
xoffset = 0;
yoffset = 0;
break;
}
case RETAIN_SHAPE:
default:
{
ratioX = availableImageWidth / normalWidth;
ratioY = availableImageHeight / normalHeight;
ratioX = ratioX < ratioY ? ratioX : ratioY;
ratioY = ratioX;
normalWidth *= ratioX;
normalHeight *= ratioY;
xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth));
yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight));
break;
}
}
}
PdfTemplate template = pdfContentByte.createTemplate((float)displayWidth, (float)displayHeight);
Graphics2D g = forceSvgShapes
? template.createGraphicsShapes((float)displayWidth, (float)displayHeight)
: template.createGraphics(availableImageWidth, availableImageHeight, new LocalFontMapper());
if (clip != null)
{
g.setClip(clip);
}
if (printImage.getModeValue() == ModeEnum.OPAQUE)
{
g.setColor(printImage.getBackcolor());
g.fillRect(0, 0, (int)displayWidth, (int)displayHeight);
}
Rectangle2D rectangle = new Rectangle2D.Double(0, 0, displayWidth, displayHeight);
renderer.render(g, rectangle);
g.dispose();
pdfContentByte.saveState();