package epson.common;

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

import com.epson.mobilephone.common.maintain2.MaintainPrinter2;
import com.google.common.primitives.UnsignedBytes;

import epson.print.MyPrinter;

import java.util.Hashtable;

public class Info_paper {
    public static int boder_pixel_300 = 35;
    public static int boder_pixel_360 = 42;
    private int leftMargin;
    private int leftMargin_border;
    private int paper_height;
    private int paper_height_boder;
    private int paper_height_boderless;
    private int paper_width;
    private int paper_width_boder;
    private int paper_width_boderless;
    private int resolution;
    private int topMargin;
    private int topMargin_border;

    public int getPaper_width() {
        return paper_width;
    }

    public void setPaper_width(int i) {
        paper_width = i;
    }

    public int getPaper_height() {
        return paper_height;
    }

    public void setPaper_height(int i) {
        paper_height = i;
    }

    public int getPaper_width_boder() {
        return paper_width_boder;
    }

    public void setPaper_width_boder(int i) {
        paper_width_boder = i;
    }

    public int getPaper_height_boder() {
        return paper_height_boder;
    }

    public void setPaper_height_boder(int i) {
        paper_height_boder = i;
    }

    public int getLeftMargin_border() {
        return leftMargin_border;
    }

    public void setLeftMargin_border(int i) {
        leftMargin_border = i;
    }

    public int getTopMargin_border() {
        return topMargin_border;
    }

    public void setTopMargin_border(int i) {
        topMargin_border = i;
    }

    public int getBottomMargin_border() {
        return (getPaper_height() - getPaper_height_boder()) - topMargin_border;
    }

    public int getRightMargin_border() {
        return (getPaper_width() - getPaper_width_boder()) - leftMargin_border;
    }

    public int getPaper_width_boderless() {
        return paper_width_boderless;
    }

    public void setPaper_width_boderless(int i) {
        paper_width_boderless = i;
    }

    public int getPaper_height_boderless() {
        return paper_height_boderless;
    }

    public void setPaper_height_boderless(int i) {
        paper_height_boderless = i;
    }

    public int getLeftMargin() {
        return leftMargin;
    }

    public void setLeftMargin(int i) {
        leftMargin = i;
    }

    public int getTopMargin() {
        return topMargin;
    }

    public void setTopMargin(int i) {
        topMargin = i;
    }

    public void setResolution(int i) {
        resolution = i;
    }

    public int getBottomMargin() {
        return (getPaper_height() - getPaper_height_boderless()) - topMargin;
    }

    public int getRightMargin() {
        return (getPaper_width() - getPaper_width_boderless()) - leftMargin;
    }

    private Info_paper(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9) {
        paper_height = i2;
        paper_width = i;
        paper_height_boder = i4;
        paper_height_boderless = i8;
        leftMargin_border = (i - i3) / 2;
        topMargin_border = getBorder_pixel(i9);
        paper_width_boder = i3;
        paper_width_boderless = i7;
        topMargin = i6;
        leftMargin = i5;
    }

    public Info_paper() {
    }

    public static Info_paper getInfoPaper(Context context, int i) {
        int curPrinterResolution = getCurPrinterResolution(context);
        Hashtable<Integer, Info_paper> areaInfo = AreaInfoCache.getAreaInfo(context, curPrinterResolution);
        if (areaInfo != null && areaInfo.containsKey(Integer.valueOf(i))) {
            return areaInfo.get(Integer.valueOf(i));
        }
        int[] mediaInfo = MaintainPrinter2.getInstance().getMediaInfo(i, curPrinterResolution);
        if (mediaInfo != null) {
            return new Info_paper(mediaInfo[0], mediaInfo[1], mediaInfo[2], mediaInfo[3], mediaInfo[4], mediaInfo[5], mediaInfo[6], mediaInfo[7], curPrinterResolution);
        }
        return null;
    }

    public static Info_paper get360DpiPaperSizeInfo(int i) {
        int[] mediaInfo = MaintainPrinter2.getInstance().getMediaInfo(i, 1);
        if (mediaInfo != null) {
            return new Info_paper(mediaInfo[0], mediaInfo[1], mediaInfo[2], mediaInfo[3], mediaInfo[4], mediaInfo[5], mediaInfo[6], mediaInfo[7], 1);
        }
        return null;
    }

    public static int getCurPrinterResolution(Context context) {
        switch (MyPrinter.getCurPrinter(context).getLang()) {
            case 0:
            case 1:
                return 1;
            default:
                return 8;
        }
    }

    public static int getBorder_pixel(int i) {
        if (i == 4) {
            return boder_pixel_300 / 2;
        }
        if (i == 8) {
            return boder_pixel_300;
        }
        if (i == 16) {
            return boder_pixel_300 * 2;
        }
        switch (i) {
            case 1:
                return boder_pixel_360;
            case 2:
                return boder_pixel_360 * 2;
            default:
                return boder_pixel_360;
        }
    }

