float imh = (float)dim.getHeight() / 1000f;
float sx = fwidth / (float)imw;
float sy = fheight / (float)imh;
gen.commentln("%FOPBeginGraphics2D");
gen.saveGraphicsState();
// Clip to the image area.
gen.writeln("newpath");
gen.defineRect(fx, fy, fwidth, fheight);
gen.writeln("clip");