package epson.print.phlayout;

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

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

public class BorderedLayoutPosition implements ILayoutPosition {
    private int layout = 2;
    private int layoutMulti = 0;
    private int m3mmHeight = 0;
    private int m3mmWidth = 0;
    private int mBottomMargin = 0;
    private boolean mIsPaperLandScape = false;
    private int mLeftMargin = 0;
    private AltRect mPreview3mmEffectivePrintPosition = new AltRect();
    private int[] mPreviewMargin = new int[4];
    private int mRightMargin = 0;
    private int mTopMargin = 0;

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

    public Rect getPreviewPaperRect() {
        return null;
    }

    public int getLayoutId() {
        return layout;
    }

    public int getLeftMargin() {
        return mPreviewMargin[0];
    }

    public int getRightMargin() {
        return mPreviewMargin[2];
    }

    public int getTopMargin() {
        return mPreviewMargin[1];
    }

    public int getBottomMargin() {
        return mPreviewMargin[3];
    }

    public int[] getPrintSize(Context context, int i, int i2) {
        setLayoutId(2, i2);
        setPaperSizeFromPaperInfo(Info_paper.getInfoPaper(context, i));
        return new int[]{this.m3mmWidth, m3mmHeight};
    }

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

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

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

    public boolean getIsPaperLandscape() {
        return mIsPaperLandScape;
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void setPaperAndImageSize_forTest(int i, int i2, int i3, int i4) {
        m3mmWidth = i3;
        m3mmHeight = i4;
    }

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

    public void setPaperAndCalcPreviewPosition(Info_paper info_paper, int i, int i2, Point point) {
        int i3 = layout;
        setPaperSizeFromPaperInfo(info_paper);
        if (this.m3mmWidth <= 0 || m3mmHeight <= 0) {
            m3mmWidth = 2892;
            m3mmHeight = 4125;
        }
        calculateLayoutSizeBordered(i, i2, point);
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void calculateLayoutSizeBordered(int i, int i2, Point point) {
        int i3;
        int i4;
        if ((!this.mIsPaperLandScape || m3mmWidth > m3mmHeight) && (this.mIsPaperLandScape || m3mmWidth <= m3mmHeight)) {
            i3 = (int) (((double) i2) * 0.800000011920929d);
            int i5 = m3mmWidth;
            int i6 = m3mmHeight;
            int i7 = (int) (((float) (i3 * i5)) / ((float) i6));
            int i8 = (int) (((double) i) * 0.800000011920929d);
            if (i7 > i8) {
                i3 = (int) (((float) (i6 * i8)) / ((float) i5));
                i4 = i8;
            } else {
                i4 = i7;
            }
        } else {
            i4 = (int) (((double) i) * 0.800000011920929d);
            int i9 = m3mmWidth;
            int i10 = m3mmHeight;
            i3 = (int) (((float) (i4 * i9)) / ((float) i10));
            int i11 = (int) (((double) i2) * 0.800000011920929d);
            if (i3 > i11) {
                i4 = (int) (((float) (i10 * i11)) / ((float) i9));
                i3 = i11;
            }
        }
        AltRect altRect = mPreview3mmEffectivePrintPosition;
        altRect.left = (i - i4) / 2;
        altRect.top = (i2 - i3) / 2;
        altRect.right = altRect.left + i4;
        AltRect altRect2 = mPreview3mmEffectivePrintPosition;
        altRect2.bottom = altRect2.top + i3;
        point.x = ((this.mPreview3mmEffectivePrintPosition.right - mPreview3mmEffectivePrintPosition.left) / 2) + mPreview3mmEffectivePrintPosition.left;
        point.y = ((this.mPreview3mmEffectivePrintPosition.bottom - mPreview3mmEffectivePrintPosition.top) / 2) + mPreview3mmEffectivePrintPosition.top;
        float width = ((float) mPreview3mmEffectivePrintPosition.width()) / ((float) m3mmWidth);
        int[] iArr = mPreviewMargin;
        iArr[0] = (int) (((float) mLeftMargin) * width);
        iArr[1] = (int) (((float) mTopMargin) * width);
        iArr[2] = (int) (((float) mRightMargin) * width);
        iArr[3] = (int) (((float) mBottomMargin) * width);
        if (this.mIsPaperLandScape) {
            int i12 = iArr[1];
            iArr[1] = iArr[2];
            iArr[2] = iArr[3];
            iArr[3] = iArr[0];
            iArr[0] = i12;
        }
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void setPaperSizeFromPaperInfo(Info_paper info_paper) {
        if (this.layout == 2) {
            m3mmWidth = info_paper.getPaper_width_boder();
            m3mmHeight = info_paper.getPaper_height_boder();
            mLeftMargin = info_paper.getLeftMargin_border();
            mTopMargin = info_paper.getTopMargin_border();
            mRightMargin = info_paper.getRightMargin_border();
            mBottomMargin = info_paper.getBottomMargin_border();
            int i = layoutMulti;
            if (i == 65536) {
                Rect printingArea_2in1 = info_paper.getPrintingArea_2in1();
                m3mmWidth = printingArea_2in1.width();
                m3mmHeight = printingArea_2in1.height();
            } else if (i == 131072 || i == 262144) {
                Rect printingArea_4in1 = info_paper.getPrintingArea_4in1();
                m3mmWidth = printingArea_4in1.width();
                m3mmHeight = printingArea_4in1.height();
            }
        } else {
            throw new RuntimeException();
        }
    }

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

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