    static class AreaInfoCache {
        static final int SIZE_OF_EPS_INT32 = 4;
        private static Hashtable<Integer, Info_paper> areaInfoCache = null;
        private static long areaInfoTimeStamp = -1;

        AreaInfoCache() {
        }

        /* JADX WARNING: Removed duplicated region for block: B:79:0x015c A[SYNTHETIC, Splitter:B:79:0x015c] */
        /* JADX WARNING: Removed duplicated region for block: B:84:0x0164 A[SYNTHETIC, Splitter:B:84:0x0164] */
        /* JADX WARNING: Removed duplicated region for block: B:91:0x016b A[SYNTHETIC, Splitter:B:91:0x016b] */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public static java.util.Hashtable<java.lang.Integer, epson.common.Info_paper> getAreaInfo(android.content.Context r17, int r18) {
            /*
                java.util.Hashtable r0 = new java.util.Hashtable
                r0.<init>()
                epson.common.ExternalFileUtils r1 = epson.common.ExternalFileUtils.getInstance(r17)
                java.io.File r1 = r1.getAreaInfo()
                java.util.Hashtable<java.lang.Integer, epson.common.Info_paper> r2 = areaInfoCache
                if (r2 == 0) goto L_0x0025
                long r2 = r1.lastModified()
                long r4 = areaInfoTimeStamp
                int r6 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1))
                if (r6 != 0) goto L_0x0025
                java.lang.String r0 = "Info_paper"
                java.lang.String r1 = "Use cache areaInfo"
                epson.print.Util.EPLog.v(r0, r1)
                java.util.Hashtable<java.lang.Integer, epson.common.Info_paper> r0 = areaInfoCache
                return r0
            L_0x0025:
                java.lang.String r2 = "Info_paper"
                java.lang.String r3 = "Read areaInfo file"
                epson.print.Util.EPLog.v(r2, r3)
                r3 = 4
                byte[] r4 = new byte[r3]     // Catch:{ FileNotFoundException -> 0x0168, IOException -> 0x0155, all -> 0x0152 }
                java.io.BufferedInputStream r5 = new java.io.BufferedInputStream     // Catch:{ FileNotFoundException -> 0x0168, IOException -> 0x0155, all -> 0x0152 }
                java.io.FileInputStream r6 = new java.io.FileInputStream     // Catch:{ FileNotFoundException -> 0x0168, IOException -> 0x0155, all -> 0x0152 }
                r6.<init>(r1)     // Catch:{ FileNotFoundException -> 0x0168, IOException -> 0x0155, all -> 0x0152 }
                r5.<init>(r6)     // Catch:{ FileNotFoundException -> 0x0168, IOException -> 0x0155, all -> 0x0152 }
                r6 = 0
                int r7 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r7) goto L_0x0145
                int r7 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r8 = 0
            L_0x0045:
                if (r8 >= r7) goto L_0x0139
                epson.common.Info_paper r9 = new epson.common.Info_paper     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r9.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r10 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r10) goto L_0x0133
                int r10 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r11 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r11) goto L_0x012d
                int r11 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r9.setPaper_width(r11)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r11 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r11) goto L_0x0127
                int r11 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r9.setPaper_height(r11)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r11 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r11) goto L_0x0121
                int r11 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r12 = 0
            L_0x007b:
                if (r12 >= r11) goto L_0x010d
                int r13 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r13) goto L_0x0107
                int r13 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r14 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r14) goto L_0x0101
                int r14 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r15 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r15) goto L_0x00fb
                int r15 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r2 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r2) goto L_0x00f5
                int r2 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r16 = r7
                int r7 = r5.read(r4, r6, r3)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                if (r3 != r7) goto L_0x00ef
                int r7 = toInt(r4)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                switch(r13) {
                    case 1: goto L_0x00d0;
                    case 2: goto L_0x00b5;
                    default: goto L_0x00b4;
                }     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x00b4:
                goto L_0x00ea
            L_0x00b5:
                r9.setTopMargin_border(r14)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r9.setLeftMargin_border(r15)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r13 = -r14
                int r14 = r9.getPaper_height()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r13 = r13 + r14
                int r13 = r13 - r2
                r9.setPaper_height_boder(r13)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r2 = -r15
                int r13 = r9.getPaper_width()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r2 = r2 + r13
                int r2 = r2 - r7
                r9.setPaper_width_boder(r2)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                goto L_0x00ea
            L_0x00d0:
                r9.setTopMargin(r14)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r9.setLeftMargin(r15)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r13 = -r14
                int r14 = r9.getPaper_height()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r13 = r13 + r14
                int r13 = r13 - r2
                r9.setPaper_height_boderless(r13)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r2 = -r15
                int r13 = r9.getPaper_width()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r2 = r2 + r13
                int r2 = r2 - r7
                r9.setPaper_width_boderless(r2)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x00ea:
                int r12 = r12 + 1
                r7 = r16
                goto L_0x007b
            L_0x00ef:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x00f5:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x00fb:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x0101:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x0107:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x010d:
                r2 = r18
                r16 = r7
                r9.setResolution(r2)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                java.lang.Integer r7 = java.lang.Integer.valueOf(r10)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.put(r7, r9)     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                int r8 = r8 + 1
                r7 = r16
                goto L_0x0045
            L_0x0121:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x0127:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x012d:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x0133:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x0139:
                long r1 = r1.lastModified()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                areaInfoTimeStamp = r1     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                areaInfoCache = r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r5.close()     // Catch:{ IOException -> 0x0144 }
            L_0x0144:
                return r0
            L_0x0145:
                java.io.IOException r0 = new java.io.IOException     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                r0.<init>()     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
                throw r0     // Catch:{ FileNotFoundException -> 0x0150, IOException -> 0x014d, all -> 0x014b }
            L_0x014b:
                r0 = move-exception
                goto L_0x0162
            L_0x014d:
                r0 = move-exception
                r2 = r5
                goto L_0x0157
            L_0x0150:
                goto L_0x0169
            L_0x0152:
                r0 = move-exception
                r5 = 0
                goto L_0x0162
            L_0x0155:
                r0 = move-exception
                r2 = 0
            L_0x0157:
                r0.printStackTrace()     // Catch:{ all -> 0x0160 }
                if (r2 == 0) goto L_0x0170
                r2.close()     // Catch:{ IOException -> 0x016e }
                goto L_0x016e
            L_0x0160:
                r0 = move-exception
                r5 = r2
            L_0x0162:
                if (r5 == 0) goto L_0x0167
                r5.close()     // Catch:{ IOException -> 0x0167 }
            L_0x0167:
                throw r0
            L_0x0168:
                r5 = 0
            L_0x0169:
                if (r5 == 0) goto L_0x0170
                r5.close()     // Catch:{ IOException -> 0x016e }
            L_0x016e:
                r1 = 0
                goto L_0x0171
            L_0x0170:
                r1 = 0
            L_0x0171:
                return r1
            */
            throw new UnsupportedOperationException("Method not decompiled: epson.common.Info_paper.AreaInfoCache.getAreaInfo(android.content.Context, int):java.util.Hashtable");
        }

