Search in sources :

Example 1 with PagePaint

use of org.ebookdroid.core.PagePaint in project LibreraReader by foobnix.

the class Bitmaps method draw.

public boolean draw(final Canvas canvas, final PagePaint paint, final PointF vb, final RectF tr, final RectF cr) {
    lock.readLock().lock();
    try {
        if (this.bitmaps == null) {
            return false;
        }
        final Rect orig = canvas.getClipBounds();
        canvas.clipRect(cr.left - vb.x, cr.top - vb.y, cr.right - vb.x, cr.bottom - vb.y, Op.INTERSECT);
        final float offsetX = tr.left - vb.x;
        final float offsetY = tr.top - vb.y;
        final float scaleX = tr.width() / bounds.width();
        final float scaleY = tr.height() / bounds.height();
        final float sizeX = partSize * scaleX;
        final float sizeY = partSize * scaleY;
        final Rect src = new Rect();
        final RectF rect = new RectF(offsetX, offsetY, offsetX + sizeX, offsetY + sizeY);
        final RectF r = new RectF();
        boolean res = true;
        for (int row = 0; row < rows; row++) {
            for (int col = 0; col < columns; col++) {
                final int index = row * columns + col;
                final BitmapRef ref = this.bitmaps[index];
                if (ref != null) {
                    r.set(rect);
                    if (ref.bitmap != null) {
                        try {
                            src.set(0, 0, ref.bitmap.getWidth(), ref.bitmap.getHeight());
                            canvas.drawBitmap(ref.bitmap, src, MathUtils.round(r), paint.bitmapPaint);
                        } catch (final Throwable th) {
                        }
                    }
                } else {
                    res = false;
                }
                rect.left += sizeX;
                rect.right += sizeX;
            }
            rect.left = offsetX;
            rect.right = offsetX + sizeX;
            rect.top += sizeY;
            rect.bottom += sizeY;
        }
        canvas.clipRect(orig, Op.REPLACE);
        return res;
    } finally {
        lock.readLock().unlock();
    }
}
Also used : RectF(android.graphics.RectF) Rect(android.graphics.Rect) PagePaint(org.ebookdroid.core.PagePaint)

Aggregations

Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 PagePaint (org.ebookdroid.core.PagePaint)1