Search in sources :

Example 11 with Context2d

use of com.google.gwt.canvas.dom.client.Context2d 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)11 Canvas (com.google.gwt.canvas.client.Canvas)3 CanvasPixelArray (com.google.gwt.canvas.dom.client.CanvasPixelArray)2 ImageData (com.google.gwt.canvas.dom.client.ImageData)2 CanvasElement (com.google.gwt.dom.client.CanvasElement)1 ImageElement (com.google.gwt.dom.client.ImageElement)1 AbsolutePanel (com.google.gwt.user.client.ui.AbsolutePanel)1 HTML (com.google.gwt.user.client.ui.HTML)1 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)1 TextMetrics (com.xenoage.utils.font.TextMetrics)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 ResourceImageOptions (org.cesiumjs.cs.core.options.ResourceImageOptions)1 Entity (org.cesiumjs.cs.datasources.Entity)1 BillboardGraphics (org.cesiumjs.cs.datasources.graphics.BillboardGraphics)1 BillboardGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.BillboardGraphicsOptions)1 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)1 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)1