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 CdLayoutPosition implements ILayoutPosition {
    private int layout = 2;
    private int layoutMulti = 0;
    private int mBottomMargin = 0;
    private boolean mIsPaperLandScape = false;
    private int mLeftMargin = 0;
    private int mPaperHeight = 0;
    private int mPaperWidth = 0;
    private AltRect mPreviewPrintArea = new AltRect();
    private int mRightMargin = 0;
    private int mTopMargin = 0;

    CdLayoutPosition() {
    }

    public int getLayoutId() {
        return layout;
    }

    public int getLeftMargin() {
        return mLeftMargin;
    }

    public int getRightMargin() {
        return mRightMargin;
    }

    public int getTopMargin() {
        return mTopMargin;
    }

    public int getBottomMargin() {
        return mBottomMargin;
    }

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

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

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

    public boolean getIsPaperLandscape() {
        return mIsPaperLandScape;
    }

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

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

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

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

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

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

    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;
        }
        calculateLayoutSizeCdDvd(i, i2, point);
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void calculateLayoutSizeCdDvd(int i, int i2, @NonNull Point point) {
        int i3 = i2 > i ? (int) (((double) i) * 0.800000011920929d) : (int) (((double) i2) * 0.800000011920929d);
        AltRect altRect = mPreviewPrintArea;
        altRect.left = (i - i3) / 2;
        altRect.top = (i2 - i3) / 2;
        altRect.right = altRect.left + i3;
        AltRect altRect2 = mPreviewPrintArea;
        altRect2.bottom = altRect2.top + i3;
        point.x = ((this.mPreviewPrintArea.right - mPreviewPrintArea.left) / 2) + mPreviewPrintArea.left;
        point.y = ((this.mPreviewPrintArea.bottom - mPreviewPrintArea.top) / 2) + mPreviewPrintArea.top;
        float width = ((float) mPreviewPrintArea.width()) / ((float) mPaperWidth);
        mTopMargin = (int) (((float) mTopMargin) * width);
        mLeftMargin = (int) (((float) mLeftMargin) * width);
        mRightMargin = (int) (((float) mRightMargin) * width);
        mBottomMargin = (int) (((float) mBottomMargin) * width);
        if (this.mIsPaperLandScape) {
            int i4 = mTopMargin;
            mTopMargin = mRightMargin;
            mRightMargin = mBottomMargin;
            mBottomMargin = mLeftMargin;
            mLeftMargin = i4;
        }
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public void setPaperSizeFromPaperInfo(Info_paper info_paper) {
        mPaperWidth = info_paper.getPaper_width();
        mPaperHeight = info_paper.getPaper_height();
        mLeftMargin = info_paper.getLeftMargin_border();
        mTopMargin = info_paper.getTopMargin_border();
        mRightMargin = info_paper.getRightMargin_border();
        mBottomMargin = info_paper.getBottomMargin_border();
    }
}
