package com.epson.cameracopy.printlayout;

import android.content.Context;
import android.graphics.Point;
import android.graphics.PointF;
import com.epson.cameracopy.alt.AdditionalPrinterInfo;
import epson.common.ImageUtil;


public class ManuscriptSize {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    public static final double INCH_MM = 25.4d;
    public static final int SCALE_TYPE_INCH = 2;
    public static final int SCALE_TYPE_MM = 1;
    private int mBaseDpi;
    private String mManuscriptFileName;
    private Point mManuscriptPixelSize;
    private ManuscriptTypeAdapter mManuscriptTypeAdapter;

    interface ManuscriptTypeAdapter {
        boolean displayLength();

        Point getBasePixelSize(int i);

        String getSizeName(Context context);

        int getUnitType(Context context);
    }

    public static double getPixelToPhysicalSizeScale(int i, int i2) {
        return i2 == 2 ? 1.0d / ((double) i) : 25.4d / ((double) i);
    }

    public ManuscriptSize(DocumentSizeInfo documentSizeInfo, String str, int i) {
        mBaseDpi = i;
        switch (documentSizeInfo.getPaperId()) {
            case -2:
                mManuscriptTypeAdapter = new CustomManuscriptSize(documentSizeInfo);
                break;
            case -1:
                mManuscriptTypeAdapter = new AutoManuscriptSize(documentSizeInfo);
                break;
            default:
                mManuscriptTypeAdapter = new IdManuscriptSize(documentSizeInfo);
                break;
        }
        setManuscriptPixlSize(str);
        mManuscriptFileName = str;
    }

    public int getPixelWidth() {
        return mManuscriptPixelSize.x;
    }

    public int getPixelHeight() {
        return mManuscriptPixelSize.y;
    }

    public PointF getPhysicalSize(Context context) {
        double pixelToPhysicalSizeScale = getPixelToPhysicalSizeScale(mBaseDpi, mManuscriptTypeAdapter.getUnitType(context));
        return new PointF((float) (((double) mManuscriptPixelSize.x) * pixelToPhysicalSizeScale), (float) (((double) mManuscriptPixelSize.y) * pixelToPhysicalSizeScale));
    }

    public PointF getDocumentSize(Context context) {
        ManuscriptTypeAdapter manuscriptTypeAdapter = mManuscriptTypeAdapter;
        if (manuscriptTypeAdapter instanceof CustomManuscriptSize) {
            return ((CustomManuscriptSize) manuscriptTypeAdapter).getCustomDocumentSize(context);
        }
        return getPhysicalSize(context);
    }

    public String getSizeName(Context context) {
        return mManuscriptTypeAdapter.getSizeName(context);
    }

    public boolean displayLength() {
        return mManuscriptTypeAdapter.displayLength();
    }

    public int getUnitType(Context context) {
        return mManuscriptTypeAdapter.getUnitType(context);
    }

    public static double calcRate(int i, int i2, int i3, int i4) {
        return Math.min(((double) i) / ((double) i3), ((double) i2) / ((double) i4));
    }

    public static ManuscriptSize load(Context context, String str) {
        return new ManuscriptSize(RegistedDocumentSizeList.getInstance(context).getCurrentDocumentSize(), str, AdditionalPrinterInfo.getCurrentPrintModeResolution(context));
    }

    public String getUnitStr(Context context) {
        if (getUnitType(context) == 2) {
            return context.getString(R.string.unit_inch);
        }
        return context.getString(R.string.unit_mm);
    }

    private void setManuscriptPixlSize(String str) {
        Point basePixelSize;
        mManuscriptPixelSize = new Point();
        Point imageSize = ImageUtil.getImageSize(str);
        if (imageSize != null && (basePixelSize = mManuscriptTypeAdapter.getBasePixelSize(mBaseDpi)) != null) {
            int i = imageSize.x;
            int i2 = imageSize.y;
            if ((i2 - i) * (basePixelSize.y - basePixelSize.x) >= 0) {
                int i3 = i;
                i = i2;
                i2 = i3;
            }
            double calcRate = calcRate(basePixelSize.x, basePixelSize.y, i2, i);
            Point point = mManuscriptPixelSize;
            point.x = (int) (((double) i2) * calcRate);
            point.y = (int) (calcRate * ((double) i));
        }
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        ManuscriptSize manuscriptSize = (ManuscriptSize) obj;
        if (mBaseDpi != manuscriptSize.mBaseDpi) {
            return false;
        }
        String str = mManuscriptFileName;
        if (str == null) {
            if (manuscriptSize.mManuscriptFileName != null) {
                return false;
            }
        } else if (!str.equals(manuscriptSize.mManuscriptFileName)) {
            return false;
        }
        Point point = mManuscriptPixelSize;
        if (point == null) {
            if (manuscriptSize.mManuscriptPixelSize != null) {
                return false;
            }
        } else if (!point.equals(manuscriptSize.mManuscriptPixelSize)) {
            return false;
        }
        ManuscriptTypeAdapter manuscriptTypeAdapter = mManuscriptTypeAdapter;
        if (manuscriptTypeAdapter == null) {
            if (manuscriptSize.mManuscriptTypeAdapter != null) {
                return false;
            }
        } else if (!manuscriptTypeAdapter.equals(manuscriptSize.mManuscriptTypeAdapter)) {
            return false;
        }
        return true;
    }
}
