Search in sources :

Example 1 with GwtCanvas

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);
}
Also used : Context2d(com.google.gwt.canvas.dom.client.Context2d) GwtCanvas(com.xenoage.zong.renderer.gwtcanvas.canvas.GwtCanvas) Size2f(com.xenoage.utils.math.geom.Size2f) Page(com.xenoage.zong.layout.Page) Size2i(com.xenoage.utils.math.geom.Size2i)

Aggregations

Context2d (com.google.gwt.canvas.dom.client.Context2d)1 Size2f (com.xenoage.utils.math.geom.Size2f)1 Size2i (com.xenoage.utils.math.geom.Size2i)1 Page (com.xenoage.zong.layout.Page)1 GwtCanvas (com.xenoage.zong.renderer.gwtcanvas.canvas.GwtCanvas)1