package epson.print.copy.Component.ecopycomponent;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.p000v4.internal.view.SupportMenu;
import android.view.View;
import android.widget.LinearLayout;
import epson.common.Constants;
import epson.print.copy.Component.ecopycomponent.ECopyComponent;
import epson.print.copy.Component.ecopycomponent.ECopyOptionItem;

public class ECopyPreview extends View {

    /* renamed from: A4 */
    final Size f360A4 = new Size(1240, Constants.SCAN_MAX_HEIGHT);
    final Size A4_2Up = new Size(Constants.SCAN_MAX_HEIGHT, 1240);
    final Size A4_2UpPage = new Size(827, 1176);

    /* renamed from: B5 */
    final Size f361B5 = new Size(1075, 1518);
    final int BM_2Up = 35;
    final int BM_Border = 18;
    final int BO_Type1 = 24;
    final int BO_Type2 = 15;
    final Size Hagaki = new Size(591, 874);

    /* renamed from: KG */
    final Size f362KG = new Size(602, 898);

    /* renamed from: L */
    final Size f363L = new Size(526, 750);

    /* renamed from: L2 */
    final Size f364L2 = new Size(750, 1051);
    final int LM_2Up = 32;
    final int LM_Border = 18;
    final int LO_Type1 = 15;
    final int LO_Type2 = 15;
    final Size Max = new Size(Constants.SCAN_MAX_WIDTH, Constants.SCAN_MAX_HEIGHT);

    /* renamed from: P6 */
    final Size f365P6 = new Size(1199, 1500);
    final int PG_2Up = 35;
    final int PL_A4 = Constants.SCAN_MAX_HEIGHT;
    final int PL_B5 = 1518;
    final int PL_Hagaki = 874;
    final int PL_KG = 898;
    final int PL_L = 750;
    final int PL_L2 = 1051;
    final int PL_MAX = Constants.SCAN_MAX_HEIGHT;
    final int PL_P6 = 1500;
    final int PW_A4 = 1240;
    final int PW_B5 = 1075;
    final int PW_Hagaki = 591;
    final int PW_KG = 602;
    final int PW_L = 526;
    final int PW_L2 = 750;
    final int PW_MAX = Constants.SCAN_MAX_WIDTH;
    final int PW_P6 = 1199;
    final int RM_2Up = 32;
    final int RM_Border = 18;
    final int RO_Type1 = 15;
    final int RO_Type2 = 15;
    final int TM_2Up = 30;
    final int TM_Border = 18;
    final int TO_Type1 = 17;
    final int TO_Type2 = 8;
    Drawable backgroundDrawable = new ColorDrawable(0);
    ECopyOptionItem colorOption;
    ECopyOptionItem copiesOpiton;
    Paint copyFramePaint = new Paint();
    Size drawSize;
    Paint grayscalePaint;
    Layout layout;
    ECopyPreviewInvalidateListener listener;
    ICopyPreviewCommitEditedOptionContext optionCommitter;
    ECopyOptionContext optionContext;
    Drawable paperDrawable = new ColorDrawable(-1);
    RectF paperFrame;
    Rect paperPadding;
    Paint paperShadowPaint;
    ECopyOptionItem scaleOption;

    public enum ECopyPreviewColor {
        Color,
        Monochrome
    }

    public interface ECopyPreviewInvalidateListener {
        void needInvalidateView();
    }

    interface ICopyPreviewCommitEditedOptionContext {
        void commit(ECopyOptionContext eCopyOptionContext);
    }

    protected interface ScanImageSizeCalculator {
        void onScanImageSize(int i, int i2, float f);
    }