        static int toInt(byte[] bArr) {
            int i = 0;
            for (int i2 = 0; i2 < 4; i2++) {
                i |= (bArr[i2] & UnsignedBytes.MAX_VALUE) << (i2 * 8);
            }
            return i;
        }
    }

    public Rect getPaperSize_2in1() {
        return getRect_2in1(getPaper_width(), getPaper_height(), resolution, false);
    }

    public Rect getPaperSize_4in1() {
        return getRect_4in1(getPaper_width(), getPaper_height(), resolution, false);
    }

    public Rect getPrintingArea_2in1() {
        return getRect_2in1(getPaper_width_boder(), getPaper_height_boder(), resolution, true);
    }

    public Rect getPrintingArea_4in1() {
        return getRect_4in1(getPaper_width_boder(), getPaper_height_boder(), resolution, true);
    }

    public static Rect getRect_2in1(int i, int i2, int i3, boolean z) {
        Rect rect = new Rect();
        int i4 = 0;
        if (i <= i2) {
            int i5 = i2 / 2;
            if (z) {
                i4 = getBorder_pixel(i3) / 2;
            }
            i2 = i5 - i4;
        } else {
            int i6 = i / 2;
            if (z) {
                i4 = getBorder_pixel(i3) / 2;
            }
            i = i6 - i4;
        }
        rect.right = i;
        rect.bottom = i2;
        return rect;
    }

    public static Rect getRect_4in1(int i, int i2, int i3, boolean z) {
        Rect rect = new Rect();
        int i4 = 0;
        rect.right = (i / 2) - (z ? getBorder_pixel(i3) / 2 : 0);
        int i5 = i2 / 2;
        if (z) {
            i4 = getBorder_pixel(i3) / 2;
        }
        rect.bottom = i5 - i4;
        return rect;
    }

    public static int[] getMultiLayoutArea(int i, int i2, int i3, int i4) {
        Rect rect;
        if (i == 65536) {
            rect = getRect_2in1(i2, i3, i4, true);
        } else if (i == 131072 || i == 262144) {
            rect = getRect_4in1(i2, i3, i4, true);
        } else {
            return new int[]{i2, i3};
        }
        return new int[]{rect.width(), rect.height()};
    }
}
