package epson.print.service;


import java.util.concurrent.LinkedBlockingDeque;

import epson.print.EPImageList;
import epson.print.pdf.AreaPdfRenderer;
import epson.print.screen.PrintSetting;

public class PdfRenderingController implements RenderingController {
    private LinkedBlockingDeque<Integer> mDeque;
    private PrintService mEpsonService;
    private boolean mIsLandscape;
    private String mOriginalFilename;
    private String mPassword;
    private String mPdfFilename;
    private PdfRenderThread mPdfRenderThread;
    private int[] mPrintRange;

    public void drawBeforeStartJob() {
    }

    public PdfRenderingController(PrintService printService, String str, String str2, String str3, boolean z, int[] iArr) {
        mEpsonService = printService;
        mPdfFilename = str;
        mOriginalFilename = str2 != null ? str2 : str;
        mPassword = str3;
        mIsLandscape = z;
        mPrintRange = iArr;
    }

    public void startDrawAfterStartJob(int i) {
        mDeque = new LinkedBlockingDeque<>();
        mPdfRenderThread = getPdfRenderThread(i);
        mPdfRenderThread.createEpImageList();
        mPdfRenderThread.start();
    }

    public EPImageList getImageList() {
        PdfRenderThread pdfRenderThread = mPdfRenderThread;
        if (pdfRenderThread != null) {
            return pdfRenderThread.getImageList();
        }
        throw new IllegalStateException("startDrawAfterStartJob() not called");
    }

    /* access modifiers changed from: package-private */
    @VisibleForTesting
    public PdfRenderThread getPdfRenderThread(int i) {
        return new PdfRenderThread(this.mEpsonService, new AreaPdfRenderer(), mPdfFilename, mOriginalFilename, mPassword, mIsLandscape, mDeque, mEpsonService.getLocalPrinterLayout1AreaSize(i), mPrintRange, i);
    }

    public void waitPage(int i, int i2) throws InterruptedException, LocalInterrupt {
        while (i < i2) {
            if (!this.mEpsonService.getCancelPrinting()) {
                int intValue = mDeque.takeFirst().intValue();
                if (i == intValue) {
                    i++;
                } else {
                    throw new RuntimeException("page = [" + i + "] que [" + intValue + "]");
                }
            } else {
                throw new LocalInterrupt();
            }
        }
    }

    public void interruptSubThreads() {
        PdfRenderThread pdfRenderThread = mPdfRenderThread;
        if (pdfRenderThread != null) {
            pdfRenderThread.interrupt();
        }
    }

    public void joinSubThread(long j) {
        PdfRenderThread pdfRenderThread = mPdfRenderThread;
        if (pdfRenderThread != null) {
            try {
                pdfRenderThread.join(j);
            } catch (InterruptedException unused) {
            }
        }
    }

    public PrintSetting.Kind getKind() {
        return getKindStatic();
    }

    public static PrintSetting.Kind getKindStatic() {
        return PrintSetting.Kind.document;
    }
}
