package epson.print.service;


import epson.print.EPImageList;
import epson.print.pdf.AreaPdfRenderer;
import epson.print.screen.PrintSetting;
import java.util.concurrent.LinkedBlockingDeque;

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) {
        this.mEpsonService = printService;
        this.mPdfFilename = str;
        this.mOriginalFilename = str2 != null ? str2 : str;
        this.mPassword = str3;
        this.mIsLandscape = z;
        this.mPrintRange = iArr;
    }

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

    public EPImageList getImageList() {
        PdfRenderThread pdfRenderThread = this.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(), this.mPdfFilename, this.mOriginalFilename, this.mPassword, this.mIsLandscape, this.mDeque, this.mEpsonService.getLocalPrinterLayout1AreaSize(i), this.mPrintRange, i);
    }

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

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

    public void joinSubThread(long j) {
        PdfRenderThread pdfRenderThread = this.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;
    }
}
