package epson.print.phlayout;

import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;

import epson.common.Info_paper;
import epson.print.EPImage;

class BorderlessLayoutPosition implements ILayoutPosition {
    private int layout = 2;
    private int layoutMulti = 0;
    private int[] mBorderlessPrintArea = new int[2];
    private int mBottomMargin = 0;
    private boolean mIsPaperLandScape = false;
    private int mLeftMargin = 0;
    private int mPaperHeight = 0;
    private int mPaperWidth = 0;
    private AltRect mPreviewPaperRect = new AltRect();
    private AltRectF mPreviewPrintAreaRect = new AltRectF();
    private int mRightMargin = 0;
    private int mTopMargin = 0;

    BorderlessLayoutPosition() {
    }

    public int getLayoutId() {
        return layout;
    }

    public int getLeftMargin() {
        return (int) (((float) mPreviewPaperRect.left) - mPreviewPrintAreaRect.left);
    }

    public int getRightMargin() {
        return (int) (this.mPreviewPrintAreaRect.right - ((float) mPreviewPaperRect.right));
    }

    public int getTopMargin() {
        return (int) (((float) mPreviewPaperRect.top) - mPreviewPrintAreaRect.top);
    }

    public int getBottomMargin() {
        return (int) (this.mPreviewPrintAreaRect.bottom - ((float) mPreviewPaperRect.bottom));
    }

    public RectF getPreviewImageCircumscribedTargetSize() {
        return mPreviewPrintAreaRect.getRectF();
    }

    public boolean isPreviewImageSizeValid() {
        return mPreviewPaperRect.right - mPreviewPaperRect.left > 0 && mPreviewPaperRect.bottom - mPreviewPaperRect.top > 0;
    }

    private AltRectF getPreviewImageAltRect() {
        return mPreviewPrintAreaRect;
    }

    public void setPaperLandscape(boolean z) {
        mIsPaperLandScape = z;
    }

    public boolean getIsPaperLandscape() {
        return mIsPaperLandScape;
    }

