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 this.layout;
    }

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

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

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

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

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

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

    private AltRectF getPreviewImageAltRect() {
        return this.mPreviewPrintAreaRect;
    }

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

    public boolean getIsPaperLandscape() {
        return this.mIsPaperLandScape;
    }

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

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

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

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

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

    public void setPaperAndCalcPreviewPosition(Info_paper info_paper, int i, int i2, Point point) {
        setPaperSizeFromPaperInfo(info_paper);
        if (this.mPaperWidth <= 0 || this.mPaperHeight <= 0) {
            this.mPaperWidth = 2892;
            this.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 || this.mPaperWidth > this.mPaperHeight) && (this.mIsPaperLandScape || this.mPaperWidth <= this.mPaperHeight)) {
            int i10 = (int) (((double) i9) * 0.800000011920929d);
            int i11 = this.mPaperWidth;
            int i12 = this.mPaperHeight;
            int i13 = (int) (((float) (i10 * i11)) / ((float) i12));
            int[] iArr2 = this.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) this.mPaperHeight);
            iArr[0] = (int) (((float) this.mLeftMargin) * f);
            iArr[1] = (int) (((float) this.mTopMargin) * f);
            i4 = 2;
            iArr[2] = (int) (((float) this.mRightMargin) * f);
            iArr[3] = (int) (((float) this.mBottomMargin) * f);
        } else {
            int i19 = (int) (((double) i8) * 0.800000011920929d);
            int i20 = this.mPaperWidth;
            int i21 = this.mPaperHeight;
            int i22 = (int) (((float) (i19 * i20)) / ((float) i21));
            int[] iArr3 = this.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) this.mPaperHeight);
            iArr[0] = (int) (((float) this.mTopMargin) * f2);
            iArr[1] = (int) (((float) this.mRightMargin) * f2);
            iArr[2] = (int) (((float) this.mBottomMargin) * f2);
            iArr[3] = (int) (((float) this.mLeftMargin) * f2);
            i4 = 2;
        }
        AltRect altRect = this.mPreviewPaperRect;
        altRect.left = (i8 - i7) / i4;
        altRect.top = (i9 - i3) / i4;
        altRect.right = altRect.left + i7;
        AltRect altRect2 = this.mPreviewPaperRect;
        altRect2.bottom = altRect2.top + i3;
        this.mPreviewPrintAreaRect = new AltRectF();
        this.mPreviewPrintAreaRect.left = (float) (this.mPreviewPaperRect.left - iArr[0]);
        this.mPreviewPrintAreaRect.top = (float) (this.mPreviewPaperRect.top - iArr[1]);
        AltRectF altRectF = this.mPreviewPrintAreaRect;
        altRectF.right = altRectF.left + ((float) i6);
        AltRectF altRectF2 = this.mPreviewPrintAreaRect;
        altRectF2.bottom = altRectF2.top + ((float) i5);
        point2.x = (int) (((this.mPreviewPrintAreaRect.right - this.mPreviewPrintAreaRect.left) / 2.0f) + this.mPreviewPrintAreaRect.left);
        point2.y = (int) (((this.mPreviewPrintAreaRect.bottom - this.mPreviewPrintAreaRect.top) / 2.0f) + this.mPreviewPrintAreaRect.top);
    }

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

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

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