use of com.xenoage.zong.renderer.gwtcanvas.canvas.GwtCanvas in project Zong by Xenoage.
the class GwtCanvasLayoutRenderer method paintToCanvas.
/**
* Paints the given page of the given {@link Layout} at the given zoom level
* into the given {@link CanvasElement}, which is resized to include the whole page.
* The size in pixel is also returned.
*/
public static Size2i paintToCanvas(Layout layout, int pageIndex, float zoom, com.google.gwt.canvas.client.Canvas canvas) {
Context2d context = canvas.getContext2d();
// compute size
Page page = layout.getPages().get(pageIndex);
Size2f pageSize = page.getFormat().getSize();
int width = Units.mmToPxInt(pageSize.width, zoom);
int height = Units.mmToPxInt(pageSize.height, zoom);
// resize canvas and coordinate space
canvas.setWidth(width + "px");
canvas.setHeight(height + "px");
// double resolution: smoother
int coordSpaceFactor = 2;
canvas.setCoordinateSpaceWidth(width * coordSpaceFactor);
canvas.setCoordinateSpaceHeight(height * coordSpaceFactor);
context.scale(coordSpaceFactor, coordSpaceFactor);
// white page
context.setFillStyle("white");
context.fillRect(0, 0, width, height);
// paint layout
LayoutRenderer.paintToCanvas(layout, pageIndex, zoom, origin, new GwtCanvas(context, CanvasFormat.Raster, CanvasDecoration.Interactive, CanvasIntegrity.Perfect));
return new Size2i(width, height);
}