final Dimension2D dimensionsPt = info.getSize().getDimensionPt();
final Dimension2D dimensionsMpt = info.getSize().getDimensionMpt();
if (img instanceof ImageGraphics2D) {
final ImageGraphics2D imageG2D = (ImageGraphics2D)img;
FormGenerator formGen = new FormGenerator(
form.getName(), imageDescription, dimensionsPt) {
protected void generatePaintProc(PSGenerator gen)
throws IOException {
gen.getResourceTracker().notifyResourceUsageOnPage(
PSProcSets.EPS_PROCSET);
gen.writeln("BeginEPSF");
PSGraphics2DAdapter adapter = new PSGraphics2DAdapter(gen, false);
adapter.paintImage(imageG2D.getGraphics2DImagePainter(),
null,
0, 0,
(int)Math.round(dimensionsMpt.getWidth()),
(int)Math.round(dimensionsMpt.getHeight()));
gen.writeln("EndEPSF");
}
};
formGen.generate(gen);
} else if (img instanceof ImageRendered) {
ImageRendered imgRend = (ImageRendered)img;
RenderedImage ri = imgRend.getRenderedImage();
FormGenerator formGen = new ImageFormGenerator(
form.getName(), imageDescription,
info.getSize().getDimensionPt(),
ri, false);
formGen.generate(gen);
} else if (img instanceof ImageXMLDOM) {
throw new UnsupportedOperationException(
"Embedding an ImageXMLDOM as a form isn't supported, yet");
} else if (img instanceof ImageRawStream) {
final ImageRawStream raw = (ImageRawStream)img;
if (raw instanceof ImageRawEPS) {
final ImageRawEPS eps = (ImageRawEPS)raw;
throw new UnsupportedOperationException(
"Embedding EPS as forms isn't supported, yet");
/*
InputStream in = eps.createInputStream();
try {
FormGenerator formGen = new EPSFormGenerator(form.getName(),
imageDescription, dimensions, in);
formGen.generate(gen);
} finally {
IOUtils.closeQuietly(in);
}*/
} else if (raw instanceof ImageRawCCITTFax) {
ImageRawCCITTFax jpeg = (ImageRawCCITTFax)raw;
ImageEncoder encoder = new ImageEncoderCCITTFax(jpeg);
FormGenerator formGen = new ImageFormGenerator(
form.getName(), imageDescription,
info.getSize().getDimensionPt(),
info.getSize().getDimensionPx(),
encoder,
jpeg.getColorSpace(), 1, false);
formGen.generate(gen);
} else if (raw instanceof ImageRawJPEG) {
ImageRawJPEG jpeg = (ImageRawJPEG)raw;
ImageEncoder encoder = new ImageEncoderJPEG(jpeg);
FormGenerator formGen = new ImageFormGenerator(
form.getName(), imageDescription,
info.getSize().getDimensionPt(),
info.getSize().getDimensionPx(),
encoder,
jpeg.getColorSpace(), jpeg.isInverted());
formGen.generate(gen);
} else {
throw new UnsupportedOperationException("Unsupported raw image: " + info);
}
} else {
throw new UnsupportedOperationException("Unsupported image type: " + img);