Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8295324: JavaFX: Blank pages when printing #916

Expand Up @@ -177,7 +177,7 @@ private void setEnabledState(Window owner, boolean state) {

public boolean showPrintDialog(Window owner) {

if (jobRunning || jobDone) {
if (jobRunning || jobDone || jobCanceled) {
return false;
}

Expand Down Expand Up @@ -252,7 +252,7 @@ private boolean showPrintDialogWithNestedLoop(Window owner) {
}

public boolean showPageDialog(Window owner) {
if (jobRunning || jobDone) {
if (jobRunning || jobDone || jobCanceled) {
return false;
}
if (GraphicsEnvironment.isHeadless()) {
Expand Down Expand Up @@ -812,6 +812,7 @@ public PageLayout validatePageLayout(PageLayout pageLayout) {
private boolean jobRunning = false;
private boolean jobError = false;
private boolean jobDone = false;
private boolean jobCanceled = false;
private J2DPageable j2dPageable = null;

/*
Expand Down Expand Up @@ -847,7 +848,7 @@ public boolean print(PageLayout pageLayout, Node node) {
}
}

if (jobError || jobDone) {
if (jobError || jobDone || jobCanceled) {
return false;
}

Expand All @@ -867,7 +868,9 @@ public boolean print(PageLayout pageLayout, Node node) {
t.printStackTrace();
}
jobError = true;
jobDone = true;
if (!jobCanceled) {
jobDone = true;
}
}
return !jobError;
}
Expand All @@ -878,14 +881,18 @@ public void run() {

try {
pJob2D.print(printReqAttrSet);
jobDone = true;
if (!jobCanceled) {
jobDone = true;
}
} catch (Throwable t) { /* subsumes declared PrinterException */
if (com.sun.prism.impl.PrismSettings.debug) {
System.err.println("print caught exception.");
t.printStackTrace();
}
jobError = true;
jobDone = true;
if (!jobCanceled) {
jobDone = true;
}
}
/*
* If the job ends because its reached a page range limit
Expand Down Expand Up @@ -1066,14 +1073,15 @@ private boolean waitForNextPage(int pageIndex) {
if (newPageInfo == null) {
monitor.notify(); // page is printed and no new page to print
}
while (newPageInfo == null && !jobDone && !jobError) {
while (newPageInfo == null && !jobDone && !jobCanceled && !jobError) {
try {
monitor.wait(1000);
} catch (InterruptedException e) {
}
}
}
if (jobDone || jobError) {
// Even if the jobDone is set to true (this is also done by 'endJob()'), we need to process the last page.
if (jobDone && newPageInfo == null || jobCanceled || jobError) {
return false;
}
currPageInfo = newPageInfo;
Expand Down Expand Up @@ -1134,7 +1142,7 @@ private boolean getPage(int pageIndex) {
}

public int print(Graphics g, PageFormat pf, int pageIndex) {
if (jobError || jobDone || !getPage(pageIndex)) {
if (jobError || jobCanceled || jobDone && !getPage(pageIndex)) {
return Printable.NO_SUCH_PAGE;
}
int x = (int)pf.getImageableX();
Expand Down Expand Up @@ -1212,7 +1220,7 @@ private void implPrintPage(PageLayout pageLayout, Node node) {
Toolkit.getToolkit().enterNestedEventLoop(elo);
elo = null;
} else {
while (!pageDone && !jobDone && !jobError) {
while (!pageDone && !jobDone && !jobCanceled && !jobError) {
synchronized (monitor) {
try {
if (!pageDone) {
Expand All @@ -1229,7 +1237,7 @@ private void implPrintPage(PageLayout pageLayout, Node node) {


public boolean endJob() {
if (jobRunning && !jobDone && !jobError) {
if (jobRunning && !jobDone && !jobCanceled && !jobError) {
jobDone = true;
try {
synchronized (monitor) {
Expand All @@ -1251,7 +1259,7 @@ public void cancelJob() {
if (!pJob2D.isCancelled()) {
pJob2D.cancel();
}
jobDone = true;
jobCanceled = true;
if (jobRunning) {
jobRunning = false;
try {
Expand Down