    public Rect getPreviewPaperRect() {
        return mPreviewPaperRect.getRect();
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public AltRect getPreviewPaperAltRect() {
        return mPreviewPaperRect;
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void setPaperAndImageSize_forTest(int i, int i2, int i3, int i4) {
        mPaperWidth = i;
        mPaperHeight = i2;
        int[] iArr = mBorderlessPrintArea;
        iArr[0] = i3;
        iArr[1] = i4;
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void setMargin_forTest(int[] iArr) {
        mLeftMargin = iArr[0];
        mTopMargin = iArr[1];
        mRightMargin = iArr[2];
        mBottomMargin = iArr[3];
    }

    public void setLayoutId(int i, int i2) {
        layout = i;
        layoutMulti = i2;
    }

    public void setPaperAndCalcPreviewPosition(Info_paper info_paper, int i, int i2, Point point) {
        setPaperSizeFromPaperInfo(info_paper);
        if (this.mPaperWidth <= 0 || mPaperHeight <= 0) {
            mPaperWidth = 2892;
            mPaperHeight = 4125;
        }
        calculateLayoutSizeBorderless(i, i2, point);
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void calculateLayoutSizeBorderless(int i, int i2, Point point) {
        int i3;
        int i4;
        int i5;
        int i6;
        int i7;
        int i8 = i;
        int i9 = i2;
        Point point2 = point;
        int[] iArr = new int[4];
        if ((!this.mIsPaperLandScape || mPaperWidth > mPaperHeight) && (this.mIsPaperLandScape || mPaperWidth <= mPaperHeight)) {
            int i10 = (int) (((double) i9) * 0.800000011920929d);
            int i11 = mPaperWidth;
            int i12 = mPaperHeight;
            int i13 = (int) (((float) (i10 * i11)) / ((float) i12));
            int[] iArr2 = mBorderlessPrintArea;
            int i14 = (int) (((float) (iArr2[0] * i13)) / ((float) i11));
            int i15 = (int) (((float) (iArr2[1] * i10)) / ((float) i12));
            int i16 = (int) (((double) i8) * 0.800000011920929d);
            if (i13 > i16) {
                int i17 = (int) (((float) (i16 * i12)) / ((float) i11));
                i6 = (int) (((float) (iArr2[0] * i16)) / ((float) i11));
                i5 = (int) (((float) (iArr2[1] * i17)) / ((float) i12));
                i3 = i17;
                i7 = i16;
            } else {
                i6 = i14;
                int i18 = i15;
                i3 = i10;
                i7 = i13;
                i5 = i18;
            }
            float f = ((float) i3) / ((float) mPaperHeight);
            iArr[0] = (int) (((float) mLeftMargin) * f);
            iArr[1] = (int) (((float) mTopMargin) * f);
            i4 = 2;
            iArr[2] = (int) (((float) mRightMargin) * f);
            iArr[3] = (int) (((float) mBottomMargin) * f);
        } else {
            int i19 = (int) (((double) i8) * 0.800000011920929d);
            int i20 = mPaperWidth;
            int i21 = mPaperHeight;
            int i22 = (int) (((float) (i19 * i20)) / ((float) i21));
            int[] iArr3 = mBorderlessPrintArea;
            int i23 = (int) (((float) (i19 * iArr3[1])) / ((float) i21));
            int i24 = (int) (((float) (iArr3[0] * i22)) / ((float) i20));
            int i25 = (int) (((double) i9) * 0.800000011920929d);
            if (i22 > i25) {
                i19 = (int) (((float) (i25 * i21)) / ((float) i20));
                i23 = (int) (((float) (iArr3[1] * i19)) / ((float) i21));
                i24 = (int) (((float) (iArr3[0] * i25)) / ((float) i20));
                i22 = i25;
            }
            float f2 = ((float) i7) / ((float) mPaperHeight);
            iArr[0] = (int) (((float) mTopMargin) * f2);
            iArr[1] = (int) (((float) mRightMargin) * f2);
            iArr[2] = (int) (((float) mBottomMargin) * f2);
            iArr[3] = (int) (((float) mLeftMargin) * f2);
            i4 = 2;
        }
        AltRect altRect = mPreviewPaperRect;
        altRect.left = (i8 - i7) / i4;
        altRect.top = (i9 - i3) / i4;
        altRect.right = altRect.left + i7;
        AltRect altRect2 = mPreviewPaperRect;
        altRect2.bottom = altRect2.top + i3;
        mPreviewPrintAreaRect = new AltRectF();
        mPreviewPrintAreaRect.left = (float) (this.mPreviewPaperRect.left - iArr[0]);
        mPreviewPrintAreaRect.top = (float) (this.mPreviewPaperRect.top - iArr[1]);
        AltRectF altRectF = mPreviewPrintAreaRect;
        altRectF.right = altRectF.left + ((float) i6);
        AltRectF altRectF2 = mPreviewPrintAreaRect;
        altRectF2.bottom = altRectF2.top + ((float) i5);
        point2.x = (int) (((this.mPreviewPrintAreaRect.right - mPreviewPrintAreaRect.left) / 2.0f) + mPreviewPrintAreaRect.left);
        point2.y = (int) (((this.mPreviewPrintAreaRect.bottom - mPreviewPrintAreaRect.top) / 2.0f) + mPreviewPrintAreaRect.top);
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void setPaperSizeFromPaperInfo(Info_paper info_paper) {
        mPaperWidth = info_paper.getPaper_width();
        mPaperHeight = info_paper.getPaper_height();
        mBorderlessPrintArea[0] = info_paper.getPaper_width_boderless();
        mBorderlessPrintArea[1] = info_paper.getPaper_height_boderless();
        mLeftMargin = -info_paper.getLeftMargin();
        mTopMargin = -info_paper.getTopMargin();
        mRightMargin = -info_paper.getRightMargin();
        mBottomMargin = -info_paper.getBottomMargin();
    }

    public void copyPreviewPrintAreaFromEpImage(@NonNull EPImage ePImage) {
        mIsPaperLandScape = ePImage.isPaperLandScape;
        mPreviewPrintAreaRect.left = (float) ePImage.previewPaperRectLeft;
        mPreviewPrintAreaRect.top = (float) ePImage.previewPaperRectTop;
        mPreviewPrintAreaRect.right = (float) ePImage.previewPaperRectRight;
        mPreviewPrintAreaRect.bottom = (float) ePImage.previewPaperRectBottom;
    }

    public void copyPreviewPrintAreaToEpImage(EPImage ePImage) {
        ePImage.isPaperLandScape = mIsPaperLandScape;
        ePImage.previewPaperRectLeft = (int) mPreviewPrintAreaRect.left;
        ePImage.previewPaperRectTop = (int) mPreviewPrintAreaRect.top;
        ePImage.previewPaperRectRight = (int) mPreviewPrintAreaRect.right;
        ePImage.previewPaperRectBottom = (int) mPreviewPrintAreaRect.bottom;
    }
}
