Search in sources :

Example 1 with AndroidCanvas

use of com.xenoage.zong.android.renderer.canvas.AndroidCanvas in project Zong by Xenoage.

the class AndroidLayoutRenderer method paint.

/**
 * Returns a {@link Bitmap} with the given page of the given {@link Layout}
 * which is rendered at the given zoom level.
 */
public Bitmap paint(Layout layout, int pageIndex, float zoom) {
    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);
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    // TODO: necessary? and really 8888 bitmap?
    canvas.drawARGB(255, 255, 255, 255);
    canvas.scale(zoom, zoom);
    paint(layout, pageIndex, new AndroidCanvas(canvas, pageSize, CanvasFormat.Raster, CanvasDecoration.None, CanvasIntegrity.Perfect), zoom);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Size2f(com.xenoage.utils.math.geom.Size2f) AndroidCanvas(com.xenoage.zong.android.renderer.canvas.AndroidCanvas) Canvas(android.graphics.Canvas) Page(com.xenoage.zong.layout.Page) AndroidCanvas(com.xenoage.zong.android.renderer.canvas.AndroidCanvas)

Example 2 with AndroidCanvas

use of com.xenoage.zong.android.renderer.canvas.AndroidCanvas in project Zong by Xenoage.

the class ScreenViewBitmaps method renderPage.

private Bitmap renderPage(int page) {
    Bitmap ret = Bitmap.createBitmap(screenSize.width, screenSize.height, Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    int background = R.drawable.paper_middle;
    int pagesCount = layout.getPages().size();
    if (pagesCount == 1)
        background = R.drawable.paper_single;
    else if (page == 0)
        background = R.drawable.paper_first;
    else if (page == pagesCount - 1)
        background = R.drawable.paper_last;
    Bitmap bmp = BitmapFactory.decodeResource(resources, background);
    canvas.drawBitmap(bmp, null, canvas.getClipBounds(), null);
    AndroidCanvas context = new AndroidCanvas(canvas, layout.getPages().get(page).getFormat().getSize(), CanvasFormat.Raster, CanvasDecoration.None, CanvasIntegrity.Perfect);
    androidLayoutRenderer.paint(layout, page, context, scaling);
    // first page: draw title
    if (page == 0) {
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        paint.setAntiAlias(true);
        paint.setTypeface(Typeface.SERIF);
        paint.setTextSize(titleTextHeightPx * 0.6f);
        float width = paint.measureText(title);
        canvas.drawText(title, screenSize.width / 2 - width / 2, marginPx + titleTextHeightPx, paint);
    }
    return ret;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) AndroidCanvas(com.xenoage.zong.android.renderer.canvas.AndroidCanvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint) AndroidCanvas(com.xenoage.zong.android.renderer.canvas.AndroidCanvas)

Example 3 with AndroidCanvas

use of com.xenoage.zong.android.renderer.canvas.AndroidCanvas in project Zong by Xenoage.

the class ScoreDocScoreView method renderPage.

private Bitmap renderPage(int pageIndex) {
    // prepare bitmap
    Bitmap ret = Bitmap.createBitmap(screenSizePx.width, screenSizePx.height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    AndroidCanvas androidCanvas = new AndroidCanvas(canvas, layout.getPages().get(pageIndex).getFormat().getSize(), CanvasFormat.Raster, CanvasDecoration.None, CanvasIntegrity.Perfect);
    // background
    canvas.drawBitmap(getBackgroundImage(pageIndex), null, canvas.getClipBounds(), null);
    // paint score
    androidLayoutRenderer.paint(layout, pageIndex, androidCanvas, zoom);
    // first page: draw title
    if (pageIndex == 0) {
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        paint.setAntiAlias(true);
        paint.setTypeface(Typeface.SERIF);
        paint.setTextSize(titleTextHeightPx * 0.6f);
        float width = paint.measureText(title);
        canvas.drawText(title, screenSizePx.width / 2 - width / 2, marginPx + titleTextHeightPx, paint);
    }
    return ret;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) AndroidCanvas(com.xenoage.zong.android.renderer.canvas.AndroidCanvas) Paint(android.graphics.Paint) AndroidCanvas(com.xenoage.zong.android.renderer.canvas.AndroidCanvas)

Aggregations

Bitmap (android.graphics.Bitmap)3 Canvas (android.graphics.Canvas)3 AndroidCanvas (com.xenoage.zong.android.renderer.canvas.AndroidCanvas)3 Paint (android.graphics.Paint)2 Size2f (com.xenoage.utils.math.geom.Size2f)1 Page (com.xenoage.zong.layout.Page)1