Skip to content

Commit 3ee0380

Browse files
vipinmenonprsadhuk
authored andcommitted
8234393: [macos] printing ignores printer tray
Reviewed-by: psadhukhan, prr
1 parent 3f9c8a3 commit 3ee0380

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,6 +44,7 @@
4444
import javax.print.attribute.standard.MediaSize;
4545
import javax.print.attribute.standard.MediaSizeName;
4646
import javax.print.attribute.standard.PageRanges;
47+
import javax.print.attribute.Attribute;
4748

4849
import sun.java2d.*;
4950
import sun.print.*;
@@ -64,6 +65,8 @@ public final class CPrinterJob extends RasterPrinterJob {
6465

6566
private static Font defaultFont;
6667

68+
private String tray = null;
69+
6770
// This is the NSPrintInfo for this PrinterJob. Protect multi thread
6871
// access to it. It is used by the pageDialog, jobDialog, and printLoop.
6972
// This way the state of these items is shared across these calls.
@@ -179,6 +182,11 @@ protected void setAttributes(PrintRequestAttributeSet attributes) throws Printer
179182
if (attributes == null) {
180183
return;
181184
}
185+
Attribute attr = attributes.get(Media.class);
186+
if (attr instanceof CustomMediaTray) {
187+
CustomMediaTray customTray = (CustomMediaTray) attr;
188+
tray = customTray.getChoiceName();
189+
}
182190

183191
PageRanges pageRangesAttr = (PageRanges)attributes.get(PageRanges.class);
184192
if (isSupportedValue(pageRangesAttr, attributes)) {
@@ -631,6 +639,10 @@ private String getPrinterName(){
631639
return service.getName();
632640
}
633641

642+
private String getPrinterTray() {
643+
return tray;
644+
}
645+
634646
private void setPrinterServiceFromNative(String printerName) {
635647
// This is called from the native side.
636648
PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);

src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -546,6 +546,7 @@ static JNF_MEMBER_CACHE(jm_getDestinationFile, sjc_CPrinterJob,
546546
static JNF_MEMBER_CACHE(jm_getPageFormatArea, sjc_CPrinterJob, "getPageFormatArea", "(Ljava/awt/print/PageFormat;)Ljava/awt/geom/Rectangle2D;");
547547
static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
548548
static JNF_MEMBER_CACHE(jm_getPageable, sjc_CPrinterJob, "getPageable", "()Ljava/awt/print/Pageable;");
549+
static JNF_MEMBER_CACHE(jm_getPrinterTray, sjc_CPrinterJob, "getPrinterTray", "()Ljava/lang/String;");
549550

550551
jboolean retVal = JNI_FALSE;
551552

@@ -560,6 +561,13 @@ static JNF_MEMBER_CACHE(jm_getDestinationFile, sjc_CPrinterJob,
560561
[printerView setFirstPage:firstPage lastPage:lastPage];
561562

562563
NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, jthis, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object)
564+
jobject printerTrayObj = JNFCallObjectMethod(env, jthis, jm_getPrinterTray);
565+
if (printerTrayObj != NULL) {
566+
NSString *printerTray = JNFJavaToNSString(env, printerTrayObj);
567+
if (printerTray != nil) {
568+
[[printInfo printSettings] setObject:printerTray forKey:@"InputSlot"];
569+
}
570+
}
563571

564572
// <rdar://problem/4156975> passing jthis CPrinterJob as well, so we can extract the printer name from the current job
565573
javaPageFormatToNSPrintInfo(env, jthis, page, printInfo);

src/java.desktop/share/classes/sun/print/CustomMediaTray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,7 @@
3030
import javax.print.attribute.standard.Media;
3131
import java.util.ArrayList;
3232

33-
class CustomMediaTray extends MediaTray {
33+
public class CustomMediaTray extends MediaTray {
3434
private static ArrayList<String> customStringTable = new ArrayList<>();
3535
private static ArrayList<MediaTray> customEnumTable = new ArrayList<>();
3636
private String choiceName;

test/jdk/java/awt/print/PrinterJob/TestMediaTraySelection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
* questions.
2222
*/
2323
/*
24-
* @bug 6357887 8165146
24+
* @bug 6357887 8165146 8234393
2525
* @summary Verifies if selected printertray is used
26-
* @requires os.family == "linux"
26+
* @requires (os.family == "linux" | os.family == "mac")
2727
* @run main/manual TestMediaTraySelection
2828
*/
2929

0 commit comments

Comments
 (0)