    private ECopyPreview(Context context) {
        super(context);
        this.copyFramePaint.setColor(SupportMenu.CATEGORY_MASK);
        this.copyFramePaint.setStyle(Paint.Style.STROKE);
        this.copyFramePaint.setStrokeWidth(2.0f);
        this.paperPadding = new Rect();
        this.grayscalePaint = new Paint();
        this.paperShadowPaint = new Paint();
        this.paperFrame = new RectF();
        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0.0f);
        this.grayscalePaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    }

    public void setBackground(Drawable drawable) {
        this.backgroundDrawable = drawable;
    }

    public void setPaperDrawable(Drawable drawable) {
        this.paperDrawable = drawable;
    }

    public void setCopyFramePaint(Paint paint) {
        this.copyFramePaint = paint;
    }

    public void setPaperShadowPaint(Paint paint) {
        this.paperShadowPaint = paint;
    }

    public void setPaperPadding(Rect rect) {
        this.paperPadding = new Rect(rect);
        resize();
    }

    private void requestInvalidateView() {
        ((Activity) getContext()).runOnUiThread(new Runnable() {
            public void run() {
                ECopyPreview.this.listener.needInvalidateView();
            }
        });
    }

    public void setColor(ECopyPreviewColor eCopyPreviewColor) {
        ECopyOptionItem.ECopyOptionItemChoice eCopyOptionItemChoice = ECopyOptionItem.ECopyOptionItemChoice.ColorEffectsType_Color;
        if (eCopyPreviewColor == ECopyPreviewColor.Monochrome) {
            eCopyOptionItemChoice = ECopyOptionItem.ECopyOptionItemChoice.ColorEffectsType_MonochromeGrayscale;
        }
        this.colorOption.selectChoice(eCopyOptionItemChoice);
        requestInvalidateView();
    }

    public ECopyPreviewColor getColor() {
        return this.colorOption.getSelectedChoice() == ECopyOptionItem.ECopyOptionItemChoice.ColorEffectsType_MonochromeGrayscale ? ECopyPreviewColor.Monochrome : ECopyPreviewColor.Color;
    }

    public void setScale(int i) {
        this.scaleOption.selectValue(i);
        this.layout.setCopyScale(((float) this.scaleOption.getSelectedValue()) / 100.0f);
        requestInvalidateView();
    }

    public int getScale() {
        return this.scaleOption.getSelectedValue();
    }

    public void setCopies(int i) {
        this.copiesOpiton.selectValue(i);
    }

    public int getCopies() {
        return this.copiesOpiton.getSelectedValue();
    }

    public void dismiss(boolean z) {
        if (z) {
            this.optionCommitter.commit(this.optionContext);
        }
    }

    private void compose(ECopyOptionContext eCopyOptionContext, ICopyPreviewCommitEditedOptionContext iCopyPreviewCommitEditedOptionContext) {
        this.optionContext = eCopyOptionContext;
        this.optionCommitter = iCopyPreviewCommitEditedOptionContext;
        this.copiesOpiton = this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.Copies);
        this.scaleOption = this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.CopyMagnification);
        this.colorOption = this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.ColorEffectsType);
        resize();
    }

    private void resize() {
        int i = (this.drawSize.width - this.paperPadding.left) - this.paperPadding.right;
        int i2 = (this.drawSize.height - this.paperPadding.top) - this.paperPadding.bottom;
        ECopyComponent.ECopyType copyType = this.optionContext.getCopyType();
        if (copyType == ECopyComponent.ECopyType.A4_2up || copyType == ECopyComponent.ECopyType.B5_2up || copyType == ECopyComponent.ECopyType.A4_2up_Book || copyType == ECopyComponent.ECopyType.B5_2up_Book) {
            this.layout = new Layout2Up(i, i2);
        } else if (copyType == ECopyComponent.ECopyType.Mirror) {
            this.layout = new LayoutMirror(i, i2);
        } else if (copyType == ECopyComponent.ECopyType.Borderless) {
            this.layout = new LayoutBorderless(i, i2);
        } else {
            this.layout = new LayoutStandard(i, i2);
        }
        this.layout.setCopyScale(((float) this.scaleOption.getSelectedValue()) / 100.0f);
    }

    protected static ECopyPreview createPreview(Context context, int i, int i2, ECopyPreviewInvalidateListener eCopyPreviewInvalidateListener) {
        ECopyPreview eCopyPreview = new ECopyPreview(context);
        eCopyPreview.setLayoutParams(new LinearLayout.LayoutParams(i, i2));
        eCopyPreview.getClass();
        eCopyPreview.drawSize = new Size(i, i2);
        eCopyPreview.listener = eCopyPreviewInvalidateListener;
        return eCopyPreview;
    }

    protected void drawScanPreview(Bitmap bitmap) {
        this.layout.setScanImage(bitmap);
        requestInvalidateView();
    }

    protected void calculateScanImageSize(int i, int i2, ScanImageSizeCalculator scanImageSizeCalculator) {
        float scanImageScale = this.layout.getScanImageScale(i, i2);
        scanImageSizeCalculator.onScanImageSize((int) (((float) i) * scanImageScale), (int) (((float) i2) * scanImageScale), scanImageScale);
    }

    protected void setPaperFrame(RectF rectF) {
        this.paperFrame = rectF;
        this.layout.setPaperFrame(rectF);
        requestInvalidateView();
    }

    protected void onDraw(Canvas canvas) {
        canvas.save();
        this.backgroundDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        this.backgroundDrawable.draw(canvas);
        Point offset = this.layout.getOffset();
        offset.offset(this.paperPadding.left, this.paperPadding.top);
        RectF paperRect = this.layout.getPaperRect();
        paperRect.offset((float) offset.x, (float) offset.y);
        if (this.optionContext.copyType == ECopyComponent.ECopyType.Mirror) {
            canvas.scale(-1.0f, 1.0f);
            canvas.translate(-(paperRect.centerX() * 2.0f), 0.0f);
        }
        canvas.drawRect(paperRect, this.paperShadowPaint);
        Paint paint = null;
        if (this.colorOption.getSelectedChoice() == ECopyOptionItem.ECopyOptionItemChoice.ColorEffectsType_MonochromeGrayscale) {
            paint = this.grayscalePaint;
        }
        canvas.drawBitmap(this.layout.getBitmap(), (float) offset.x, (float) offset.y, paint);
        RectF copyFrame = this.layout.getCopyFrame();
        if (!this.paperFrame.isEmpty() && copyFrame != null) {
            copyFrame.offset((float) offset.x, (float) offset.y);
            Path path = new Path();
            path.addRect(copyFrame, Path.Direction.CW);
            canvas.drawPath(path, this.copyFramePaint);
        }
        canvas.restore();
    }

    class Size {
        int height;
        int width;

        Size(int i, int i2) {
            this.width = i;
            this.height = i2;
        }

        Size(Size size) {
            this.width = size.width;
            this.height = size.height;
        }

        private void scale(float f) {
            this.width = (int) (((float) this.width) * f);
            this.height = (int) (((float) this.height) * f);
        }
    }

    static abstract class Layout {

        enum AspectFit {
            Max,
            Min
        }

        private abstract Bitmap getBitmap();

        private abstract RectF getCopyFrame();

        private abstract Point getOffset();

        private abstract RectF getPaperRect();

        private abstract float getScanImageScale(int i, int i2);

        private abstract void setCopyScale(float f);

        private abstract void setPaperFrame(RectF rectF);

        private abstract void setScanImage(Bitmap bitmap);

        Layout() {
        }

        private void scaleRect(float f, RectF rectF) {
            Matrix matrix = new Matrix();
            matrix.postScale(f, f);
            matrix.mapRect(rectF);
        }

        private float getAspectFitScale(float f, float f2, float f3, float f4, AspectFit aspectFit) {
            PointF pointF = new PointF();
            pointF.x = f / f3;
            pointF.y = f2 / f4;
            return aspectFit == AspectFit.Min ? Math.min(pointF.x, pointF.y) : Math.max(pointF.x, pointF.y);
        }
    }

    class LayoutStandard extends Layout {
        boolean autofitEnabled = false;
        Canvas canvas;
        RectF copyFrame;
        float copyScale = 1.0f;
        float imageScale = 1.0f;
        int layoutHeight;
        int layoutWidth;
        float limitCopyScaleDown = 0.0f;
        Bitmap maxPaperImage;
        Point offset = new Point();
        RectF paper;
        Path paperBorderClipPath = new Path();
        Bitmap paperImage;
        Size paperSize;
        RectF scanFrame;
        Bitmap scanImage;

        LayoutStandard(int i, int i2) {
            this.layoutWidth = i;
            this.layoutHeight = i2;
            if (ECopyPreview.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.XScale).getSelectedChoice() == ECopyOptionItem.ECopyOptionItemChoice.XScale_Autofit) {
                this.autofitEnabled = true;
            }
            ECopyOptionItem copyOptionItemOf = ECopyPreview.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.PrintMediaSize);
            switch (copyOptionItemOf.getSelectedChoice()) {
                case PrintMediaSize_A4:
                    this.paperSize = ECopyPreview.this.f360A4;
                    break;
                case PrintMediaSize_B5:
                    this.paperSize = ECopyPreview.this.f361B5;
                    break;
                case PrintMediaSize_L:
                    this.paperSize = ECopyPreview.this.f363L;
                    break;
                case PrintMediaSize_2L:
                    this.paperSize = ECopyPreview.this.f364L2;
                    break;
                case PrintMediaSize_Postcard:
                    this.paperSize = ECopyPreview.this.Hagaki;
                    break;
                case PrintMediaSize_KG:
                    this.paperSize = ECopyPreview.this.f362KG;
                    break;
                case PrintMediaSize_8x10in:
                    this.paperSize = ECopyPreview.this.f365P6;
                    break;
                default:
                    this.paperSize = ECopyPreview.this.Max;
                    break;
            }
            float f = (float) i;
            float f2 = (float) i2;
            float aspectFitScale = getAspectFitScale(f, f2, (float) this.paperSize.width, (float) this.paperSize.height, Layout.AspectFit.Min);
            RectF rectF = new RectF(0.0f, 0.0f, (float) this.paperSize.width, (float) this.paperSize.height);
            scaleRect(aspectFitScale, rectF);
            this.paperImage = Bitmap.createBitmap((int) rectF.width(), (int) rectF.height(), Bitmap.Config.ARGB_8888);
            RectF rectF2 = new RectF(0.0f, 0.0f, (float) this.paperSize.width, (float) this.paperSize.height);
            rectF2.left += 18.0f;
            rectF2.top += 18.0f;
            rectF2.right -= 18.0f;
            rectF2.bottom -= 18.0f;
            scaleRect(aspectFitScale, rectF2);
            this.paperBorderClipPath.addRect(rectF2, Path.Direction.CW);
            float aspectFitScale2 = getAspectFitScale(f, f2, (float) ECopyPreview.this.Max.width, (float) ECopyPreview.this.Max.height, Layout.AspectFit.Min);
            RectF rectF3 = new RectF(0.0f, 0.0f, (float) ECopyPreview.this.Max.width, (float) ECopyPreview.this.Max.height);
            scaleRect(aspectFitScale2, rectF3);
            this.maxPaperImage = Bitmap.createBitmap((int) rectF3.width(), (int) rectF3.height(), Bitmap.Config.ARGB_8888);
            invalidatePaperSize();
        }

        private Bitmap getBitmap() {
            boolean showPaper = showPaper();
            Bitmap bitmap = showPaper ? this.paperImage : this.maxPaperImage;
            this.canvas = new Canvas(bitmap);
            this.canvas.save();
            ECopyPreview.this.paperDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
            ECopyPreview.this.paperDrawable.draw(this.canvas);
            Bitmap bitmap2 = this.scanImage;
            if (bitmap2 != null) {
                if (showPaper) {
                    float f = this.copyScale / this.limitCopyScaleDown;
                    if (this.autofitEnabled) {
                        f = 1.0f / getAspectFitScale(this.scanFrame.width(), this.scanFrame.height(), (float) this.canvas.getWidth(), (float) this.canvas.getHeight(), Layout.AspectFit.Max);
                    }
                    Matrix matrix = new Matrix();
                    matrix.postScale(f, f);
                    this.canvas.clipPath(this.paperBorderClipPath);
                    this.canvas.drawBitmap(this.scanImage, matrix, (Paint) null);
                } else {
                    this.canvas.drawBitmap(bitmap2, 0.0f, 0.0f, (Paint) null);
                }
            }
            this.canvas.restore();
            return bitmap;
        }

        private float getScanImageScale(int i, int i2) {
            this.imageScale = getAspectFitScale((float) ((ECopyPreview.this.drawSize.width - ECopyPreview.this.paperPadding.left) - ECopyPreview.this.paperPadding.right), (float) ((ECopyPreview.this.drawSize.height - ECopyPreview.this.paperPadding.top) - ECopyPreview.this.paperPadding.bottom), (float) i, (float) i2, Layout.AspectFit.Min);
            return this.imageScale;
        }

        private void setScanImage(Bitmap bitmap) {
            this.scanImage = bitmap;
        }

        private Point getOffset() {
            return new Point(this.offset);
        }

        private void setPaperFrame(RectF rectF) {
            this.scanFrame = new RectF(rectF);
            scaleRect(this.imageScale, this.scanFrame);
            this.copyFrame = new RectF(rectF);
            this.copyFrame.left += 18.0f;
            this.copyFrame.top += 18.0f;
            this.copyFrame.right -= 36.0f;
            this.copyFrame.bottom -= 36.0f;
            scaleRect(this.imageScale, this.copyFrame);
            calcLimitCopyScaleDown();
            invalidatePaperSize();
        }

        private RectF getCopyFrame() {
            RectF rectF;
            if (showPaper() || this.scanImage == null || (rectF = this.copyFrame) == null) {
                return null;
            }
            RectF rectF2 = new RectF(rectF);
            float max = 1.0f / Math.max(this.copyScale, this.limitCopyScaleDown);
            rectF2.right *= max;
            rectF2.bottom *= max;
            return rectF2;
        }

        private void setCopyScale(float f) {
            this.copyScale = f;
            invalidatePaperSize();
        }

        private boolean showPaper() {
            boolean z = this.copyScale < this.limitCopyScaleDown;
            if (this.autofitEnabled) {
                return true;
            }
            return z;
        }

        private void invalidatePaperSize() {
            Size size = showPaper() ? this.paperSize : ECopyPreview.this.Max;
            float aspectFitScale = getAspectFitScale((float) this.layoutWidth, (float) this.layoutHeight, (float) size.width, (float) size.height, Layout.AspectFit.Min);
            this.paper = new RectF(0.0f, 0.0f, (float) size.width, (float) size.height);
            scaleRect(aspectFitScale, this.paper);
            this.offset.x = ((int) (((float) this.layoutWidth) - this.paper.right)) / 2;
            this.offset.y = ((int) (((float) this.layoutHeight) - this.paper.bottom)) / 2;
        }

        private void calcLimitCopyScaleDown() {
            this.limitCopyScaleDown = getAspectFitScale(this.copyFrame.right, this.copyFrame.bottom, this.paper.width(), this.paper.height(), Layout.AspectFit.Max);
        }

        private RectF getPaperRect() {
            return new RectF(0.0f, 0.0f, this.paper.width(), this.paper.height());
        }
    }

    class LayoutMirror extends LayoutStandard {
        LayoutMirror(int i, int i2) {
            super(i, i2);
        }

        private Bitmap getBitmap() {
            boolean showPaper = showPaper();
            Bitmap bitmap = showPaper ? this.paperImage : this.maxPaperImage;
            this.canvas = new Canvas(bitmap);
            this.canvas.save();
            ECopyPreview.this.paperDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
            ECopyPreview.this.paperDrawable.draw(this.canvas);
            if (this.scanImage != null) {
                if (showPaper) {
                    float f = this.copyScale / this.limitCopyScaleDown;
                    if (this.autofitEnabled) {
                        f = 1.0f / getAspectFitScale(this.scanFrame.width(), this.scanFrame.height(), (float) this.canvas.getWidth(), (float) this.canvas.getHeight(), Layout.AspectFit.Max);
                    }
                    Matrix matrix = new Matrix();
                    matrix.postScale(f, f);
                    matrix.postTranslate(((float) bitmap.getWidth()) - (((float) this.scanImage.getWidth()) * f), 0.0f);
                    this.canvas.clipPath(this.paperBorderClipPath);
                    this.canvas.drawBitmap(this.scanImage, matrix, (Paint) null);
                } else {
                    this.canvas.drawBitmap(this.scanImage, 0.0f, 0.0f, (Paint) null);
                }
            }
            this.canvas.restore();
            return bitmap;
        }
    }

    class LayoutBorderless extends LayoutStandard {

        /* renamed from: BO */
        int f367BO;

        /* renamed from: LO */
        int f368LO;

        /* renamed from: RO */
        int f369RO;

        /* renamed from: TO */
        int f370TO;

        LayoutBorderless(int i, int i2) {
            super(i, i2);
            ECopyOptionItem.ECopyOptionItemChoice selectedChoice = ECopyPreview.this.optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.PrintMediaSize).getSelectedChoice();
            if (selectedChoice == ECopyOptionItem.ECopyOptionItemChoice.PrintMediaSize_KG || selectedChoice == ECopyOptionItem.ECopyOptionItemChoice.PrintMediaSize_L || selectedChoice == ECopyOptionItem.ECopyOptionItemChoice.PrintMediaSize_Postcard) {
                this.f368LO = 15;
                this.f369RO = 15;
                this.f370TO = 8;
                this.f367BO = 15;
                return;
            }
            this.f368LO = 15;
            this.f369RO = 15;
            this.f370TO = 17;
            this.f367BO = 15;
        }

        private Bitmap getBitmap() {
            boolean showPaper = showPaper();
            Bitmap bitmap = showPaper ? this.paperImage : this.maxPaperImage;
            this.canvas = new Canvas(bitmap);
            this.canvas.save();
            ECopyPreview.this.paperDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
            ECopyPreview.this.paperDrawable.draw(this.canvas);
            if (this.scanImage != null) {
                if (showPaper) {
                    float f = this.copyScale;
                    if (this.autofitEnabled) {
                        f = 1.0f / getAspectFitScale(this.scanFrame.width(), this.scanFrame.height(), (float) ((this.paperImage.getWidth() + this.f368LO) + this.f369RO), (float) ((this.paperImage.getHeight() + this.f370TO) + this.f367BO), Layout.AspectFit.Min);
                    }
                    Matrix matrix = new Matrix();
                    matrix.postTranslate((float) (-this.f368LO), (float) (-this.f370TO));
                    matrix.postScale(f, f);
                    this.canvas.drawBitmap(this.scanImage, matrix, (Paint) null);
                } else {
                    this.canvas.drawBitmap(this.scanImage, (float) (-this.f368LO), (float) (-this.f370TO), (Paint) null);
                }
            }
            this.canvas.restore();
            return bitmap;
        }

        private void setPaperFrame(RectF rectF) {
            this.scanFrame = new RectF(rectF);
            scaleRect(this.imageScale, this.scanFrame);
            this.copyFrame = new RectF(rectF);
            scaleRect(this.imageScale, this.copyFrame);
            calcLimitCopyScaleDown();
            invalidatePaperSize();
            this.f368LO = (int) (((float) this.f368LO) * this.imageScale);
            this.f369RO = (int) (((float) this.f369RO) * this.imageScale);
            this.f370TO = (int) (((float) this.f370TO) * this.imageScale);
            this.f367BO = (int) (((float) this.f367BO) * this.imageScale);
        }
    }

    class Layout2Up extends Layout {
        RectF copyFrame;
        float imageScale;
        Point offset = new Point();
        RectF page1;
        Bitmap page1Bitmap;
        RectF page2;
        RectF paper;

        private RectF getCopyFrame() {
            return null;
        }

        private void setCopyScale(float f) {
        }

        Layout2Up(int i, int i2) {
            Size size = ECopyPreview.this.A4_2Up;
            Size size2 = ECopyPreview.this.A4_2UpPage;
            this.paper = new RectF(0.0f, 0.0f, (float) size.width, (float) size.height);
            this.page1 = new RectF(30.0f, 32.0f, (float) (size2.width + 30), (float) (size2.height + 32));
            this.page2 = new RectF(this.page1.right + 35.0f, this.page1.top, this.page1.right + 35.0f + ((float) size2.width), this.page1.bottom);
            float f = (float) i;
            float f2 = (float) i2;
            float aspectFitScale = getAspectFitScale(f, f2, (float) size.width, (float) size.height, Layout.AspectFit.Min);
            scaleRect(aspectFitScale, this.paper);
            scaleRect(aspectFitScale, this.page1);
            scaleRect(aspectFitScale, this.page2);
            this.offset.x = ((int) (f - this.paper.right)) / 2;
            this.offset.y = ((int) (f2 - this.paper.bottom)) / 2;
        }

        public Bitmap getBitmap() {
            Bitmap createBitmap = Bitmap.createBitmap((int) this.paper.width(), (int) this.paper.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(createBitmap);
            ECopyPreview.this.paperDrawable.setBounds(0, 0, createBitmap.getWidth(), createBitmap.getHeight());
            ECopyPreview.this.paperDrawable.draw(canvas);
            Bitmap createBitmap2 = Bitmap.createBitmap((int) this.page1.width(), (int) this.page1.height(), Bitmap.Config.ARGB_8888);
            new Canvas(createBitmap2).drawColor(-3355444);
            Bitmap bitmap = this.page1Bitmap;
            if (bitmap == null) {
                bitmap = createBitmap2;
            }
            canvas.drawBitmap(bitmap, (Rect) null, this.page1, (Paint) null);
            canvas.drawBitmap(createBitmap2, (Rect) null, this.page2, (Paint) null);
            return createBitmap;
        }

        private float getScanImageScale(int i, int i2) {
            this.imageScale = getAspectFitScale(this.page1.width(), this.page1.height(), (float) i, (float) i2, Layout.AspectFit.Min);
            return this.imageScale;
        }

        private void setScanImage(Bitmap bitmap) {
            Rect rect = new Rect((int) this.copyFrame.left, (int) this.copyFrame.top, (int) this.copyFrame.right, (int) this.copyFrame.bottom);
            this.page1Bitmap = Bitmap.createBitmap((int) this.page1.width(), (int) this.page1.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(this.page1Bitmap);
            canvas.drawBitmap(bitmap, rect, new RectF(0.0f, 0.0f, (float) canvas.getWidth(), (float) canvas.getHeight()), (Paint) null);
        }

        private Point getOffset() {
            return new Point(this.offset);
        }

        private void setPaperFrame(RectF rectF) {
            this.copyFrame = new RectF(rectF);
            scaleRect(this.imageScale, this.copyFrame);
        }

        private RectF getPaperRect() {
            return new RectF(0.0f, 0.0f, this.paper.width(), this.paper.height());
        }
    }
}
